summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-08-17 22:08:15 +0200
committerTyge Lovset <[email protected]>2022-08-18 09:05:24 +0200
commitc5144785aaac11a30439064decabef62968b00a4 (patch)
treee0f17c82ac1c529261d4a414158bae17c380060f /include
parenta06463c2f0747bc142a9d5b2bf455c64aaf39890 (diff)
downloadSTC-modified-c5144785aaac11a30439064decabef62968b00a4.tar.gz
STC-modified-c5144785aaac11a30439064decabef62968b00a4.zip
Some API updates cstr, csview with utf8. Added front()/back() to cstack.
Diffstat (limited to 'include')
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/cstack.h6
-rw-r--r--include/stc/cstr.h4
-rw-r--r--include/stc/csview.h14
4 files changed, 13 insertions, 13 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 79d12b95..bfc09106 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -82,7 +82,7 @@ STC_INLINE bool _cx_memb(_empty)(const _cx_self* q)
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* q)
{ return q->capacity; }
-STC_INLINE _cx_value* _cx_memb(_top)(const _cx_self* self)
+STC_INLINE const _cx_value* _cx_memb(_top)(const _cx_self* self)
{ return &self->data[0]; }
STC_INLINE void _cx_memb(_pop)(_cx_self* self)
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index e1839d37..9ed2beda 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -120,6 +120,12 @@ STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self)
STC_INLINE const _cx_value* _cx_memb(_top)(const _cx_self* self)
{ return &self->data[self->size - 1]; }
+STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self)
+ { return (_cx_value*) &self->data[self->size - 1]; }
+
+STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self)
+ { return (_cx_value*) &self->data[0]; }
+
STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) {
if (self->size == _cx_memb(_capacity)(self))
if (!_cx_memb(_reserve)(self, self->size*3/2 + 4))
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 99b60e49..b731289b 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -370,8 +370,8 @@ STC_INLINE void cstr_replace_at(cstr* self, size_t pos, size_t len, const char*
STC_INLINE void cstr_replace_at_s(cstr* self, size_t pos, size_t len, cstr repl)
{ cstr_replace_at_sv(self, pos, len, cstr_sv(&repl)); }
-STC_INLINE void cstr_u8_replace(cstr* self, size_t pos, size_t u8len, csview repl)
- { cstr_replace_at_sv(self, pos, utf8_pos(cstr_str(self) + pos, u8len), repl); }
+STC_INLINE void cstr_u8_replace(cstr* self, size_t bytepos, size_t u8len, csview repl)
+ { cstr_replace_at_sv(self, bytepos, utf8_pos(cstr_str(self) + bytepos, u8len), repl); }
STC_INLINE void cstr_insert(cstr* self, size_t pos, const char* str)
diff --git a/include/stc/csview.h b/include/stc/csview.h
index dbff8620..555dd538 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -90,15 +90,12 @@ STC_INLINE void csview_next(csview_iter* it) {
STC_INLINE size_t csview_u8_size(csview sv)
{ return utf8_size_n(sv.str, sv.size); }
-STC_INLINE csview csview_u8_substr(csview sv, size_t u8pos, size_t u8len) {
- sv.str = utf8_at(sv.str, u8pos);
+STC_INLINE csview csview_u8_substr(csview sv, size_t bytepos, size_t u8len) {
+ sv.str += bytepos;
sv.size = utf8_pos(sv.str, u8len);
return sv;
}
-STC_INLINE csview csview_u8_slice(csview sv, size_t u8p1, size_t u8p2)
- { return csview_u8_substr(sv, u8p1, u8p2 - u8p1); }
-
STC_INLINE bool csview_valid_utf8(csview sv) // depends on src/utf8code.c
{ return utf8_valid_n(sv.str, sv.size); }
@@ -121,11 +118,8 @@ STC_INLINE csview cstr_substr_ex(const cstr* self, intptr_t pos, size_t n)
STC_INLINE csview cstr_slice_ex(const cstr* self, intptr_t p1, intptr_t p2)
{ return csview_slice_ex(cstr_sv(self), p1, p2); }
-STC_INLINE csview cstr_u8_substr(const cstr* self , size_t u8pos, size_t u8len)
- { return csview_u8_substr(cstr_sv(self), u8pos, u8len); }
-
-STC_INLINE csview cstr_u8_slice(const cstr* self , size_t u8p1, size_t u8p2)
- { return csview_u8_substr(cstr_sv(self), u8p1, u8p2 - u8p1); }
+STC_INLINE csview cstr_u8_substr(const cstr* self , size_t bytepos, size_t u8len)
+ { return csview_u8_substr(cstr_sv(self), bytepos, u8len); }
#endif
/* ---- Container helper functions ---- */