summaryrefslogtreecommitdiffhomepage
path: root/include/stc/csview.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-09 19:31:59 +0200
committerTyge Løvset <[email protected]>2023-06-09 19:31:59 +0200
commit72b0f0e7839b487a5df7c79ffe84511480cad251 (patch)
treee38e997c39bbaad183250c39971222e48bb2d59e /include/stc/csview.h
parentabd3b4372dee2291a81271f02588228279139960 (diff)
downloadSTC-modified-72b0f0e7839b487a5df7c79ffe84511480cad251.tar.gz
STC-modified-72b0f0e7839b487a5df7c79ffe84511480cad251.zip
Fixed issues with linking params i_implement, i_extern.
Diffstat (limited to 'include/stc/csview.h')
-rw-r--r--include/stc/csview.h36
1 files changed, 20 insertions, 16 deletions
diff --git a/include/stc/csview.h b/include/stc/csview.h
index e8a3ad9b..d38d5f59 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -20,12 +20,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define _i_no_undef
+#include "utf8.h"
+
#ifndef CSVIEW_H_INCLUDED
#define CSVIEW_H_INCLUDED
-#include "ccommon.h"
-#include "utf8.h"
-
#define csview_NULL c_sv_1("")
#define csview_init() csview_NULL
#define csview_drop(p) c_default_drop(p)
@@ -33,12 +33,12 @@
#define csview_lit(literal) c_sv_1(literal)
#define csview_from_n(str, n) c_sv_2(str, n)
-STC_API csview_iter csview_advance(csview_iter it, intptr_t pos);
-STC_API intptr_t csview_find_sv(csview sv, csview search);
-STC_API uint64_t csview_hash(const csview *self);
-STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
-STC_API csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
-STC_API csview csview_token(csview sv, const char* sep, intptr_t* start);
+extern csview_iter csview_advance(csview_iter it, intptr_t pos);
+extern intptr_t csview_find_sv(csview sv, csview search);
+extern uint64_t csview_hash(const csview *self);
+extern csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
+extern csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
+extern csview csview_token(csview sv, const char* sep, intptr_t* start);
STC_INLINE csview csview_from(const char* str)
{ return c_LITERAL(csview){str, c_strlen(str)}; }
@@ -147,10 +147,14 @@ STC_INLINE int csview_icmp(const csview* x, const csview* 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 ------------------------- */
-#if defined(i_implement)
+#ifndef CSVIEW_C_INCLUDED
+#if defined i_extern || (defined i_implement && !defined _i_no_undef)
+#define CSVIEW_C_INCLUDED
-STC_DEF csview_iter csview_advance(csview_iter it, intptr_t pos) {
+csview_iter csview_advance(csview_iter it, intptr_t pos) {
int inc = -1;
if (pos > 0) pos = -pos, inc = 1;
while (pos && it.ref != it.u8.end) pos += (*(it.ref += inc) & 0xC0) != 0x80;
@@ -159,15 +163,15 @@ STC_DEF csview_iter csview_advance(csview_iter it, intptr_t pos) {
return it;
}
-STC_DEF intptr_t csview_find_sv(csview sv, csview search) {
+intptr_t csview_find_sv(csview sv, csview search) {
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
return res ? (res - sv.str) : c_NPOS;
}
-STC_DEF uint64_t csview_hash(const csview *self)
+uint64_t csview_hash(const csview *self)
{ return cfasthash(self->str, self->size); }
-STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
+csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
if (pos < 0) {
pos += sv.size;
if (pos < 0) pos = 0;
@@ -178,7 +182,7 @@ STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n) {
return sv;
}
-STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
+csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
if (p1 < 0) {
p1 += sv.size;
if (p1 < 0) p1 = 0;
@@ -189,7 +193,7 @@ STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
return sv;
}
-STC_DEF csview csview_token(csview sv, const char* sep, intptr_t* start) {
+csview csview_token(csview sv, const char* sep, intptr_t* start) {
intptr_t sep_size = c_strlen(sep);
csview slice = {sv.str + *start, sv.size - *start};
const char* res = cstrnstrn(slice.str, sep, slice.size, sep_size);