diff options
| author | Tyge Løvset <[email protected]> | 2023-01-31 18:55:08 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-31 18:55:08 +0100 |
| commit | b677a0c3950b8294ba6458e682a885351273ac08 (patch) | |
| tree | f309f7f7571fb588f0f65254d17fa09d678a8e3c /include/stc/utf8.h | |
| parent | a24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e (diff) | |
| download | STC-modified-b677a0c3950b8294ba6458e682a885351273ac08.tar.gz STC-modified-b677a0c3950b8294ba6458e682a885351273ac08.zip | |
Converted all containers but the maps and examples to signed sizes and indices.
Diffstat (limited to 'include/stc/utf8.h')
| -rw-r--r-- | include/stc/utf8.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/include/stc/utf8.h b/include/stc/utf8.h index ea661bb6..ce50af87 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -23,7 +23,7 @@ extern uint32_t utf8_tolower(uint32_t c); extern uint32_t utf8_toupper(uint32_t c); extern bool utf8_iscased(uint32_t c); extern bool utf8_isword(uint32_t c); -extern bool utf8_valid_n(const char* s, size_t nbytes); +extern bool utf8_valid_n(const char* s, intptr_t nbytes); extern int utf8_icmp_sv(csview s1, csview s2); extern unsigned utf8_encode(char *out, uint32_t c); extern uint32_t utf8_peek_off(const char *s, int offset); @@ -35,7 +35,7 @@ STC_INLINE bool utf8_islower(uint32_t c) { return utf8_toupper(c) != c; } STC_INLINE bool utf8_isalnum(uint32_t c) { - if (c < 128) return isalnum(c) != 0; + if (c < 128) return isalnum((int)c) != 0; return utf8_isalpha(c) || utf8_isgroup(U8G_Nd, c); } @@ -68,17 +68,17 @@ STC_INLINE uint32_t utf8_peek(const char* s) { /* case-insensitive utf8 string comparison */ STC_INLINE int utf8_icmp(const char* s1, const char* s2) { - return utf8_icmp_sv(c_SV(s1, ~(size_t)0), c_SV(s2, ~(size_t)0)); + return utf8_icmp_sv(c_SV(s1, INTPTR_MAX), c_SV(s2, INTPTR_MAX)); } STC_INLINE bool utf8_valid(const char* s) { - return utf8_valid_n(s, ~(size_t)0); + return utf8_valid_n(s, INTPTR_MAX); } /* following functions are independent but assume valid utf8 strings: */ /* number of bytes in the utf8 codepoint from s */ -STC_INLINE unsigned utf8_chr_size(const char *s) { +STC_INLINE int utf8_chr_size(const char *s) { unsigned b = (uint8_t)*s; if (b < 0x80) return 1; /*if (b < 0xC2) return 0;*/ @@ -89,29 +89,29 @@ STC_INLINE unsigned utf8_chr_size(const char *s) { } /* number of codepoints in the utf8 string s */ -STC_INLINE size_t utf8_size(const char *s) { - size_t size = 0; +STC_INLINE intptr_t utf8_size(const char *s) { + intptr_t size = 0; while (*s) size += (*++s & 0xC0) != 0x80; return size; } -STC_INLINE size_t utf8_size_n(const char *s, size_t nbytes) { - size_t size = 0; +STC_INLINE intptr_t utf8_size_n(const char *s, intptr_t nbytes) { + intptr_t size = 0; while ((nbytes-- != 0) & (*s != 0)) { size += (*++s & 0xC0) != 0x80; } return size; } -STC_INLINE const char* utf8_at(const char *s, size_t index) { +STC_INLINE const char* utf8_at(const char *s, intptr_t index) { while ((index > 0) & (*s != 0)) index -= (*++s & 0xC0) != 0x80; return s; } -STC_INLINE size_t utf8_pos(const char* s, size_t index) - { return (size_t)(utf8_at(s, index) - s); } +STC_INLINE intptr_t utf8_pos(const char* s, intptr_t index) + { return (intptr_t)(utf8_at(s, index) - s); } #endif // UTF8_H_INCLUDED #if defined i_extern || defined STC_EXTERN |
