diff options
author | Ren Kararou <[email protected]> | 2025-02-04 02:34:21 -0600 |
---|---|---|
committer | Ren Kararou <[email protected]> | 2025-02-04 02:34:21 -0600 |
commit | d30461672662822394a9e0bf32083cf2a9cd0558 (patch) | |
tree | c615427834b92c5ced52f8dd42827f05a07993ea | |
parent | b82890c8576824420f475b1cd4088af97e508601 (diff) | |
download | libspicy-d30461672662822394a9e0bf32083cf2a9cd0558.tar.gz libspicy-d30461672662822394a9e0bf32083cf2a9cd0558.tar.bz2 libspicy-d30461672662822394a9e0bf32083cf2a9cd0558.zip |
fix luna's interesting decisions HEAD dev/strings canon
-rw-r--r-- | inc/sstring.h | 12 | ||||
-rw-r--r-- | src/sstring.c | 22 |
2 files changed, 9 insertions, 25 deletions
diff --git a/inc/sstring.h b/inc/sstring.h index b11644a..7e15a52 100644 --- a/inc/sstring.h +++ b/inc/sstring.h @@ -12,26 +12,14 @@ typedef struct spicy_static_string // I'll put this in later maybe. // CBA to re-generate after git send-email somehow // lost all of this. - int sassign(sstring* restrict dst, const sstring* restrict src); - int cassign(sstring* restrict dst, const char* restrict src); - size_t sstrlen(const sstring* str); - int sassign(sstring* restrict dst, const sstring* restrict src); - int cassign(sstring* restrict dst, const char* restrict src); - int sUPPER(sstring* str); - int slower(sstring* str); - sstring spicycat(const size_t count, ...); - sstring sstringup(); - - - #endif diff --git a/src/sstring.c b/src/sstring.c index adcffec..f8af3d1 100644 --- a/src/sstring.c +++ b/src/sstring.c @@ -17,9 +17,9 @@ int sassign(sstring* restrict dst, const sstring* restrict src) // Assignment operator for C-Strings int cassign(sstring* restrict dst, const char* restrict src) { - if (!src || !dst) return -1; - dst->len = strlen(strncpy(dst->buf, src, 65536)); - return dst->len; + if (!src || !dst) return -1; + dst->len = strlen(strncpy(dst->buf, src, 65536)); + return dst->len; } // Sizeof operator @@ -29,7 +29,6 @@ size_t sstrlen(const sstring* str) return (str->len > 65536) ? 65536 : str->len; } - static int sshift(sstring* str, size_t mode) { if(!str) return -1; @@ -46,9 +45,9 @@ static int sshift(sstring* str, size_t mode) for(size_t i=0; i<str->len; i++) { if(str->buf[i] >= lowers[mode] && str->buf[i] >= uppers[mode]) - { - str->buf[i] += offsets[mode]; - } + { + str->buf[i] += offsets[mode]; + } } return 0; } @@ -63,18 +62,16 @@ int slower(sstring* str) return sshift(str,0); } - - sstring spicycat(const size_t count, ...) { // Yes, we will have to do a copy out of this stack frame. // Unless... (O3 Ren's Beloved??) sstring returnme = sstringup(); - + va_list kittens; va_start(kittens, count); for(size_t i=0; i<count; i++) - { + { size_t spaceleft = 65536-returnme.len; // Calc how much space we have // Grab the new argument @@ -82,7 +79,7 @@ sstring spicycat(const size_t count, ...) size_t kitlen = sstrlen(kitten); // This is JUST here to avoid f-calling twice. size_t copylen = (kitlen > spaceleft) ? spaceleft : kitlen; - + *(char*)(memcpy(returnme.buf+returnme.len, kitten->buf, copylen)+copylen) = 0; returnme.len += copylen; } @@ -90,7 +87,6 @@ sstring spicycat(const size_t count, ...) return returnme; } - sstring sstringup() { return (sstring) {0U,{0}}; |