summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-03-16 21:41:40 +0100
committerTyge Løvset <[email protected]>2022-03-16 21:41:40 +0100
commit0468971b404cee5582d360d7d1c66bb4148e1614 (patch)
tree9161ccbea490a5dab70e641f7bd568521a5da636 /include
parent342484f70998258022c26e6af2926ecc7635bbdd (diff)
downloadSTC-modified-0468971b404cee5582d360d7d1c66bb4148e1614.tar.gz
STC-modified-0468971b404cee5582d360d7d1c66bb4148e1614.zip
Bugfix: carc and cbox cmp functions had bug.
Renamed: i_key_sptr / i_val_sptr to i_key_arcbox / i_val_arcbox. Other smaller updates.
Diffstat (limited to 'include')
-rw-r--r--include/stc/carc.h4
-rw-r--r--include/stc/cbox.h4
-rw-r--r--include/stc/cdeq.h2
-rw-r--r--include/stc/csview.h6
-rw-r--r--include/stc/cvec.h4
-rw-r--r--include/stc/forward.h36
-rw-r--r--include/stc/template.h26
-rw-r--r--include/stc/utf8.h10
8 files changed, 48 insertions, 44 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h
index e3deb376..7ea1eb8e 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -187,7 +187,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
- _cx_raw rx = i_valto(x), ry = i_valto(x);
+ _cx_raw rx = i_valto(x), ry = i_valto(y);
return i_cmp(&rx, &ry);
#endif
}
@@ -197,7 +197,7 @@ _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return x == y;
#else
- _cx_raw rx = i_valto(x), ry = i_valto(x);
+ _cx_raw rx = i_valto(x), ry = i_valto(y);
return i_eq(&rx, &ry);
#endif
}
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 41d8f654..7b1cf377 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -163,7 +163,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
- _cx_raw rx = i_valto(x), ry = i_valto(x);
+ _cx_raw rx = i_valto(x), ry = i_valto(y);
return i_cmp(&rx, &ry);
#endif
}
@@ -173,7 +173,7 @@ _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return x == y;
#else
- _cx_raw rx = i_valto(x), ry = i_valto(x);
+ _cx_raw rx = i_valto(x), ry = i_valto(y);
return i_eq(&rx, &ry);
#endif
}
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index cb291fbe..6b8e7efa 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -400,7 +400,7 @@ STC_DEF _cx_iter
_cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, i_valraw raw) {
for (; i1.ref != i2.ref; ++i1.ref) {
i_valraw r = i_valto(i1.ref);
- if (i_cmp(&raw, &r) == 0) return i1;
+ if (i_eq(&raw, &r)) return i1;
}
return i2;
}
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 85ade552..cd482b2c 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -66,11 +66,11 @@ 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_codep_size(self->str)}}; }
+ { return c_make(csview_iter){.codep = {self->str, utf8_codep_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_codep_size(it->ref); }
+ { it->ref += it->codep.size; it->codep.size = utf8_codep_size(it->ref); }
/* utf8 */
STC_INLINE bool utf8_valid_sv(csview sv)
@@ -82,7 +82,7 @@ STC_INLINE size_t utf8_size_sv(csview sv)
STC_INLINE csview utf8_substr(const char* str, size_t pos, size_t n) {
csview sv;
sv.str = utf8_at(str, pos);
- sv.size = utf8_at(sv.str, n) - sv.str;
+ sv.size = utf8_pos(sv.str, n);
return sv;
}
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 9278eada..f3ae9d47 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -209,7 +209,7 @@ _cx_memb(_find)(const _cx_self* self, i_valraw raw) {
STC_INLINE const _cx_value*
_cx_memb(_get)(const _cx_self* self, i_valraw raw) {
_cx_iter end = _cx_memb(_end)(self);
- _cx_value* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref;
+ _cx_value* val = _cx_memb(_find)(self, raw).ref;
return val == end.ref ? NULL : val;
}
@@ -368,7 +368,7 @@ STC_DEF _cx_iter
_cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, i_valraw raw) {
for (; i1.ref != i2.ref; ++i1.ref) {
i_valraw r = i_valto(i1.ref);
- if (i_cmp(&raw, &r) == 0) return i1;
+ if (i_eq(&raw, &r)) return i1;
}
return i2;
}
diff --git a/include/stc/forward.h b/include/stc/forward.h
index 6f450219..bffdf154 100644
--- a/include/stc/forward.h
+++ b/include/stc/forward.h
@@ -25,8 +25,10 @@
#include <stddef.h>
+#define forward_carc(CX, VAL) _c_carc_types(CX, VAL)
#define forward_carr2(CX, VAL) _c_carr2_types(CX, VAL)
#define forward_carr3(CX, VAL) _c_carr3_types(CX, VAL)
+#define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL)
#define forward_cdeq(CX, VAL) _c_cdeq_types(CX, VAL)
#define forward_clist(CX, VAL) _c_clist_types(CX, VAL)
#define forward_cmap(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, uint32_t, c_true, c_false)
@@ -35,10 +37,8 @@
#define forward_cset_huge(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, size_t, c_false, c_true)
#define forward_csmap(CX, KEY, VAL) _c_aatree_types(CX, KEY, VAL, uint32_t, c_true, c_false)
#define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, uint32_t, c_false, c_true)
-#define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL)
-#define forward_carc(CX, VAL) _c_carc_types(CX, VAL)
-#define forward_cpque(CX, VAL) _c_cpque_types(CX, VAL)
#define forward_cstack(CX, VAL) _c_cstack_types(CX, VAL)
+#define forward_cpque(CX, VAL) _c_cpque_types(CX, VAL)
#define forward_cqueue(CX, VAL) _c_cdeq_types(CX, VAL)
#define forward_cvec(CX, VAL) _c_cvec_types(CX, VAL)
@@ -46,12 +46,20 @@ typedef struct cstr { char* str; } cstr;
typedef char cstr_value;
typedef struct csview { const char* str; size_t size; } csview;
-typedef union csview_iter { const char *ref; csview cp; } csview_iter;
+typedef union csview_iter { const char *ref; csview codep; } csview_iter;
typedef char csview_value;
#define c_true(...) __VA_ARGS__
#define c_false(...)
+#define _c_carc_types(SELF, VAL) \
+ typedef VAL SELF##_value; \
+\
+ typedef struct { \
+ SELF##_value* get; \
+ long* use_count; \
+ } SELF
+
#define _c_carr2_types(SELF, VAL) \
typedef VAL SELF##_value; \
typedef struct { SELF##_value *ref; } SELF##_iter; \
@@ -62,6 +70,12 @@ typedef char csview_value;
typedef struct { SELF##_value *ref; } SELF##_iter; \
typedef struct { SELF##_value ***data; size_t xdim, ydim, zdim; } SELF
+#define _c_cbox_types(SELF, VAL) \
+ typedef VAL SELF##_value; \
+ typedef struct { \
+ SELF##_value* get; \
+ } SELF
+
#define _c_cdeq_types(SELF, VAL) \
typedef VAL SELF##_value; \
typedef struct {SELF##_value *ref; } SELF##_iter; \
@@ -132,20 +146,6 @@ typedef char csview_value;
SELF##_node *nodes; \
} SELF
-#define _c_cbox_types(SELF, VAL) \
- typedef VAL SELF##_value; \
- typedef struct { \
- SELF##_value* get; \
- } SELF
-
-#define _c_carc_types(SELF, VAL) \
- typedef VAL SELF##_value; \
-\
- typedef struct { \
- SELF##_value* get; \
- long* use_count; \
- } SELF
-
#define _c_cstack_types(SELF, VAL) \
typedef VAL SELF##_value; \
typedef struct { SELF##_value *ref; } SELF##_iter; \
diff --git a/include/stc/template.h b/include/stc/template.h
index c61aded4..12c015f6 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -40,9 +40,11 @@
#define _cx_size _cx_memb(_size_t)
#endif
-#if defined i_cnt || defined i_equ // [deprecated]
- #define i_type i_cnt
- #error "i_cnt and i_equ no longer supported: use new name i_type / i_eq"
+#ifdef i_key_sptr // [deprecated]
+ #define i_key_arcbox i_key_sptr
+#endif
+#ifdef i_val_sptr // [deprecated]
+ #define i_val_arcbox i_val_sptr
#endif
#ifdef i_type
#define i_tag i_type
@@ -64,9 +66,9 @@
#ifndef i_tag
#define i_tag str
#endif
-#elif defined i_key_sptr
- #define i_key_bind i_key_sptr
- #define i_keyraw c_PASTE(i_key_sptr, _value)
+#elif defined i_key_arcbox
+ #define i_key_bind i_key_arcbox
+ #define i_keyraw c_PASTE(i_key_arcbox, _value)
#endif
#ifdef i_key_bind
@@ -123,9 +125,9 @@
#if !defined i_tag && !defined i_key
#define i_tag str
#endif
-#elif defined i_val_sptr
- #define i_val_bind i_val_sptr
- #define i_valraw c_PASTE(i_val_sptr, _value)
+#elif defined i_val_arcbox
+ #define i_val_bind i_val_arcbox
+ #define i_valraw c_PASTE(i_val_arcbox, _value)
#endif
#ifdef i_val_bind
@@ -221,10 +223,11 @@
#undef i_hash
#undef i_from
#undef i_drop
+#undef i_size
#undef i_val
#undef i_val_str
-#undef i_val_sptr
+#undef i_val_arcbox
#undef i_val_bind
#undef i_valraw
#undef i_valfrom
@@ -233,13 +236,12 @@
#undef i_key
#undef i_key_str
-#undef i_key_sptr
+#undef i_key_arcbox
#undef i_key_bind
#undef i_keyraw
#undef i_keyfrom
#undef i_keyto
#undef i_keydrop
-#undef i_size
#undef _i_prefix
#undef _i_no_raw
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index 60599519..0a1ba161 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -9,17 +9,19 @@ int main()
{
c_auto (cstr, s1) {
s1 = cstr_new("hell😀 w😀rld");
- cstr_replace_sv(&s1, utf8_substr(s1.str, 7, 1), c_sv("x"));
+ printf("%s\n", s1.str);
+ cstr_replace_sv(&s1, utf8_substr(s1.str, 7, 1), c_sv("🐨"));
printf("%s\n", s1.str);
csview sv = csview_from_s(s1);
c_foreach (i, csview, sv)
- printf(c_PRIsv ",", c_ARGsv(i.cp));
+ printf(c_PRIsv ",", c_ARGsv(i.codep));
}
}
// Output:
-// hell😀 wxrld
-// h,e,l,l,😀, ,w,x,r,l,d,
+// hell😀 w😀rld
+// hell😀 w🐨rld
+// h,e,l,l,😀, ,w,🐨,r,l,d,
*/
#include "ccommon.h"
#include <ctype.h>