(_c >= 'A' && _c <= 'Z') ? _c + ('a' - 'A') : _c; \
})
+#define DEFINE_STRTOLOWER(type, name) \
+ void name(type *s) { \
+ if (!s) \
+ return; \
+ for (; *s; s++) \
+ *s = TOLOWER(*s); \
+ }
+
+DEFINE_STRTOLOWER(char, strtolower8);
+DEFINE_STRTOLOWER(char16_t, strtolower16);
+
#define DEFINE_STRNCASECMP(type, name, tolower) \
int name(const type *s1, const type *s2, size_t n) { \
if (!s1 || !s2) \
size_t strlen8(const char *s);
size_t strlen16(const char16_t *s);
+void strtolower8(char *s);
+void strtolower16(char16_t *s);
+
int strncmp8(const char *s1, const char *s2, size_t n);
int strncmp16(const char16_t *s1, const char16_t *s2, size_t n);
assert_se(strnlen16(u"12\0004", 5) == 2);
}
+TEST(strtolower8) {
+ char s[] = "\0001234abcDEF!\0zZ";
+
+ strtolower8(NULL);
+
+ strtolower8(s);
+ assert_se(memcmp(s, "\0001234abcDEF!\0zZ", sizeof(s)) == 0);
+
+ s[0] = '#';
+ strtolower8(s);
+ assert_se(memcmp(s, "#1234abcdef!\0zZ", sizeof(s)) == 0);
+}
+
+TEST(strtolower16) {
+ char16_t s[] = u"\0001234abcDEF!\0zZ";
+
+ strtolower16(NULL);
+
+ strtolower16(s);
+ assert_se(memcmp(s, u"\0001234abcDEF!\0zZ", sizeof(s)) == 0);
+
+ s[0] = '#';
+ strtolower16(s);
+ assert_se(memcmp(s, u"#1234abcdef!\0zZ", sizeof(s)) == 0);
+}
+
TEST(strncmp8) {
assert_se(strncmp8(NULL, "", 10) < 0);
assert_se(strncmp8("", NULL, 10) > 0);