summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/crawstr_api.md2
-rw-r--r--docs/csview_api.md2
-rw-r--r--include/stc/crawstr.h11
-rw-r--r--include/stc/cstr.h6
-rw-r--r--include/stc/csview.h6
-rw-r--r--include/stc/forward.h7
-rw-r--r--misc/examples/strings/utf8replace_c.c2
7 files changed, 20 insertions, 16 deletions
diff --git a/docs/crawstr_api.md b/docs/crawstr_api.md
index 97804e23..7d663a04 100644
--- a/docs/crawstr_api.md
+++ b/docs/crawstr_api.md
@@ -85,7 +85,7 @@ int main(void)
printf("%s\n", rs.str);
c_foreach (i, crawstr, rs)
- printf("%.*s ", c_SV(i.u8.chr));
+ printf("%.*s ", c_SV(i.chr));
puts("");
cstr str = cstr_toupper_sv(crawstr_sv(rs));
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 5202d6f5..1d58d73c 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -149,7 +149,7 @@ int main(void)
printf("%s\n", cstr_str(&s1));
c_foreach (i, cstr, s1)
- printf("%.*s,", c_SV(i.u8.chr));
+ printf("%.*s,", c_SV(i.chr));
cstr_drop(&s1);
}
diff --git a/include/stc/crawstr.h b/include/stc/crawstr.h
index 3b836222..0395c8c6 100644
--- a/include/stc/crawstr.h
+++ b/include/stc/crawstr.h
@@ -27,12 +27,13 @@
#define CRAWSTR_H_INCLUDED
#define crawstr_init() c_rs("")
-#define crawstr_drop(p) c_default_drop(p)
#define crawstr_clone(rs) c_default_clone(rs)
+#define crawstr_drop(self) c_default_drop(self)
+#define crawstr_toraw(self) (self)->str
STC_INLINE crawstr crawstr_from(const char* str)
{ return c_rs_2(str, c_strlen(str)); }
-STC_INLINE void crawstr_clear(crawstr* self) { *self = crawstr_init(); }
+STC_INLINE void crawstr_clear(crawstr* self) { *self = c_rs(""); }
STC_INLINE csview crawstr_sv(crawstr rs) { return c_sv_2(rs.str, rs.size); }
STC_INLINE intptr_t crawstr_size(crawstr rs) { return rs.size; }
@@ -70,15 +71,15 @@ STC_INLINE crawstr_iter crawstr_end(const crawstr* self) {
(void)self; return c_LITERAL(crawstr_iter){.ref = NULL};
}
STC_INLINE void crawstr_next(crawstr_iter* it) {
- it->ref += it->u8.chr.size;
- it->u8.chr.size = utf8_chr_size(it->ref);
+ it->ref += it->chr.size;
+ it->chr.size = utf8_chr_size(it->ref);
if (!*it->ref) it->ref = NULL;
}
STC_INLINE crawstr_iter crawstr_advance(crawstr_iter it, intptr_t pos) {
int inc = -1;
if (pos > 0) pos = -pos, inc = 1;
while (pos && *it.ref) pos += (*(it.ref += inc) & 0xC0) != 0x80;
- it.u8.chr.size = utf8_chr_size(it.ref);
+ it.chr.size = utf8_chr_size(it.ref);
if (!*it.ref) it.ref = NULL;
return it;
}
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index eeb65c39..f0974865 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -217,15 +217,15 @@ STC_INLINE cstr_iter cstr_end(const cstr* self) {
(void)self; return c_LITERAL(cstr_iter){NULL};
}
STC_INLINE void cstr_next(cstr_iter* it) {
- it->ref += it->u8.chr.size;
- it->u8.chr.size = utf8_chr_size(it->ref);
+ it->ref += it->chr.size;
+ it->chr.size = utf8_chr_size(it->ref);
if (!*it->ref) it->ref = NULL;
}
STC_INLINE cstr_iter cstr_advance(cstr_iter it, intptr_t pos) {
int inc = -1;
if (pos > 0) pos = -pos, inc = 1;
while (pos && *it.ref) pos += (*(it.ref += inc) & 0xC0) != 0x80;
- it.u8.chr.size = utf8_chr_size(it.ref);
+ it.chr.size = utf8_chr_size(it.ref);
if (!*it.ref) it.ref = NULL;
return it;
}
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 5aba6926..a2d1e9f0 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -89,8 +89,8 @@ STC_INLINE csview_iter csview_end(const csview* self) {
return c_LITERAL(csview_iter){.u8 = {{NULL}, self->buf + self->size}};
}
STC_INLINE void csview_next(csview_iter* it) {
- it->ref += it->u8.chr.size;
- it->u8.chr.size = utf8_chr_size(it->ref);
+ it->ref += it->chr.size;
+ it->chr.size = utf8_chr_size(it->ref);
if (it->ref == it->u8.end) it->ref = NULL;
}
@@ -159,7 +159,7 @@ STC_DEF csview_iter csview_advance(csview_iter it, intptr_t pos) {
int inc = -1;
if (pos > 0) pos = -pos, inc = 1;
while (pos && it.ref != it.u8.end) pos += (*(it.ref += inc) & 0xC0) != 0x80;
- it.u8.chr.size = utf8_chr_size(it.ref);
+ it.chr.size = utf8_chr_size(it.ref);
if (it.ref == it.u8.end) it.ref = NULL;
return it;
}
diff --git a/include/stc/forward.h b/include/stc/forward.h
index 9f7a0063..2372a618 100644
--- a/include/stc/forward.h
+++ b/include/stc/forward.h
@@ -48,6 +48,7 @@ typedef struct csview {
typedef union {
csview_value* ref;
+ csview chr;
struct { csview chr; csview_value* end; } u8;
} csview_iter;
@@ -61,7 +62,8 @@ typedef struct crawstr {
typedef union {
crawstr_value* ref;
- struct { csview chr; } u8;
+ csview chr;
+ struct { csview chr; } u8; // [deprecated]
} crawstr_iter;
@@ -75,7 +77,8 @@ typedef union cstr {
typedef union {
cstr_value* ref;
- struct { csview chr; } u8;
+ csview chr;
+ struct { csview chr; } u8; // [deprecated]
} cstr_iter;
diff --git a/misc/examples/strings/utf8replace_c.c b/misc/examples/strings/utf8replace_c.c
index 1d54486f..317313b0 100644
--- a/misc/examples/strings/utf8replace_c.c
+++ b/misc/examples/strings/utf8replace_c.c
@@ -15,7 +15,7 @@ int main(void)
printf("%s\n", cstr_str(&hello));
c_foreach (c, cstr, hello)
- printf("%.*s,", c_SV(c.u8.chr));
+ printf("%.*s,", c_SV(c.chr));
cstr str = cstr_lit("scooby, dooby doo");
cstr_replace(&str, "oo", "00");