diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2018-09-04 19:34:56 +0200 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2018-09-23 21:55:29 +0200 |
commit | b5130a81251d338be96e02134d6fca7c00229e07 (patch) | |
tree | 2569d4a46d4a4a7ce392edf778969e9526b80cd6 /lib/charset.c | |
parent | 5b2118a2ad3bd1b75dd1650db193a2f6182fa3de (diff) |
lib: charset: upper/lower case conversion
Provide functions for upper and lower case conversion.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'lib/charset.c')
-rw-r--r-- | lib/charset.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/charset.c b/lib/charset.c index 39c8329830..72c808ce64 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -6,8 +6,18 @@ */ #include <charset.h> +#include <capitalization.h> #include <malloc.h> +static struct capitalization_table capitalization_table[] = +#ifdef CONFIG_EFI_UNICODE_CAPITALIZATION + UNICODE_CAPITALIZATION_TABLE; +#elif CONFIG_FAT_DEFAULT_CODEPAGE == 1250 + CP1250_CAPITALIZATION_TABLE; +#else + CP437_CAPITALIZATION_TABLE; +#endif + s32 utf8_get(const char **src) { s32 code = 0; @@ -241,6 +251,43 @@ int utf16_utf8_strncpy(char **dst, const u16 *src, size_t count) return 0; } +s32 utf_to_lower(const s32 code) +{ + struct capitalization_table *pos = capitalization_table; + s32 ret = code; + + if (code <= 0x7f) { + if (code >= 'A' && code <= 'Z') + ret += 0x20; + return ret; + } + for (; pos->upper; ++pos) { + if (pos->upper == code) { + ret = pos->lower; + break; + } + } + return ret; +} + +s32 utf_to_upper(const s32 code) +{ + struct capitalization_table *pos = capitalization_table; + s32 ret = code; + + if (code <= 0x7f) { + if (code >= 'a' && code <= 'z') + ret -= 0x20; + return ret; + } + for (; pos->lower; ++pos) { + if (pos->lower == code) { + ret = pos->upper; + break; + } + } + return ret; +} size_t u16_strlen(const u16 *in) { |