28#define clod_sstr(ptr_v, size_v) ((clod_sstr){ .ptr = (char*)(ptr_v), .size = (size_v) })
30#define CLOD_SSTR_NULL ((clod_sstr){ .ptr = nullptr, .size = 0 })
32#define CLOD_SSTR_C(c_string) ((clod_sstr){ .ptr = (char*)(c_string), .size = strlen(c_string) })
44static inline bool clod_sstr_eq(
const clod_sstr str1,
const clod_sstr str2) {
45 if (str1.
size != str2.
size)
return false;
46 if (str1.
ptr == str2.
ptr)
return true;
47 if (str1.
ptr ==
nullptr || str2.
ptr ==
nullptr)
return false;
48 return memcmp(str1.
ptr, str2.
ptr, str1.
size) == 0;
58static inline void clod_sstr_cat(clod_sstr *str1,
const clod_sstr str2) {
59 if (str2.
size == 0)
return;
75 if (str.
size < elem.
size)
return CLOD_SSTR_NULL;
76 if (elem.
size == 0)
return clod_sstr(str.
ptr, 0);
78 for (
size_t i = 0; i < str.
size - elem.
size; i++)
79 if (memcmp(str.
ptr + i, elem.
ptr, elem.
size) == 0)
80 return clod_sstr(str.
ptr + i, elem.
size);
82 return CLOD_SSTR_NULL;
99static inline clod_sstr
clod_sstr_find(
const clod_sstr str,
const char elem, ptrdiff_t occurrence) {
100 if (occurrence > 0) {
101 for (
size_t i = 0; i < str.
size; i++) {
102 if (str.
ptr[i] == elem) occurrence--;
103 if (occurrence == 0)
return clod_sstr(str.
ptr + i, str.
size - i);
105 return CLOD_SSTR_NULL;
108 if (occurrence < 0) {
109 for (
size_t i = str.
size; i > 0; i--) {
110 if (str.
ptr[i - 1] == elem) occurrence++;
111 if (occurrence == 0)
return clod_sstr(str.
ptr + i - 1, str.
size - i + 1);
113 return CLOD_SSTR_NULL;
static clod_sstr clod_sstr_find(const clod_sstr str, const char elem, ptrdiff_t occurrence)
static clod_sstr clod_sstr_contains(const clod_sstr str, const clod_sstr elem)
static void clod_sstr_cat(clod_sstr *str1, const clod_sstr str2)
static bool clod_sstr_eq(const clod_sstr str1, const clod_sstr str2)