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
committerLennart Poettering <lennart@poettering.net>2016-01-11 19:39:59 +0100
commitb577e3d589ec00f6d96e90b0d4bf344dbd40cd76 (patch)
tree3ef35c1801ce366abd93012ae338d91f6dbffcdc /src/basic/string-util.c
parentd424da2ae0860268ab863ce8945a425aa79e3826 (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 8178c7093f..849e457439 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -317,14 +317,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;
}