}
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 */
if (!bad)
bad = WHITESPACE;
- for (p = s; *p; p++)
+ for (char *p = s; *p; p++)
if (!strchr(bad, *p))
c = p + 1;
}
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;
}
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;
}
bool string_has_cc(const char *p, const char *ok) {
- const char *t;
-
assert(p);
/*
* considered OK.
*/
- for (t = p; *t; t++) {
+ for (const char *t = p; *t; t++) {
if (ok && strchr(ok, *t))
continue;
* 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 */
/* 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;
}
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;