diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-03 14:36:24 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-05 12:12:42 +0200 |
commit | a01080ceb388912c140cd0b8391d70b883c0a17e (patch) | |
tree | d79ad5f33bd31196896675dbd615612bc55e02ef /src/basic/string-util.c | |
parent | basic/string-util: split out helper function (diff) | |
download | systemd-a01080ceb388912c140cd0b8391d70b883c0a17e.tar.xz systemd-a01080ceb388912c140cd0b8391d70b883c0a17e.zip |
basic/string-util: inline iterator variable declarations
Diffstat (limited to 'src/basic/string-util.c')
-rw-r--r-- | src/basic/string-util.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c index c8ed87765f..bcf39cd3ec 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -150,7 +150,7 @@ char *delete_chars(char *s, const char *bad) { } char *delete_trailing_chars(char *s, const char *bad) { - char *p, *c = s; + char *c = s; /* Drops all specified bad characters, at the end of the string */ @@ -160,7 +160,7 @@ char *delete_trailing_chars(char *s, const char *bad) { if (!bad) bad = WHITESPACE; - for (p = s; *p; p++) + for (char *p = s; *p; p++) if (!strchr(bad, *p)) c = p + 1; @@ -193,34 +193,28 @@ char ascii_toupper(char x) { } char *ascii_strlower(char *t) { - char *p; - assert(t); - for (p = t; *p; p++) + for (char *p = t; *p; p++) *p = ascii_tolower(*p); return t; } char *ascii_strupper(char *t) { - char *p; - assert(t); - for (p = t; *p; p++) + for (char *p = t; *p; p++) *p = ascii_toupper(*p); return t; } char *ascii_strlower_n(char *t, size_t n) { - size_t i; - if (n <= 0) return t; - for (i = 0; i < n; i++) + for (size_t i = 0; i < n; i++) t[i] = ascii_tolower(t[i]); return t; @@ -252,10 +246,8 @@ int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m) { } bool chars_intersect(const char *a, const char *b) { - const char *p; - /* Returns true if any of the chars in a are in b. */ - for (p = a; *p; p++) + for (const char *p = a; *p; p++) if (strchr(b, *p)) return true; @@ -263,8 +255,6 @@ bool chars_intersect(const char *a, const char *b) { } bool string_has_cc(const char *p, const char *ok) { - const char *t; - assert(p); /* @@ -273,7 +263,7 @@ bool string_has_cc(const char *p, const char *ok) { * considered OK. */ - for (t = p; *t; t++) { + for (const char *t = p; *t; t++) { if (ok && strchr(ok, *t)) continue; @@ -465,7 +455,7 @@ char *cellescape(char *buf, size_t len, const char *s) { * very end. */ - size_t i = 0, last_char_width[4] = {}, k = 0, j; + size_t i = 0, last_char_width[4] = {}, k = 0; assert(len > 0); /* at least a terminating NUL */ @@ -494,7 +484,7 @@ char *cellescape(char *buf, size_t len, const char *s) { /* Ellipsation is necessary. This means we might need to truncate the string again to make space for 4 * characters ideally, but the buffer is shorter than that in the first place take what we can get */ - for (j = 0; j < ELEMENTSOF(last_char_width); j++) { + for (size_t j = 0; j < ELEMENTSOF(last_char_width); j++) { if (i + 4 <= len) /* nice, we reached our space goal */ break; @@ -900,14 +890,12 @@ int free_and_strndup(char **p, const char *s, size_t l) { } bool string_is_safe(const char *p) { - const char *t; - if (!p) return false; /* Checks if the specified string contains no quotes or control characters */ - for (t = p; *t; t++) { + for (const char *t = p; *t; t++) { if (*t > 0 && *t < ' ') /* no control characters */ return false; |