summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-05-20 16:37:21 +0200
committerTyge Løvset <[email protected]>2021-05-20 16:37:21 +0200
commit079aa69a085ddb478c15f20f6f0f4b0d790022b8 (patch)
tree87c15eefd3641f34993be4b914cca2a75f971d71
parent6270e01be0f105e3512cfde04a7f7d6b67aa8a2e (diff)
downloadSTC-modified-079aa69a085ddb478c15f20f6f0f4b0d790022b8.tar.gz
STC-modified-079aa69a085ddb478c15f20f6f0f4b0d790022b8.zip
Final API changes for csview: Added csview_trimmed*(), removed a few.
-rw-r--r--docs/csview_api.md10
-rw-r--r--stc/ccommon.h1
-rw-r--r--stc/csview.h11
3 files changed, 10 insertions, 12 deletions
diff --git a/docs/csview_api.md b/docs/csview_api.md
index ba5daed8..fed7f6f4 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -9,6 +9,9 @@ Its lifetime is limited by the source string storage. It keeps the length of the
when passing it around. It is faster when using`csview` as convertion type (raw) than `const char*` in associative
containers with cstr keys. E.g. prefer `using_cmap_svkey()` over `using_cmap_strkey()`.
+Note that a **csview** may not be null-terminated, and should therefore be printed the following way:
+`printf("%.*s", csview_ARG(sv))`.
+
See the c++ class [std::basic_string_view](https://en.cppreference.com/w/cpp/string/basic_string_view) for a functional
description.
@@ -24,21 +27,18 @@ All csview definitions and prototypes are available by including a single header
```c
csview c_lit(const char literal_only[]); // csview from literal, no strlen()
csview c_sv(cstr s); // construct csview from cstr
-
csview csview_from(const char* str); // construct from (const char*)
csview csview_from_n(const char* str, size_t n); // construct
csview csview_from_s(cstr s); // same as c_sv()
csview csview_lit(const char literal_only[]); // same as c_lit()
-csview csview_remove_prefix(csview sv, size_t n);
-csview csview_remove_suffix(csview sv, size_t n);
-csview csview_substr(csview sv, size_t pos, size_t n);
-
size_t csview_size(csview sv);
size_t csview_length(csview sv);
bool csview_empty(csview sv);
void csview_clear(csview* self);
+csview csview_trimmed(csview sv, size_t left, size_t right);
+csview csview_trimmed_s(cstr s, size_t left, size_t right);
bool csview_equals(csview sv, csview sv2);
size_t csview_find(csview sv, csview needle);
diff --git a/stc/ccommon.h b/stc/ccommon.h
index dc87471e..d29ce699 100644
--- a/stc/ccommon.h
+++ b/stc/ccommon.h
@@ -132,6 +132,7 @@
*b = (n)*sizeof *b > (BYTES) ? c_new_n(type, n) : _c_b \
; b; b != _c_b ? c_free(b) : (void)0, b = NULL)
#define c_breakwith continue
+#define c_breakdefer continue
#define c_var(CX, c, ...) \
CX c = CX##_init(); c_emplace(CX, c, __VA_ARGS__)
diff --git a/stc/csview.h b/stc/csview.h
index 19f89983..d4d3f65d 100644
--- a/stc/csview.h
+++ b/stc/csview.h
@@ -39,18 +39,15 @@ STC_INLINE csview csview_from(const char* str)
{ return c_make(csview){str, strlen(str)}; }
STC_INLINE csview csview_from_n(const char* str, size_t n)
{ return c_make(csview){str, n}; }
-
#define csview_lit(literal) \
c_make(csview){literal, sizeof c_make(strlit_t){literal} - 1}
STC_INLINE csview csview_from_s(cstr s)
{ return c_make(csview){s.str, _cstr_rep(&s)->size}; }
-STC_INLINE csview csview_remove_prefix(csview sv, size_t n)
- { sv.str += n, sv.size -= n; return sv; }
-STC_INLINE csview csview_remove_suffix(csview sv, size_t n)
- { sv.size -= n; return sv; }
-STC_INLINE csview csview_substr(csview sv, size_t pos, size_t n)
- { sv.str += pos, sv.size = n; return sv; }
+STC_INLINE csview csview_trimmed(csview sv, size_t left, size_t right)
+ { sv.str += left, sv.size -= left + right; return sv; }
+STC_INLINE csview csview_trimmed_s(cstr s, size_t left, size_t right)
+ { return c_make(csview){s.str + left, _cstr_rep(&s)->size - right - left}; }
STC_INLINE size_t csview_size(csview sv) { return sv.size; }
STC_INLINE size_t csview_length(csview sv) { return sv.size; }