summaryrefslogtreecommitdiffhomepage
path: root/include/stc/csview.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-31 18:55:08 +0100
committerTyge Løvset <[email protected]>2023-01-31 18:55:08 +0100
commitb677a0c3950b8294ba6458e682a885351273ac08 (patch)
treef309f7f7571fb588f0f65254d17fa09d678a8e3c /include/stc/csview.h
parenta24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e (diff)
downloadSTC-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/csview.h')
-rw-r--r--include/stc/csview.h74
1 files changed, 37 insertions, 37 deletions
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 4df735b3..a30672cd 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -34,41 +34,41 @@
#define csview_lit(literal) c_SV_1(literal)
#define csview_from_n(str, n) c_SV_2(str, n)
-STC_API size_t csview_find_sv(csview sv, csview search);
+STC_API intptr_t csview_find_sv(csview sv, csview search);
STC_INLINE csview csview_from(const char* str)
- { return c_LITERAL(csview){str, strlen(str)}; }
+ { return c_LITERAL(csview){str, c_strlen(str)}; }
STC_INLINE void csview_clear(csview* self) { *self = csview_NULL; }
-STC_INLINE size_t csview_size(csview sv) { return sv.size; }
+STC_INLINE intptr_t csview_size(csview sv) { return sv.size; }
STC_INLINE bool csview_empty(csview sv) { return sv.size == 0; }
STC_INLINE bool csview_equals(csview sv, const char* str)
- { size_t n = strlen(str); return sv.size == n && !memcmp(sv.str, str, n); }
+ { intptr_t n = c_strlen(str); return sv.size == n && !c_memcmp(sv.str, str, n); }
-STC_INLINE size_t csview_find(csview sv, const char* str)
- { return csview_find_sv(sv, c_SV(str, strlen(str))); }
+STC_INLINE intptr_t csview_find(csview sv, const char* str)
+ { return csview_find_sv(sv, c_SV(str, c_strlen(str))); }
STC_INLINE bool csview_contains(csview sv, const char* str)
{ return csview_find(sv, str) != c_NPOS; }
STC_INLINE bool csview_starts_with(csview sv, const char* str) {
- size_t n = strlen(str);
- return n > sv.size ? false : !memcmp(sv.str, str, n);
+ intptr_t n = c_strlen(str);
+ return n > sv.size ? false : !c_memcmp(sv.str, str, n);
}
STC_INLINE bool csview_ends_with(csview sv, const char* str) {
- size_t n = strlen(str);
- return n > sv.size ? false : !memcmp(sv.str + sv.size - n, str, n);
+ intptr_t n = c_strlen(str);
+ return n > sv.size ? false : !c_memcmp(sv.str + sv.size - n, str, n);
}
-STC_INLINE csview csview_substr(csview sv, size_t pos, size_t n) {
+STC_INLINE csview csview_substr(csview sv, intptr_t pos, intptr_t n) {
if (pos + n > sv.size) n = sv.size - pos;
sv.str += pos, sv.size = n;
return sv;
}
-STC_INLINE csview csview_slice(csview sv, size_t p1, size_t p2) {
+STC_INLINE csview csview_slice(csview sv, intptr_t p1, intptr_t p2) {
if (p2 > sv.size) p2 = sv.size;
sv.str += p1, sv.size = p2 > p1 ? p2 - p1 : 0;
return sv;
@@ -99,10 +99,10 @@ STC_INLINE csview_iter csview_advance(csview_iter it, intptr_t pos) {
/* utf8 */
-STC_INLINE size_t csview_u8_size(csview sv)
+STC_INLINE intptr_t csview_u8_size(csview sv)
{ return utf8_size_n(sv.str, sv.size); }
-STC_INLINE csview csview_u8_substr(csview sv, size_t bytepos, size_t u8len) {
+STC_INLINE csview csview_u8_substr(csview sv, intptr_t bytepos, intptr_t u8len) {
sv.str += bytepos;
sv.size = utf8_pos(sv.str, u8len);
return sv;
@@ -111,12 +111,12 @@ STC_INLINE csview csview_u8_substr(csview sv, size_t bytepos, size_t u8len) {
STC_INLINE bool csview_valid_utf8(csview sv) // depends on src/utf8code.c
{ return utf8_valid_n(sv.str, sv.size); }
-STC_API csview csview_substr_ex(csview sv, intptr_t pos, size_t n);
+STC_API csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
-STC_API csview csview_token(csview sv, const char* sep, size_t* start);
+STC_API csview csview_token(csview sv, const char* sep, intptr_t* start);
#define c_FORTOKEN_SV(it, inputsv, sep) \
- for (struct { csview _inp, token, *ref; const char *_sep; size_t pos; } \
+ for (struct { csview _inp, token, *ref; const char *_sep; intptr_t pos; } \
it = {._inp=inputsv, .token=it._inp, .ref=&it.token, ._sep=sep} \
; it.pos <= it._inp.size && (it.token = csview_token(it._inp, it._sep, &it.pos)).str ; )
@@ -126,27 +126,27 @@ STC_API csview csview_token(csview sv, const char* sep, size_t* start);
/* csview interaction with cstr: */
#ifdef CSTR_H_INCLUDED
-STC_INLINE csview cstr_substr(const cstr* self, size_t pos, size_t n)
+STC_INLINE csview cstr_substr(const cstr* self, intptr_t pos, intptr_t n)
{ return csview_substr(cstr_sv(self), pos, n); }
-STC_INLINE csview cstr_slice(const cstr* self, size_t p1, size_t p2)
+STC_INLINE csview cstr_slice(const cstr* self, intptr_t p1, intptr_t p2)
{ return csview_slice(cstr_sv(self), p1, p2); }
-STC_INLINE csview cstr_substr_ex(const cstr* self, intptr_t pos, size_t n)
+STC_INLINE csview cstr_substr_ex(const cstr* self, intptr_t pos, intptr_t n)
{ return csview_substr_ex(cstr_sv(self), pos, 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 bytepos, size_t u8len)
+STC_INLINE csview cstr_u8_substr(const cstr* self , intptr_t bytepos, intptr_t u8len)
{ return csview_u8_substr(cstr_sv(self), bytepos, u8len); }
#endif
/* ---- Container helper functions ---- */
STC_INLINE int csview_cmp(const csview* x, const csview* y) {
- size_t n = x->size < y->size ? x->size : y->size;
- int c = memcmp(x->str, y->str, n);
+ intptr_t n = x->size < y->size ? x->size : y->size;
+ int c = c_memcmp(x->str, y->str, n);
return c ? c : (int)(x->size - y->size);
}
@@ -154,48 +154,48 @@ STC_INLINE int csview_icmp(const csview* x, const csview* y)
{ return utf8_icmp_sv(*x, *y); }
STC_INLINE bool csview_eq(const csview* x, const csview* y)
- { return x->size == y->size && !memcmp(x->str, y->str, x->size); }
+ { return x->size == y->size && !c_memcmp(x->str, y->str, x->size); }
STC_API uint64_t csview_hash(const csview *self);
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement)
-STC_DEF size_t csview_find_sv(csview sv, csview search) {
+STC_DEF intptr_t csview_find_sv(csview sv, csview search) {
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
- return res ? (size_t)(res - sv.str) : c_NPOS;
+ return res ? (res - sv.str) : c_NPOS;
}
STC_DEF uint64_t csview_hash(const csview *self)
{ return cfasthash(self->str, self->size); }
-STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, size_t n) {
+STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
if (pos < 0) {
- pos += (intptr_t)sv.size;
+ pos += sv.size;
if (pos < 0) pos = 0;
}
- if ((size_t)pos > sv.size) pos = (intptr_t)sv.size;
- if ((size_t)pos + n > sv.size) n = sv.size - (size_t)pos;
+ if (pos > sv.size) pos = sv.size;
+ if (pos + n > sv.size) n = sv.size - pos;
sv.str += pos, sv.size = n;
return sv;
}
STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
if (p1 < 0) {
- p1 += (intptr_t)sv.size;
+ p1 += sv.size;
if (p1 < 0) p1 = 0;
}
- if (p2 < 0) p2 += (intptr_t)sv.size;
- if (p2 > (intptr_t)sv.size) p2 = (intptr_t)sv.size;
- sv.str += p1, sv.size = (size_t)(p2 > p1 ? p2 - p1 : 0);
+ if (p2 < 0) p2 += sv.size;
+ if (p2 > sv.size) p2 = sv.size;
+ sv.str += p1, sv.size = (p2 > p1 ? p2 - p1 : 0);
return sv;
}
-STC_DEF csview csview_token(csview sv, const char* sep, size_t* start) {
- size_t sep_size = strlen(sep);
+STC_DEF csview csview_token(csview sv, const char* sep, intptr_t* start) {
+ intptr_t sep_size = c_strlen(sep);
csview slice = {sv.str + *start, sv.size - *start};
const char* res = cstrnstrn(slice.str, sep, slice.size, sep_size);
- csview tok = {slice.str, res ? (size_t)(res - slice.str) : slice.size};
+ csview tok = {slice.str, res ? (res - slice.str) : slice.size};
*start += tok.size + sep_size;
return tok;
}