summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-01-14 09:59:32 +0100
committerTyge Løvset <[email protected]>2022-01-14 09:59:32 +0100
commit64c15e66853f766102aac2642a45d4940d0bb42c (patch)
tree849658a019a00e7a096222c166ecbc574ff6bb69 /include
parentc0359b2d99be860370a3520cbddf11cd3dd1ade9 (diff)
downloadSTC-modified-64c15e66853f766102aac2642a45d4940d0bb42c.tar.gz
STC-modified-64c15e66853f766102aac2642a45d4940d0bb42c.zip
Final utf8 api, and docs.
Diffstat (limited to 'include')
-rw-r--r--include/stc/csview.h12
-rw-r--r--include/stc/utf8.h6
2 files changed, 9 insertions, 9 deletions
diff --git a/include/stc/csview.h b/include/stc/csview.h
index e65821bb..f3a0ae11 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -69,18 +69,18 @@ STC_INLINE bool csview_ends_with(csview sv, csview sub)
{ if (sub.size > sv.size) return false;
return !memcmp(sv.str + sv.size - sub.size, sub.str, sub.size); }
STC_INLINE csview_iter csview_begin(const csview* self)
- { return c_make(csview_iter){.cp = {self->str, utf8_codepoint_size(*self->str)}}; }
+ { return c_make(csview_iter){.cp = {self->str, utf8_codepoint_size(self->str)}}; }
STC_INLINE csview_iter csview_end(const csview* self)
{ return c_make(csview_iter){self->str + self->size}; }
STC_INLINE void csview_next(csview_iter* it)
- { it->ref += it->cp.size; it->cp.size = utf8_codepoint_size(*it->ref); }
+ { it->ref += it->cp.size; it->cp.size = utf8_codepoint_size(it->ref); }
/* utf8 */
-STC_INLINE bool csview_valid_utf8(csview sv)
- { return utf8_valid(sv.str); }
+STC_INLINE bool utf8_valid_sv(csview sv)
+ { return utf8_size_n(sv.str, sv.size) != SIZE_MAX; }
-STC_INLINE size_t csview_size_utf8(csview sv)
- { return utf8_size(sv.str); }
+STC_INLINE size_t utf8_size_sv(csview sv)
+ { return utf8_size_n(sv.str, sv.size); }
STC_INLINE csview utf8_substr(const char* str, size_t pos, size_t n) {
csview sv;
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index 93f8461a..4270c8c7 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -49,8 +49,8 @@ STC_INLINE uint32_t utf8_peek(const char *s) {
return codepoint;
}
-STC_INLINE size_t utf8_codepoint_size(char c) {
- uint8_t u = (uint8_t)c;
+STC_INLINE size_t utf8_codepoint_size(const char* s) {
+ uint8_t u = *(const uint8_t *)s;
size_t ret = (u & 0xF0) == 0xE0;
ret += ret << 1; // 3
ret |= u < 0x80; // 1
@@ -60,7 +60,7 @@ STC_INLINE size_t utf8_codepoint_size(char c) {
}
STC_INLINE const char *utf8_next(const char *s) {
- const char* t = s + utf8_codepoint_size(*s);
+ const char* t = s + utf8_codepoint_size(s);
uintptr_t p = (uintptr_t)t;
p &= (uintptr_t) -(*s != 0);