From f3529a2600141dc7f84c734ea3bf5db8f7090e56 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 11 Jun 2023 07:36:31 +0200 Subject: More internal structuring --- include/stc/cstr.h | 3 +++ include/stc/csview.h | 39 +++++++++++++++++++++------------------ include/stc/utf8.h | 3 ++- src/libstc.c | 16 ++++------------ 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index f47889b4..0c5b67d8 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -655,8 +655,11 @@ intptr_t cstr_printf(cstr* self, const char* fmt, ...) { #if defined __GNUC__ && !defined __clang__ # pragma GCC diagnostic pop #endif +#ifndef _i_no_undef #undef i_opt #undef i_header #undef i_static #undef i_implement #undef i_import +#endif +#undef _i_no_undef diff --git a/include/stc/csview.h b/include/stc/csview.h index ee217e98..a1893063 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -114,6 +114,22 @@ STC_INLINE bool csview_valid_utf8(csview sv) // depends on src/utf8code.c #define c_fortoken(it, input, sep) \ c_fortoken_sv(it, csview_from(input), sep) +/* ---- Container helper functions ---- */ + +STC_INLINE int csview_cmp(const csview* x, const csview* y) { + 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); +} + +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 && !c_memcmp(x->str, y->str, x->size); } + +#endif // CSVIEW_H_INCLUDED + /* csview interaction with cstr: */ #ifdef CSTR_H_INCLUDED @@ -131,23 +147,7 @@ STC_INLINE csview cstr_slice_ex(const cstr* self, intptr_t p1, intptr_t p2) 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) { - 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); -} - -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 && !c_memcmp(x->str, y->str, x->size); } - -#endif // CSVIEW_H_INCLUDED /* -------------------------- IMPLEMENTATION ------------------------- */ #ifndef CSVIEW_C_INCLUDED @@ -203,8 +203,11 @@ csview csview_token(csview sv, const char* sep, intptr_t* start) { } #endif #endif -#undef i_opt +#ifndef _i_no_undef +#undef i_static #undef i_header #undef i_implement -#undef i_static #undef i_import +#undef i_opt +#endif +#undef _i_no_undef diff --git a/include/stc/utf8.h b/include/stc/utf8.h index e853263b..d6c759eb 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -1,10 +1,11 @@ +#include "ccommon.h" + #ifndef UTF8_H_INCLUDED #define UTF8_H_INCLUDED #include #include "forward.h" -#include "ccommon.h" enum { U8G_Cc, U8G_Lt, U8G_Nd, U8G_Nl, diff --git a/src/libstc.c b/src/libstc.c index afc19a08..7b49540a 100644 --- a/src/libstc.c +++ b/src/libstc.c @@ -1,16 +1,8 @@ -#include -#if 1 #define i_import -#include "../include/stc/utf8.h" -#define i_implement -#include "../include/stc/cstr.h" -#define i_implement -#include "../include/stc/cregex.h" -#define i_implement -#include "../include/stc/csview.h" -#else -#define i_import -#include "../include/stc/cregex.h" +#include "../include/stc/cregex.h" /* cstr. utf8, and cregex */ #define i_implement #include "../include/stc/csview.h" +#if __STDC_VERSION__ >= 201112L +# define i_implement +# include "../include/c11/fmt.h" #endif -- cgit v1.2.3