summaryrefslogtreecommitdiff
path: root/src/basic/string-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-07 19:43:26 +0100
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit07de3e94bec7f426258007c4a790a78589d2fee3 (patch)
tree6ab081e34b12627c200540962f4b01d0a9a977eb /src/basic/string-util.c
parentd7ef73f05df04d2b6d59932fd3d21f155665a888 (diff)
basic: introduce generic ascii_strlower_n() call and make use of it everywhere
Diffstat (limited to 'src/basic/string-util.c')
-rw-r--r--src/basic/string-util.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 2c9754db0..e2bdb8976 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -310,14 +310,33 @@ char *truncate_nl(char *s) {
return s;
}
+char ascii_tolower(char x) {
+
+ if (x >= 'A' && x <= 'Z')
+ return x - 'A' + 'a';
+
+ return x;
+}
+
char *ascii_strlower(char *t) {
char *p;
assert(t);
for (p = t; *p; p++)
- if (*p >= 'A' && *p <= 'Z')
- *p = *p - 'A' + 'a';
+ *p = ascii_tolower(*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++)
+ t[i] = ascii_tolower(t[i]);
return t;
}