diff options
| author | Tyge Løvset <[email protected]> | 2022-06-10 12:02:12 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-10 12:02:12 +0200 |
| commit | d564436422d842a52a00f8b3ef0fadec20625a0d (patch) | |
| tree | 4c04f8f7764f54ad5d166b1bc747382b628f0288 | |
| parent | 6fc13dad84b2b315ea33af180d907e63a632accd (diff) | |
| download | STC-modified-d564436422d842a52a00f8b3ef0fadec20625a0d.tar.gz STC-modified-d564436422d842a52a00f8b3ef0fadec20625a0d.zip | |
removed cstr_length() and csview_length() -> use .._size().
| -rw-r--r-- | docs/cstr_api.md | 1 | ||||
| -rw-r--r-- | docs/csview_api.md | 8 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 2 | ||||
| -rw-r--r-- | include/stc/alt/cstr.h | 1 | ||||
| -rw-r--r-- | include/stc/cstr.h | 3 | ||||
| -rw-r--r-- | include/stc/csview.h | 3 | ||||
| -rw-r--r-- | include/stc/utf8.h | 2 | ||||
| -rw-r--r-- | src/utf8code.c | 2 |
8 files changed, 8 insertions, 14 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 57c8c6e0..612e50e2 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -37,7 +37,6 @@ csview cstr_sv(const cstr* self); // access cstr_buf cstr_buffer(cstr* self); // access to mutable buffer (with capacity) size_t cstr_size(cstr s); -size_t cstr_length(cstr s); size_t cstr_capacity(cstr s); bool cstr_empty(cstr s); diff --git a/docs/csview_api.md b/docs/csview_api.md index fcdb9f72..49f7cb70 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -34,7 +34,6 @@ csview csview_from_n(const char* str, size_t n); // construct void csview_clear(csview* self); size_t csview_size(csview sv); -size_t csview_length(csview sv); bool csview_empty(csview sv); bool csview_equals(csview sv, csview sv2); @@ -52,7 +51,7 @@ csview csview_token(csview sv, csview sep, size_t* start); // see sp #### UTF8 methods ```c size_t csview_u8size(csview sv); -csview csview_u8substr(csview sv, size_t u8pos, size_t u8len); +csview csview_substr_u8(csview sv, size_t u8pos, size_t u8len); csview_iter csview_begin(const csview* self); csview_iter csview_end(const csview* self); @@ -63,14 +62,15 @@ bool csview_valid_utf8(csview sv); // from utf8.h/utf8code.c: bool utf8_valid(const char* s); -bool utf8_valid_n(const char* s, size_t n); +bool utf8_valid_n(const char* s, size_t nbytes); size_t utf8_size(const char *s); size_t utf8_size_n(const char *s, size_t nbytes); // number of UTF8 codepoints within n bytes const char* utf8_at(const char *s, size_t index); // from UTF8 index to char* position size_t utf8_pos(const char* s, size_t index); // from UTF8 index to byte index position unsigned utf8_chr_size(const char* s); // 0-4 (0 if s[0] is illegal utf8) uint32_t utf8_decode(utf8_decode_t *d, uint8_t byte); // decode next byte to utf8, return state. -unsigned utf8_encode(char *out, uint32_t cp); // encode unicode cp into out buffer +unsigned utf8_encode(char *out, uint32_t codepoint); // encode unicode cp into out buffer +uint32_t utf8_peek(const char* s, int pos); // codepoint value at utf8 pos (may be negative) ``` #### Extended cstr methods diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index 52eb5bd2..c38b37e4 100644 --- a/examples/utf8replace_c.c +++ b/examples/utf8replace_c.c @@ -8,7 +8,7 @@ int main() { cstr_replace_sv( &hello, - csview_u8substr(cstr_sv(&hello), 7, 1), + csview_substr_u8(cstr_sv(&hello), 7, 1), c_sv("🐨") ); printf("%s\n", cstr_str(&hello)); diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index da3776bd..f5a5b169 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -75,7 +75,6 @@ STC_INLINE cstr cstr_from(const char* str) { return cstr_from_n(str, strlen(str)); } STC_INLINE char* cstr_data(cstr* self) { return self->str; } STC_INLINE size_t cstr_size(cstr s) { return _cstr_p(&s)->size; } -STC_INLINE size_t cstr_length(cstr s) { return _cstr_p(&s)->size; } STC_INLINE size_t cstr_capacity(cstr s) { return _cstr_p(&s)->cap; } STC_INLINE bool cstr_empty(cstr s) { return _cstr_p(&s)->size == 0; } STC_INLINE void cstr_drop(cstr* self) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index a6d4beb1..8116fce2 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -163,9 +163,6 @@ STC_INLINE bool cstr_empty(cstr s) STC_INLINE size_t cstr_size(cstr s) { return SSO_CALL(&s, size(&s)); } -STC_INLINE size_t cstr_length(cstr s) - { return SSO_CALL(&s, size(&s)); } - STC_INLINE size_t cstr_capacity(cstr s) { return cstr_is_long(&s) ? cstr_l_cap(&s) : cstr_s_cap; } diff --git a/include/stc/csview.h b/include/stc/csview.h index 6d12901b..4bdf3af2 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -43,7 +43,6 @@ STC_INLINE csview csview_from_n(const char* str, size_t n) STC_INLINE void csview_clear(csview* self) { *self = csview_null; } STC_INLINE size_t csview_size(csview sv) { return sv.size; } -STC_INLINE size_t csview_length(csview sv) { return sv.size; } STC_INLINE bool csview_empty(csview sv) { return sv.size == 0; } STC_INLINE bool csview_equals(csview sv, csview sv2) @@ -93,7 +92,7 @@ STC_INLINE void csview_next(csview_iter* it) STC_INLINE size_t csview_u8size(csview sv) { return utf8_size_n(sv.str, sv.size); } -STC_INLINE csview csview_u8substr(csview sv, size_t u8pos, size_t u8len) { +STC_INLINE csview csview_substr_u8(csview sv, size_t u8pos, size_t u8len) { sv.str = utf8_at(sv.str, u8pos); sv.size = utf8_pos(sv.str, u8len); return sv; diff --git a/include/stc/utf8.h b/include/stc/utf8.h index 31ea3aa9..fb06de62 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -41,7 +41,7 @@ bool utf8_valid_n(const char* s, size_t nbytes); int utf8_icmp_n(size_t u8max, const char* s1, size_t n1, const char* s2, size_t n2); unsigned utf8_encode(char *out, uint32_t c); -uint32_t utf8_peek(const char *s, int pos); +uint32_t utf8_peek(const char *s, int u8pos); /* decode next utf8 codepoint. https://bjoern.hoehrmann.de/utf-8/decoder/dfa */ typedef struct { uint32_t state, codep; } utf8_decode_t; diff --git a/src/utf8code.c b/src/utf8code.c index f64ede70..b67ee36e 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -45,7 +45,7 @@ unsigned utf8_encode(char *out, uint32_t c) return 0; } -uint32_t utf8_peek(const char* s, int pos) { +uint32_t utf8_peek(const char* s, int u8pos) { int inc = -1; if (pos > 0) pos = -pos, inc = 1; |
