From 3a507cbc6abe0cfe80b49969ca1fa9c901533a78 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 9 Jan 2022 20:10:53 +0100 Subject: Removed strings.h. --- include/stc/cregex.h | 2 +- include/stc/csview.h | 39 +++++++++++++++++++++++++++++++++++++++ include/stc/strings.h | 47 ----------------------------------------------- include/stc/utf8.h | 4 ++-- 4 files changed, 42 insertions(+), 50 deletions(-) delete mode 100644 include/stc/strings.h (limited to 'include') diff --git a/include/stc/cregex.h b/include/stc/cregex.h index c00d8cf4..c261911e 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -84,7 +84,7 @@ STC_INLINE bool cregex_find_v(cregex re, const char *s, csview *sv) { STC_API cregex_match cregex_capture(cregex re, size_t index); /* get captured slice from capture group number index as a csview */ -STC_INLINE csview cregex_capture_v(cregex re, size_t index, const char* s) { +STC_INLINE csview cregex_capture_v(cregex re, const char* s, size_t index) { cregex_match cap = cregex_capture(re, index); return c_make(csview){s + cap.start, cap.end - cap.start}; } diff --git a/include/stc/csview.h b/include/stc/csview.h index 43dbb853..c8c80b4d 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -73,6 +73,45 @@ 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; } +/* csview interaction with cstr: */ +#ifdef CSTR_H_INCLUDED + +STC_INLINE csview csview_from_s(cstr s) + { return c_make(csview){s.str, _cstr_rep(&s)->size}; } + +STC_INLINE cstr cstr_from_v(csview sv) + { return cstr_from_n(sv.str, sv.size); } +STC_INLINE cstr cstr_from_replace_all_v(csview sv, csview find, csview repl) + { return cstr_from_replace_all(sv.str, sv.size, find.str, find.size, + repl.str, repl.size); } +STC_INLINE csview cstr_to_v(const cstr* self) + { return c_make(csview){self->str, _cstr_rep(self)->size}; } +STC_INLINE csview cstr_substr(cstr s, intptr_t pos, size_t n) + { return csview_substr(csview_from_s(s), pos, n); } +STC_INLINE csview cstr_slice(cstr s, intptr_t p1, intptr_t p2) + { return csview_slice(csview_from_s(s), p1, p2); } +STC_INLINE cstr* cstr_assign_v(cstr* self, csview sv) + { return cstr_assign_n(self, sv.str, sv.size); } +STC_INLINE cstr* cstr_append_v(cstr* self, csview sv) + { return cstr_append_n(self, sv.str, sv.size); } +STC_INLINE void cstr_insert_v(cstr* self, size_t pos, csview sv) + { cstr_replace_n(self, pos, 0, sv.str, sv.size); } +STC_INLINE void cstr_replace_v(cstr* self, size_t pos, size_t len, csview sv) + { cstr_replace_n(self, pos, len, sv.str, sv.size); } +STC_INLINE bool cstr_equals_v(cstr s, csview sv) + { return sv.size == cstr_size(s) && !memcmp(s.str, sv.str, sv.size); } +STC_INLINE size_t cstr_find_v(cstr s, csview needle) + { char* res = c_strnstrn(s.str, needle.str, cstr_size(s), needle.size); + return res ? res - s.str : cstr_npos; } +STC_INLINE bool cstr_contains_v(cstr s, csview needle) + { return c_strnstrn(s.str, needle.str, cstr_size(s), needle.size) != NULL; } +STC_INLINE bool cstr_starts_with_v(cstr s, csview sub) + { if (sub.size > cstr_size(s)) return false; + return !memcmp(s.str, sub.str, sub.size); } +STC_INLINE bool cstr_ends_with_v(cstr s, csview sub) + { if (sub.size > cstr_size(s)) return false; + return !memcmp(s.str + cstr_size(s) - sub.size, sub.str, sub.size); } +#endif /* ---- Container helper functions ---- */ STC_INLINE int csview_cmp(const csview* x, const csview* y) { diff --git a/include/stc/strings.h b/include/stc/strings.h deleted file mode 100644 index 20fbfe5d..00000000 --- a/include/stc/strings.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef STC_STRINGS_INCLUDED -#define STC_STRINGS_INCLUDED - -#include "cstr.h" -#include "csview.h" -#include - -/* cstr interaction with csview: */ - -STC_INLINE csview csview_from_s(cstr s) - { return c_make(csview){s.str, _cstr_rep(&s)->size}; } - -STC_INLINE cstr cstr_from_v(csview sv) - { return cstr_from_n(sv.str, sv.size); } -STC_INLINE cstr cstr_from_replace_all_v(csview sv, csview find, csview repl) - { return cstr_from_replace_all(sv.str, sv.size, find.str, find.size, - repl.str, repl.size); } -STC_INLINE csview cstr_to_v(const cstr* self) - { return c_make(csview){self->str, _cstr_rep(self)->size}; } -STC_INLINE csview cstr_substr(cstr s, intptr_t pos, size_t n) - { return csview_substr(csview_from_s(s), pos, n); } -STC_INLINE csview cstr_slice(cstr s, intptr_t p1, intptr_t p2) - { return csview_slice(csview_from_s(s), p1, p2); } -STC_INLINE cstr* cstr_assign_v(cstr* self, csview sv) - { return cstr_assign_n(self, sv.str, sv.size); } -STC_INLINE cstr* cstr_append_v(cstr* self, csview sv) - { return cstr_append_n(self, sv.str, sv.size); } -STC_INLINE void cstr_insert_v(cstr* self, size_t pos, csview sv) - { cstr_replace_n(self, pos, 0, sv.str, sv.size); } -STC_INLINE void cstr_replace_v(cstr* self, size_t pos, size_t len, csview sv) - { cstr_replace_n(self, pos, len, sv.str, sv.size); } -STC_INLINE bool cstr_equals_v(cstr s, csview sv) - { return sv.size == cstr_size(s) && !memcmp(s.str, sv.str, sv.size); } -STC_INLINE size_t cstr_find_v(cstr s, csview needle) - { char* res = c_strnstrn(s.str, needle.str, cstr_size(s), needle.size); - return res ? res - s.str : cstr_npos; } -STC_INLINE bool cstr_contains_v(cstr s, csview needle) - { return c_strnstrn(s.str, needle.str, cstr_size(s), needle.size) != NULL; } -STC_INLINE bool cstr_starts_with_v(cstr s, csview sub) - { if (sub.size > cstr_size(s)) return false; - return !memcmp(s.str, sub.str, sub.size); } -STC_INLINE bool cstr_ends_with_v(cstr s, csview sub) - { if (sub.size > cstr_size(s)) return false; - return !memcmp(s.str + cstr_size(s) - sub.size, sub.str, sub.size); } - -#endif -#undef i_opt diff --git a/include/stc/utf8.h b/include/stc/utf8.h index 2d578986..540ade39 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -1,5 +1,5 @@ -#ifndef STC_UTF8_INCLUDED -#define STC_UTF8_INCLUDED +#ifndef UTF8_H_INCLUDED +#define UTF8_H_INCLUDED #include "ccommon.h" #include -- cgit v1.2.3