mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
char32: add helper functions to work with c32 case
This commit is contained in:
parent
19466a21d8
commit
71de0c45bc
2 changed files with 37 additions and 0 deletions
22
char32.c
22
char32.c
|
|
@ -53,6 +53,14 @@ UNITTEST
|
|||
xassert(c32cmp(U"b", U"a") > 0);
|
||||
}
|
||||
|
||||
UNITTEST
|
||||
{
|
||||
xassert(c32ncmp(U"foo", U"foot", 3) == 0);
|
||||
xassert(c32ncmp(U"foot", U"FOOT", 4) > 0);
|
||||
xassert(c32ncmp(U"a", U"b", 1) < 0);
|
||||
xassert(c32ncmp(U"bb", U"aa", 2) > 0);
|
||||
}
|
||||
|
||||
UNITTEST
|
||||
{
|
||||
char32_t copy[16];
|
||||
|
|
@ -127,6 +135,20 @@ UNITTEST
|
|||
xassert(c32cmp(dst, U"foobar12345678") == 0);
|
||||
}
|
||||
|
||||
UNITTEST
|
||||
{
|
||||
xassert(!isc32upper(U'a'));
|
||||
xassert(isc32upper(U'A'));
|
||||
xassert(!isc32upper(U'a'));
|
||||
}
|
||||
|
||||
UNITTEST
|
||||
{
|
||||
xassert(hasc32upper(U"abc1A"));
|
||||
xassert(!hasc32upper(U"abc1_aaa"));
|
||||
xassert(!hasc32upper(U""));
|
||||
}
|
||||
|
||||
UNITTEST
|
||||
{
|
||||
char32_t *c = xc32dup(U"foobar");
|
||||
|
|
|
|||
15
char32.h
15
char32.h
|
|
@ -20,6 +20,10 @@ static inline int c32cmp(const char32_t *s1, const char32_t *s2) {
|
|||
return wcscmp((const wchar_t *)s1, (const wchar_t *)s2);
|
||||
}
|
||||
|
||||
static inline int c32ncmp(const char32_t *s1, const char32_t *s2, size_t n) {
|
||||
return wcsncmp((const wchar_t *)s1, (const wchar_t *)s2, n);
|
||||
}
|
||||
|
||||
static inline char32_t *c32ncpy(char32_t *dst, const char32_t *src, size_t n) {
|
||||
return (char32_t *)wcsncpy((wchar_t *)dst, (const wchar_t *)src, n);
|
||||
}
|
||||
|
|
@ -60,6 +64,10 @@ static inline char32_t toc32upper(char32_t c) {
|
|||
return (char32_t)towupper((wint_t)c);
|
||||
}
|
||||
|
||||
static inline bool isc32upper(char32_t c32) {
|
||||
return iswupper((wint_t)c32);
|
||||
}
|
||||
|
||||
static inline bool isc32space(char32_t c32) {
|
||||
return iswspace((wint_t)c32);
|
||||
}
|
||||
|
|
@ -72,6 +80,13 @@ static inline bool isc32graph(char32_t c32) {
|
|||
return iswgraph((wint_t)c32);
|
||||
}
|
||||
|
||||
static inline bool hasc32upper(const char32_t *s) {
|
||||
for (int i = 0; s[i] != '\0'; i++) {
|
||||
if (isc32upper(s[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline int c32width(char32_t c) {
|
||||
#if defined(FOOT_GRAPHEME_CLUSTERING)
|
||||
return utf8proc_charwidth((utf8proc_int32_t)c);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue