From 20400977b40599fd1c6637dd659e72b900794d0f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 4 Dec 2022 20:52:36 +0100 Subject: Support for linking dependant UTF8 and cstr functions and/or cregex.c by defining i_extern before including and . I.e. #define i_extern #define i_implement // define cstr functions as shared symbols (static if not defined). #include // include cstr.h, utf8code.c, cregex.c, unless already included. --- src/cregex.c | 8 ++++---- src/utf8code.c | 35 ++++------------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/cregex.c b/src/cregex.c index 358e299d..1747ed3f 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -23,11 +23,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#include -#include -#define i_header +#ifndef CREGEX_C_INCLUDED +#define CREGEX_C_INCLUDED #include +#include // header only #include #include @@ -1260,3 +1259,4 @@ void cregex_drop(cregex* self) { c_free(self->prog); } +#endif \ No newline at end of file diff --git a/src/utf8code.c b/src/utf8code.c index b1534230..5dfb7d30 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -1,7 +1,7 @@ +#ifndef UTF8_C_INCLUDED +#define UTF8_C_INCLUDED #include -#define i_header -#include -#include +#include // header only #include "utf8tabs.inc" const uint8_t utf8_dtab[] = { @@ -143,31 +143,4 @@ bool utf8_isalpha(uint32_t c) { if (c < 128) return isalpha(c) != 0; return utf8_islower(c) || utf8_isupper(c); } - -static struct { - int (*conv_asc)(int); - uint32_t (*conv_utf)(uint32_t); -} -fn_tocase[] = {{tolower, utf8_casefold}, - {tolower, utf8_tolower}, - {toupper, utf8_toupper}}; - -cstr cstr_tocase(csview sv, int k) { - cstr out = cstr_null; - char *buf = cstr_reserve(&out, sv.size*3/2); - uint32_t cp; size_t sz = 0; - utf8_decode_t d = {.state=0}; - - while (*sv.str) { - do { utf8_decode(&d, (uint8_t)*sv.str++); } while (d.state); - if (d.codep < 128) - buf[sz++] = (char)fn_tocase[k].conv_asc((int)d.codep); - else { - cp = fn_tocase[k].conv_utf(d.codep); - sz += utf8_encode(buf + sz, cp); - } - } - _cstr_set_size(&out, sz); - cstr_shrink_to_fit(&out); - return out; -} +#endif -- cgit v1.2.3