boot: Add strtolower8/16

This commit is contained in:
Jan Janssen
2022-05-31 15:10:45 +02:00
parent 3d5127c68f
commit 98850528bf
3 changed files with 40 additions and 0 deletions
+11
View File
@@ -43,6 +43,17 @@ size_t strlen16(const char16_t *s) {
(_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) \
+3
View File
@@ -11,6 +11,9 @@ size_t strnlen16(const char16_t *s, size_t n);
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);
+26
View File
@@ -41,6 +41,32 @@ TEST(strnlen16) {
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);