35 lines
971 B
C
35 lines
971 B
C
#pragma once
|
|
|
|
#include "../std.h"
|
|
|
|
typedef struct str {
|
|
char* data;
|
|
u32 len;
|
|
bool isZeroTerminated;
|
|
} str;
|
|
|
|
// creates str from a string literal
|
|
#define STR(LITERAL) str_construct(LITERAL, ARRAY_SIZE(LITERAL) - 1, true)
|
|
|
|
#define str_construct(DATA, LEN, ZERO_TERMINATED) ((str){ .data = DATA, .len = LEN, .isZeroTerminated = ZERO_TERMINATED })
|
|
|
|
static const str str_null = str_construct(NULL, 0, 0);
|
|
|
|
/// copies src content to new string and adds \0 at the end
|
|
str str_copy(str src);
|
|
|
|
/// compares two strings, NullPtr-friendly
|
|
bool str_equals(str str0, str str1);
|
|
|
|
/// allocates new string which is reversed variant of <s>
|
|
str str_reverse(str s);
|
|
|
|
i32 str_seek(str src, str fragment, u32 startIndex);
|
|
i32 str_seekReverse(str src, str fragment, u32 startIndex);
|
|
|
|
i32 str_seekChar(str src, char c, u32 startIndex);
|
|
i32 str_seekCharReverse(str src, char c, u32 startIndex);
|
|
|
|
bool str_startsWith(str src, str fragment);
|
|
bool str_endsWith(str src, str fragment);
|