update stuff
This commit is contained in:
parent
6d36aa4442
commit
95d74c2ef4
13 changed files with 1196 additions and 48 deletions
29
str.c
29
str.c
|
|
@ -12,6 +12,11 @@
|
|||
|
||||
// == STR_T ========================================================
|
||||
|
||||
strview_t strv__ignore(str_t s, size_t l) {
|
||||
COLLA_UNUSED(s); COLLA_UNUSED(l);
|
||||
return STRV_EMPTY;
|
||||
}
|
||||
|
||||
str_t str_init(arena_t *arena, const char *buf) {
|
||||
return str_init_len(arena, buf, buf ? strlen(buf) : 0);
|
||||
}
|
||||
|
|
@ -206,6 +211,18 @@ tstr_t strv_to_tstr(arena_t *arena, strview_t src) {
|
|||
#endif
|
||||
}
|
||||
|
||||
str_t strv_to_upper(arena_t *arena, strview_t src) {
|
||||
str_t out = str(arena, src);
|
||||
str_upper(&out);
|
||||
return out;
|
||||
}
|
||||
|
||||
str_t strv_to_lower(arena_t *arena, strview_t src) {
|
||||
str_t out = str(arena, src);
|
||||
str_lower(&out);
|
||||
return out;
|
||||
}
|
||||
|
||||
strview_t strv_remove_prefix(strview_t ctx, usize n) {
|
||||
if (n > ctx.len) n = ctx.len;
|
||||
return (strview_t){
|
||||
|
|
@ -285,7 +302,8 @@ bool strv_contains(strview_t ctx, char c) {
|
|||
|
||||
bool strv_contains_view(strview_t ctx, strview_t view) {
|
||||
if (ctx.len < view.len) return false;
|
||||
usize end = ctx.len - view.len;
|
||||
usize end = (ctx.len - view.len) + 1;
|
||||
|
||||
for (usize i = 0; i < end; ++i) {
|
||||
if (memcmp(ctx.buf + i, view.buf, view.len) == 0) {
|
||||
return true;
|
||||
|
|
@ -314,7 +332,10 @@ usize strv_find(strview_t ctx, char c, usize from) {
|
|||
}
|
||||
|
||||
usize strv_find_view(strview_t ctx, strview_t view, usize from) {
|
||||
usize end = ctx.len - view.len;
|
||||
if (view.len > ctx.len) return STR_NONE;
|
||||
|
||||
usize end = (ctx.len - view.len) + 1;
|
||||
|
||||
for (usize i = from; i < end; ++i) {
|
||||
if (memcmp(ctx.buf + i, view.buf, view.len) == 0) {
|
||||
return i;
|
||||
|
|
@ -374,6 +395,10 @@ bool char_is_num(char c) {
|
|||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
char char_lower(char c) {
|
||||
return c >= 'A' && c <= 'Z' ? c - 32 : c;
|
||||
}
|
||||
|
||||
// == INPUT STREAM =================================================
|
||||
|
||||
instream_t istr_init(strview_t str) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue