diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 14:41:53 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 14:41:53 +0200 |
commit | 5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (patch) | |
tree | 684758441f5b431d0008253243034b6a4a29417c /src/str.c | |
parent | 249866e3d1e11dc72eaa1305f4bb479ded92ef38 (diff) |
initial clang-format
Diffstat (limited to 'src/str.c')
-rw-r--r-- | src/str.c | 43 |
1 files changed, 29 insertions, 14 deletions
@@ -1,4 +1,5 @@ #include "str.h" + #include "stralloc.h" /** @@ -8,61 +9,67 @@ @brief string handling functions */ -unsigned int str_copy(register char *s,register const char *t) +unsigned int str_copy(register char *s, register const char *t) { register int len; len = 0; for (;;) { + // clang-format off if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; + // clang-format on } } -unsigned int str_copyb(register char *s,register const char *t,unsigned int max) +unsigned int str_copyb(register char *s, register const char *t, unsigned int max) { register int len; len = 0; while (max-- > 0) { + // clang-format off if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; + // clang-format on } return len; } -int str_diff(register const char *s,register const char *t) +int str_diff(register const char *s, register const char *t) { register char x; for (;;) { + // clang-format off x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; + // clang-format on } - return ((int)(unsigned int)(unsigned char) x) - - ((int)(unsigned int)(unsigned char) *t); + return ((int)(unsigned int)(unsigned char)x) - ((int)(unsigned int)(unsigned char)*t); } -int str_diffn(register const char *s,register const char *t,unsigned int len) +int str_diffn(register const char *s, register const char *t, unsigned int len) { register char x; for (;;) { + // clang-format off if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t; + // clang-format on } - return ((int)(unsigned int)(unsigned char) x) - - ((int)(unsigned int)(unsigned char) *t); + return ((int)(unsigned int)(unsigned char)x) - ((int)(unsigned int)(unsigned char)*t); } unsigned int str_len(register const char *s) @@ -71,14 +78,16 @@ unsigned int str_len(register const char *s) t = s; for (;;) { + // clang-format off if (!*t) { return t - s; } ++t; if (!*t) { return t - s; } ++t; if (!*t) { return t - s; } ++t; if (!*t) { return t - s; } ++t; + // clang-format on } } -unsigned int str_chr(register const char *s,int c) +unsigned int str_chr(register const char *s, int c) { register char ch; register const char *t; @@ -86,15 +95,17 @@ unsigned int str_chr(register const char *s,int c) ch = c; t = s; for (;;) { + // clang-format off if (!*t) { break; } if (*t == ch) { break; } ++t; if (!*t) { break; } if (*t == ch) { break; } ++t; if (!*t) { break; } if (*t == ch) { break; } ++t; if (!*t) { break; } if (*t == ch) { break; } ++t; + // clang-format on } return t - s; } -unsigned int str_rchr(register const char *s,int c) +unsigned int str_rchr(register const char *s, int c) { register char ch; register const char *t; @@ -104,32 +115,36 @@ unsigned int str_rchr(register const char *s,int c) t = s; u = 0; for (;;) { + // clang-format off if (!*t) { break; } if (*t == ch) { u = t; } ++t; if (!*t) { break; } if (*t == ch) { u = t; } ++t; if (!*t) { break; } if (*t == ch) { u = t; } ++t; if (!*t) { break; } if (*t == ch) { u = t; } ++t; + // clang-format on } if (!u) u = t; return u - s; } -int str_start(register const char *s,register const char *t) +int str_start(register const char *s, register const char *t) { register char x; for (;;) { + // clang-format off x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; + // clang-format on } } -char *str_append(char *dest, char const *s) +char *str_append(char *dest, const char *s) { static stralloc sa = {0}; - stralloc_copys(&sa,dest); - stralloc_catb(&sa,s,sizeof(s)); + stralloc_copys(&sa, dest); + stralloc_catb(&sa, s, sizeof(s)); return sa.s; } |