summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-09 19:31:59 +0200
committerTyge Løvset <[email protected]>2023-06-09 19:31:59 +0200
commit72b0f0e7839b487a5df7c79ffe84511480cad251 (patch)
treee38e997c39bbaad183250c39971222e48bb2d59e /include/stc
parentabd3b4372dee2291a81271f02588228279139960 (diff)
downloadSTC-modified-72b0f0e7839b487a5df7c79ffe84511480cad251.tar.gz
STC-modified-72b0f0e7839b487a5df7c79ffe84511480cad251.zip
Fixed issues with linking params i_implement, i_extern.
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/cbits.h6
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/cdeq.h2
-rw-r--r--include/stc/clist.h2
-rw-r--r--include/stc/cmap.h2
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/cqueue.h2
-rw-r--r--include/stc/crand.h2
-rw-r--r--include/stc/cregex.h10
-rw-r--r--include/stc/csmap.h2
-rw-r--r--include/stc/cspan.h2
-rw-r--r--include/stc/cstr.h102
-rw-r--r--include/stc/csview.h36
-rw-r--r--include/stc/cvec.h2
-rw-r--r--include/stc/forward.h1
-rw-r--r--include/stc/utf8.h16
16 files changed, 102 insertions, 89 deletions
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index fe422202..8a6558bf 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -161,9 +161,9 @@ STC_INLINE void cbits_resize(cbits* self, const int64_t size, const bool value)
if (new_n >= old_n) {
c_memset(self->data64 + old_n, -(int)value, (new_n - old_n)*8);
if (old_n > 0) {
- uint64_t m = _cbits_bit(osize) - 1; /* mask */
- value ? (self->data64[old_n - 1] |= ~m)
- : (self->data64[old_n - 1] &= m);
+ uint64_t mask = _cbits_bit(osize) - 1;
+ if (value) self->data64[old_n - 1] |= ~mask;
+ else self->data64[old_n - 1] &= mask;
}
}
}
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 01ead57a..87522a6e 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -253,6 +253,6 @@ STC_INLINE intptr_t cnextpow2(intptr_t n) {
#if defined(STC_EXTERN)
#define i_extern
#endif
-#if defined(i_static) || defined(STC_IMPLEMENT) || defined(i_extern)
+#if defined(STC_IMPLEMENT) || defined(i_extern)
#define i_implement
#endif
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index b3714bf8..8bb62602 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -113,7 +113,7 @@ _cx_memb(_get_mut)(_cx_self* self, _cx_raw raw)
#endif
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
STC_DEF _cx_value*
_cx_memb(_push_front)(_cx_self* self, i_key value) {
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 128e848d..310db204 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -214,7 +214,7 @@ STC_INLINE bool _cx_memb(_eq)(const _cx_self* self, const _cx_self* other) {
#endif
// -------------------------- IMPLEMENTATION -------------------------
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
#if !defined i_no_clone
STC_DEF _cx_self
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 837631f8..f6c3eb07 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -261,7 +261,7 @@ _cx_memb(_eq)(const _cx_self* self, const _cx_self* other) {
}
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
#ifndef i_max_load_factor
#define i_max_load_factor 0.80f
#endif
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 85002c67..31a53ece 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -108,7 +108,7 @@ STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
#endif // !i_no_emplace
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
STC_DEF void
_cx_memb(_sift_down_)(_cx_self* self, const intptr_t idx, const intptr_t n) {
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index 571c1fe9..28515877 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -121,7 +121,7 @@ STC_INLINE void _cx_memb(_adjust_end_)(_cx_self* self, intptr_t n)
{ self->end = (self->end + n) & self->capmask; }
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
STC_DEF _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t n) {
intptr_t len = _cx_memb(_size)(it._s);
diff --git a/include/stc/crand.h b/include/stc/crand.h
index f566c1cf..b9687c01 100644
--- a/include/stc/crand.h
+++ b/include/stc/crand.h
@@ -92,7 +92,7 @@ STC_INLINE double crand_f64(crand_t* rng) {
}
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
/* Global random() */
static crand_t crand_global = {{
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index 919f5474..e6180a31 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -135,7 +135,7 @@ STC_INLINE bool cregex_is_match(const cregex* re, const char* input)
#define cregex_replace_sv_4(pattern, input, replace, count) \
cregex_replace_sv_6(pattern, input, replace, count, NULL, CREG_DEFAULT)
cstr cregex_replace_sv_6(const cregex* re, csview input, const char* replace, int count,
- bool (*mfun)(int i, csview match, cstr* mstr), int rflags);
+ bool (*transform)(int group, csview match, cstr* result), int rflags);
/* replace input with replace using regular expression */
#define cregex_replace(...) c_MACRO_OVERLOAD(cregex_replace, __VA_ARGS__)
@@ -153,20 +153,20 @@ STC_INLINE cstr cregex_replace_4(const cregex* re, const char* input, const char
#define cregex_replace_pattern_4(pattern, input, replace, count) \
cregex_replace_pattern_6(pattern, input, replace, count, NULL, CREG_DEFAULT)
cstr cregex_replace_pattern_6(const char* pattern, const char* input, const char* replace, int count,
- bool (*mfun)(int i, csview match, cstr* mstr), int crflags);
+ bool (*transform)(int group, csview match, cstr* result), int crflags);
/* destroy regex */
void cregex_drop(cregex* re);
-#endif // CREGEX_H_INCLUDED
-#if defined i_extern || defined i_implement
+#if defined i_implement
# include "../../src/cregex.c"
#endif
#if defined i_extern
# include "../../src/utf8code.c"
#endif
+#endif // CREGEX_H_INCLUDED
#undef i_opt
#undef i_header
#undef i_static
-#undef i_implement
#undef i_extern
+#undef i_implement
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index e8138926..7638b8f2 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -249,7 +249,7 @@ _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n)
{ _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; }
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
STC_DEF void
_cx_memb(_next)(_cx_iter *it) {
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index b07e75a8..5b592098 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -212,7 +212,7 @@ STC_API intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
int rank, const int32_t a[][2]);
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
STC_DEF intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t stri[], const int32_t a[]) {
intptr_t off = a[0];
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 03eefd2f..ae80dab4 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -24,16 +24,12 @@
/* A string type with short string optimization in C99 with good small-string
* optimization (22 characters with 24 bytes string).
*/
+#define _i_no_undef
+#include "utf8.h"
+
#ifndef CSTR_H_INCLUDED
#define CSTR_H_INCLUDED
-#define i_header
-#if defined i_extern || defined STC_EXTERN
-# define _i_extern
-#endif
-#include "ccommon.h"
-#include "forward.h"
-#include "utf8.h"
#include <stdlib.h> /* malloc */
#include <stdarg.h>
#include <stdio.h> /* vsnprintf */
@@ -65,8 +61,8 @@ enum { cstr_s_cap = sizeof(cstr_buf) - 2 };
#define cstr_l_drop(s) c_free((s)->lon.data)
#define cstr_is_long(s) ((s)->sml.size > 127)
-STC_API char* _cstr_init(cstr* self, intptr_t len, intptr_t cap);
-STC_API char* _cstr_internal_move(cstr* self, intptr_t pos1, intptr_t pos2);
+extern char* _cstr_init(cstr* self, intptr_t len, intptr_t cap);
+extern char* _cstr_internal_move(cstr* self, intptr_t pos1, intptr_t pos2);
/**************************** PUBLIC API **********************************/
@@ -74,19 +70,21 @@ STC_API char* _cstr_internal_move(cstr* self, intptr_t pos1, intptr_t pos2);
#define cstr_NULL (c_LITERAL(cstr){{{0}, 0}})
#define cstr_toraw(self) cstr_str(self)
-STC_API char* cstr_reserve(cstr* self, intptr_t cap);
-STC_API void cstr_shrink_to_fit(cstr* self);
-STC_API char* cstr_resize(cstr* self, intptr_t size, char value);
-STC_API intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* search);
-STC_API char* cstr_assign_n(cstr* self, const char* str, intptr_t len);
-STC_API char* cstr_append_n(cstr* self, const char* str, intptr_t len);
-STC_API bool cstr_getdelim(cstr *self, int delim, FILE *fp);
-STC_API void cstr_erase(cstr* self, intptr_t pos, intptr_t len);
-STC_API void cstr_u8_erase(cstr* self, intptr_t bytepos, intptr_t u8len);
-STC_API cstr cstr_from_fmt(const char* fmt, ...);
-STC_API intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...);
-STC_API intptr_t cstr_printf(cstr* self, const char* fmt, ...);
-STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, int32_t count);
+extern char* cstr_reserve(cstr* self, intptr_t cap);
+extern void cstr_shrink_to_fit(cstr* self);
+extern char* cstr_resize(cstr* self, intptr_t size, char value);
+extern intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* search);
+extern intptr_t cstr_find_sv(const cstr* self, csview search);
+extern char* cstr_assign_n(cstr* self, const char* str, intptr_t len);
+extern char* cstr_append_n(cstr* self, const char* str, intptr_t len);
+extern bool cstr_getdelim(cstr *self, int delim, FILE *fp);
+extern void cstr_erase(cstr* self, intptr_t pos, intptr_t len);
+extern void cstr_u8_erase(cstr* self, intptr_t bytepos, intptr_t u8len);
+extern cstr cstr_from_fmt(const char* fmt, ...);
+extern intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...);
+extern intptr_t cstr_printf(cstr* self, const char* fmt, ...);
+extern cstr cstr_replace_sv(csview sv, csview search, csview repl, int32_t count);
+extern uint64_t cstr_hash(const cstr *self);
STC_INLINE cstr_buf cstr_buffer(cstr* s) {
return cstr_is_long(s)
@@ -284,8 +282,6 @@ STC_INLINE intptr_t cstr_find(const cstr* self, const char* search) {
return res ? (res - str) : c_NPOS;
}
-STC_API intptr_t cstr_find_sv(const cstr* self, csview search);
-
STC_INLINE intptr_t cstr_find_s(const cstr* self, cstr search)
{ return cstr_find(self, cstr_str(&search)); }
@@ -404,13 +400,15 @@ STC_INLINE void cstr_insert_s(cstr* self, intptr_t pos, cstr s) {
cstr_replace_at_sv(self, pos, 0, sv);
}
-
STC_INLINE bool cstr_getline(cstr *self, FILE *fp)
{ return cstr_getdelim(self, '\n', fp); }
-STC_API uint64_t cstr_hash(const cstr *self);
+#endif // CSTR_H_INCLUDED
+
+/* -------------------------- EXTERN ------------------------- */
+#if defined(i_extern) && !defined(CSTR_X_INCLUDED)
+#define CSTR_X_INCLUDED
-#ifdef _i_extern
static struct {
int (*conv_asc)(int);
uint32_t (*conv_utf)(uint32_t);
@@ -439,23 +437,25 @@ cstr cstr_tocase(csview sv, int k) {
cstr_shrink_to_fit(&out);
return out;
}
-#endif
+#endif // i_extern
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#ifndef CSTR_C_INCLUDED
+#if defined i_extern || (defined i_implement && !defined _i_no_undef)
+#define CSTR_C_INCLUDED
-STC_DEF uint64_t cstr_hash(const cstr *self) {
+uint64_t cstr_hash(const cstr *self) {
csview sv = cstr_sv(self);
return cfasthash(sv.str, sv.size);
}
-STC_DEF intptr_t cstr_find_sv(const cstr* self, csview search) {
+intptr_t cstr_find_sv(const cstr* self, csview search) {
csview sv = cstr_sv(self);
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
return res ? (res - sv.str) : c_NPOS;
}
-STC_DEF char* _cstr_internal_move(cstr* self, const intptr_t pos1, const intptr_t pos2) {
+char* _cstr_internal_move(cstr* self, const intptr_t pos1, const intptr_t pos2) {
cstr_buf r = cstr_buffer(self);
if (pos1 != pos2) {
const intptr_t newlen = (r.size + pos2 - pos1);
@@ -467,7 +467,7 @@ STC_DEF char* _cstr_internal_move(cstr* self, const intptr_t pos1, const intptr_
return r.data;
}
-STC_DEF char* _cstr_init(cstr* self, const intptr_t len, const intptr_t cap) {
+char* _cstr_init(cstr* self, const intptr_t len, const intptr_t cap) {
if (cap > cstr_s_cap) {
self->lon.data = (char *)c_malloc(cap + 1);
cstr_l_set_size(self, len);
@@ -478,7 +478,7 @@ STC_DEF char* _cstr_init(cstr* self, const intptr_t len, const intptr_t cap) {
return self->sml.data;
}
-STC_DEF void cstr_shrink_to_fit(cstr* self) {
+void cstr_shrink_to_fit(cstr* self) {
cstr_buf r = cstr_buffer(self);
if (r.size == r.cap)
return;
@@ -492,7 +492,7 @@ STC_DEF void cstr_shrink_to_fit(cstr* self) {
}
}
-STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) {
+char* cstr_reserve(cstr* self, const intptr_t cap) {
if (cstr_is_long(self)) {
if (cap > cstr_l_cap(self)) {
self->lon.data = (char *)c_realloc(self->lon.data, cap + 1);
@@ -505,7 +505,7 @@ STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) {
char* data = (char *)c_malloc(cap + 1);
const intptr_t len = cstr_s_size(self);
/* copy full short buffer to emulate realloc() */
- c_memcpy(data, self->sml.data, cstr_s_cap + 2);
+ c_memcpy(data, self->sml.data, sizeof self->sml);
self->lon.data = data;
self->lon.size = (size_t)len;
cstr_l_set_cap(self, cap);
@@ -514,7 +514,7 @@ STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) {
return self->sml.data;
}
-STC_DEF char* cstr_resize(cstr* self, const intptr_t size, const char value) {
+char* cstr_resize(cstr* self, const intptr_t size, const char value) {
cstr_buf r = cstr_buffer(self);
if (size > r.size) {
if (size > r.cap && !(r.data = cstr_reserve(self, size)))
@@ -525,20 +525,20 @@ STC_DEF char* cstr_resize(cstr* self, const intptr_t size, const char value) {
return r.data;
}
-STC_DEF intptr_t cstr_find_at(const cstr* self, const intptr_t pos, const char* search) {
+intptr_t cstr_find_at(const cstr* self, const intptr_t pos, const char* search) {
csview sv = cstr_sv(self);
if (pos > sv.size) return c_NPOS;
const char* res = strstr((char*)sv.str + pos, search);
return res ? (res - sv.str) : c_NPOS;
}
-STC_DEF char* cstr_assign_n(cstr* self, const char* str, const intptr_t len) {
+char* cstr_assign_n(cstr* self, const char* str, const intptr_t len) {
char* d = cstr_reserve(self, len);
if (d) { c_memmove(d, str, len); _cstr_set_size(self, len); }
return d;
}
-STC_DEF char* cstr_append_n(cstr* self, const char* str, const intptr_t len) {
+char* cstr_append_n(cstr* self, const char* str, const intptr_t len) {
cstr_buf r = cstr_buffer(self);
if (r.size + len > r.cap) {
const size_t off = (size_t)(str - r.data);
@@ -551,7 +551,7 @@ STC_DEF char* cstr_append_n(cstr* self, const char* str, const intptr_t len) {
return r.data;
}
-STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
+bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
int c = fgetc(fp);
if (c == EOF)
return false;
@@ -571,7 +571,7 @@ STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
}
}
-STC_DEF cstr
+cstr
cstr_replace_sv(csview in, csview search, csview repl, int32_t count) {
cstr out = cstr_NULL;
intptr_t from = 0; char* res;
@@ -587,14 +587,14 @@ cstr_replace_sv(csview in, csview search, csview repl, int32_t count) {
return out;
}
-STC_DEF void cstr_erase(cstr* self, const intptr_t pos, intptr_t len) {
+void cstr_erase(cstr* self, const intptr_t pos, intptr_t len) {
cstr_buf r = cstr_buffer(self);
if (len > r.size - pos) len = r.size - pos;
c_memmove(&r.data[pos], &r.data[pos + len], r.size - (pos + len));
_cstr_set_size(self, r.size - len);
}
-STC_DEF void cstr_u8_erase(cstr* self, const intptr_t bytepos, const intptr_t u8len) {
+void cstr_u8_erase(cstr* self, const intptr_t bytepos, const intptr_t u8len) {
cstr_buf r = cstr_buffer(self);
intptr_t len = utf8_pos(r.data + bytepos, u8len);
c_memmove(&r.data[bytepos], &r.data[bytepos + len], r.size - (bytepos + len));
@@ -609,7 +609,7 @@ STC_DEF void cstr_u8_erase(cstr* self, const intptr_t bytepos, const intptr_t u8
# pragma warning(disable: 4996)
#endif
-STC_DEF intptr_t cstr_vfmt(cstr* self, intptr_t start, const char* fmt, va_list args) {
+intptr_t cstr_vfmt(cstr* self, intptr_t start, const char* fmt, va_list args) {
va_list args2;
va_copy(args2, args);
const int n = vsnprintf(NULL, 0ULL, fmt, args);
@@ -624,7 +624,7 @@ STC_DEF intptr_t cstr_vfmt(cstr* self, intptr_t start, const char* fmt, va_list
# pragma warning(pop)
#endif
-STC_DEF cstr cstr_from_fmt(const char* fmt, ...) {
+cstr cstr_from_fmt(const char* fmt, ...) {
cstr s = cstr_NULL;
va_list args;
va_start(args, fmt);
@@ -633,7 +633,7 @@ STC_DEF cstr cstr_from_fmt(const char* fmt, ...) {
return s;
}
-STC_DEF intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...) {
+intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
const intptr_t n = cstr_vfmt(self, cstr_size(self), fmt, args);
@@ -642,21 +642,21 @@ STC_DEF intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...) {
}
/* NB! self-data in args is UB */
-STC_DEF intptr_t cstr_printf(cstr* self, const char* fmt, ...) {
+intptr_t cstr_printf(cstr* self, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
const intptr_t n = cstr_vfmt(self, 0, fmt, args);
va_end(args);
return n;
}
-
#endif // i_implement
+#endif // CSTR_C_INCLUDED
+
#if defined __GNUC__ && !defined __clang__
# pragma GCC diagnostic pop
#endif
-#endif // CSTR_H_INCLUDED
#undef i_opt
#undef i_header
#undef i_static
#undef i_implement
-#undef _i_extern
+#undef i_extern
diff --git a/include/stc/csview.h b/include/stc/csview.h
index e8a3ad9b..d38d5f59 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -20,12 +20,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define _i_no_undef
+#include "utf8.h"
+
#ifndef CSVIEW_H_INCLUDED
#define CSVIEW_H_INCLUDED
-#include "ccommon.h"
-#include "utf8.h"
-
#define csview_NULL c_sv_1("")
#define csview_init() csview_NULL
#define csview_drop(p) c_default_drop(p)
@@ -33,12 +33,12 @@
#define csview_lit(literal) c_sv_1(literal)
#define csview_from_n(str, n) c_sv_2(str, n)
-STC_API csview_iter csview_advance(csview_iter it, intptr_t pos);
-STC_API intptr_t csview_find_sv(csview sv, csview search);
-STC_API uint64_t csview_hash(const csview *self);
-STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
-STC_API csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
-STC_API csview csview_token(csview sv, const char* sep, intptr_t* start);
+extern csview_iter csview_advance(csview_iter it, intptr_t pos);
+extern intptr_t csview_find_sv(csview sv, csview search);
+extern uint64_t csview_hash(const csview *self);
+extern csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
+extern csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
+extern csview csview_token(csview sv, const char* sep, intptr_t* start);
STC_INLINE csview csview_from(const char* str)
{ return c_LITERAL(csview){str, c_strlen(str)}; }
@@ -147,10 +147,14 @@ STC_INLINE int csview_icmp(const csview* x, const csview* y)
STC_INLINE bool csview_eq(const csview* x, const csview* y)
{ return x->size == y->size && !c_memcmp(x->str, y->str, x->size); }
+#endif // CSVIEW_H_INCLUDED
+
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#ifndef CSVIEW_C_INCLUDED
+#if defined i_extern || (defined i_implement && !defined _i_no_undef)
+#define CSVIEW_C_INCLUDED
-STC_DEF csview_iter csview_advance(csview_iter it, intptr_t pos) {
+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;
@@ -159,15 +163,15 @@ STC_DEF csview_iter csview_advance(csview_iter it, intptr_t pos) {
return it;
}
-STC_DEF intptr_t csview_find_sv(csview sv, csview search) {
+intptr_t csview_find_sv(csview sv, csview search) {
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
return res ? (res - sv.str) : c_NPOS;
}
-STC_DEF uint64_t csview_hash(const csview *self)
+uint64_t csview_hash(const csview *self)
{ return cfasthash(self->str, self->size); }
-STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
+csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
if (pos < 0) {
pos += sv.size;
if (pos < 0) pos = 0;
@@ -178,7 +182,7 @@ STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
return sv;
}
-STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
+csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
if (p1 < 0) {
p1 += sv.size;
if (p1 < 0) p1 = 0;
@@ -189,7 +193,7 @@ STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
return sv;
}
-STC_DEF csview csview_token(csview sv, const char* sep, intptr_t* start) {
+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);
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 512dbf67..747c654d 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -264,7 +264,7 @@ _cx_memb(_sort)(_cx_self* self) {
}
#endif // !c_no_cmp
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
+#if defined(i_implement) || defined(i_static)
STC_DEF _cx_self
_cx_memb(_init)(void) {
diff --git a/include/stc/forward.h b/include/stc/forward.h
index 9eafb857..484a8b63 100644
--- a/include/stc/forward.h
+++ b/include/stc/forward.h
@@ -24,6 +24,7 @@
#define STC_FORWARD_H_INCLUDED
#include <stdint.h>
+#include <stddef.h>
#define forward_carc(CX, VAL) _c_carc_types(CX, VAL)
#define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL)
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index a4cc3846..338f0db9 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -1,3 +1,4 @@
+
#ifndef UTF8_H_INCLUDED
#define UTF8_H_INCLUDED
@@ -5,7 +6,6 @@
#include "forward.h"
#include "ccommon.h"
-// utf8 methods defined in src/utf8code.c:
enum {
U8G_Cc, U8G_Lt, U8G_Nd, U8G_Nl,
U8G_Pc, U8G_Pd, U8G_Pf, U8G_Pi,
@@ -16,6 +16,7 @@ enum {
U8G_SIZE
};
+// utf8 methods defined in src/utf8code.c:
extern bool utf8_isgroup(int group, uint32_t c);
extern bool utf8_isalpha(uint32_t c);
extern uint32_t utf8_casefold(uint32_t c);
@@ -112,9 +113,16 @@ STC_INLINE const char* utf8_at(const char *s, intptr_t index) {
STC_INLINE intptr_t utf8_pos(const char* s, intptr_t index)
{ return (intptr_t)(utf8_at(s, index) - s); }
-
#endif // UTF8_H_INCLUDED
-#if defined(i_extern)
+
+#if defined i_extern || (defined i_implement && !defined _i_no_undef)
# include "../../src/utf8code.c"
-# undef i_extern
#endif
+#ifndef _i_no_undef
+#undef i_static
+#undef i_header
+#undef i_implement
+#undef i_extern
+#undef i_opt
+#endif
+#undef _i_no_undef