summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-01-09 20:10:53 +0100
committerTyge Løvset <[email protected]>2022-01-09 20:10:53 +0100
commit3a507cbc6abe0cfe80b49969ca1fa9c901533a78 (patch)
tree012c56768fa5f1c7386ce716b6f50399e0a9d564
parent8a38affcb58be7eba502d32b78c84b376fe4fe45 (diff)
downloadSTC-modified-3a507cbc6abe0cfe80b49969ca1fa9c901533a78.tar.gz
STC-modified-3a507cbc6abe0cfe80b49969ca1fa9c901533a78.zip
Removed strings.h.
-rw-r--r--docs/csview_api.md5
-rw-r--r--examples/regex_match.c2
-rw-r--r--examples/splitstr.c7
-rw-r--r--examples/sview_split.c3
-rw-r--r--include/stc/cregex.h2
-rw-r--r--include/stc/csview.h39
-rw-r--r--include/stc/strings.h47
-rw-r--r--include/stc/utf8.h4
8 files changed, 50 insertions, 59 deletions
diff --git a/docs/csview_api.md b/docs/csview_api.md
index ac17fd9b..36d82436 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -20,9 +20,8 @@ description.
All csview definitions and prototypes are available by including a single header file.
```c
+#include <stc/cstr.h> // optional, include cstr+csview functionality
#include <stc/csview.h>
-// or, to use cstr+csview functionality:
-#include <stc/strings.h>
```
## Methods
@@ -146,7 +145,7 @@ void print_split(csview str, csview sep)
#define i_val_str
#include <stc/cvec.h>
-#include <stc/strings.h>
+#include <stc/csview.h>
cvec_str string_split(csview str, csview sep)
{
diff --git a/examples/regex_match.c b/examples/regex_match.c
index 5e9775b4..887f4ddf 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -25,7 +25,7 @@ int main()
csview sv = {s, 0};
while (cregex_find_next_v(re, s, &sv)) {
- printf(c_PRIsv " | ", c_ARGsv(sv));
+ printf(c_PRIsv " ; ", c_ARGsv(sv));
}
puts("");
}
diff --git a/examples/splitstr.c b/examples/splitstr.c
index db46eaed..695e7595 100644
--- a/examples/splitstr.c
+++ b/examples/splitstr.c
@@ -1,4 +1,6 @@
-#include <stc/strings.h>
+#define i_val_str
+#include <stc/cvec.h>
+#include <stc/csview.h>
void print_split(csview str, csview sep)
{
@@ -10,9 +12,6 @@ void print_split(csview str, csview sep)
}
}
-#define i_val_str
-#include <stc/cvec.h>
-
cvec_str string_split(csview str, csview sep)
{
cvec_str vec = cvec_str_init();
diff --git a/examples/sview_split.c b/examples/sview_split.c
index 22d94f23..1c29240b 100644
--- a/examples/sview_split.c
+++ b/examples/sview_split.c
@@ -1,4 +1,5 @@
-#include <stc/strings.h>
+#include <stc/cstr.h>
+#include <stc/csview.h>
int main()
{
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 <ctype.h>
-
-/* 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 <ctype.h>