ValidateStr
Description
Validate whether a given Str object is valid. Not foolproof but will work most of the time. Aborts if provided Str is not valid.
Parameters
| Name | Direction | Description |
|---|---|---|
s |
in | Pointer to Str object to validate. |
Success
Continue execution, meaning given Str object is most probably valid.
Failure
abort
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Sys.c:242:
// `o`'s allocator is NULL), not here.
Str *StrError(i32 eno, Str *err_str) {
ValidateStr(err_str);
Allocator *alloc = StrAllocator(err_str);
Str out = StrInit(alloc);- In
Io.c:1622:
}
ValidateStr(o);
ValidateStr(s);- In
Io.c:1623:
ValidateStr(o);
ValidateStr(s);
// Remember the pre-render length so the post-write padding step
- In
Io.c:1710:
}
ValidateStr(o);
// Snapshot the pre-render length so post-render padding sees the
- In
Io.c:2114:
}
ValidateStr(o);
ValidateFloat(value);- In
Io.c:2239:
LOG_FATAL("Invalid arguments");
ValidateStr(s);
bool force_case = fmt_info && (fmt_info->flags & FMT_FLAG_FORCE_CASE) != 0;- In
Io.c:2910:
}
ValidateStr(o);
ValidateBitVec(bv);- In
Io.c:2984:
}
ValidateStr(o);
ValidateInt(value);- In
Str.c:135:
Allocator *clone_allocator = NULL;
ValidateStr(src);
if (!dst) {
LOG_FATAL("Invalid arguments");- In
Str.c:155:
void StrDeinit(Str *copy) {
ValidateStr(copy);
deinit_vec(GENERIC_VEC(copy), sizeof(char));
}- In
Str.c:173:
(void)ignored_size;
ValidateStr(str);
for (idx = 0; idx < StrLen(str); idx++) {- In
Str.c:189:
i32 cmp = 0;
ValidateStr(a);
ValidateStr(b);- In
Str.c:190:
ValidateStr(a);
ValidateStr(b);
min = StrLen(a) < StrLen(b) ? StrLen(a) : StrLen(b);- In
Str.c:208:
i32 str_cmp_str(const Str *s, const Str *other) {
ValidateStr(s);
ValidateStr(other);
return str_compare(s, other);- In
Str.c:209:
i32 str_cmp_str(const Str *s, const Str *other) {
ValidateStr(s);
ValidateStr(other);
return str_compare(s, other);
}- In
Str.c:214:
i32 str_cmp_zstr(const Str *s, Zstr other) {
ValidateStr(s);
return ZstrCompare(StrBegin(s), other);
}- In
Str.c:219:
i32 str_cmp_cstr(const Str *s, Zstr other, size other_len) {
ValidateStr(s);
return ZstrCompareN(StrBegin(s), other, other_len);
}- In
Str.c:224:
i32 str_cmp_str_ignore_case(const Str *s, const Str *other) {
ValidateStr(s);
ValidateStr(other);
return ZstrCompareIgnoreCase(StrBegin(s), StrBegin(other));- In
Str.c:225:
i32 str_cmp_str_ignore_case(const Str *s, const Str *other) {
ValidateStr(s);
ValidateStr(other);
return ZstrCompareIgnoreCase(StrBegin(s), StrBegin(other));
}- In
Str.c:230:
i32 str_cmp_zstr_ignore_case(const Str *s, Zstr other) {
ValidateStr(s);
return ZstrCompareIgnoreCase(StrBegin(s), other);
}- In
Str.c:235:
i32 str_cmp_cstr_ignore_case(const Str *s, Zstr other, size other_len) {
ValidateStr(s);
return ZstrCompareNIgnoreCase(StrBegin(s), other, other_len);
}- In
Str.c:240:
Zstr str_find_cstr(const Str *s, Zstr key, size key_len) {
ValidateStr(s);
return ZstrFindSubstringN(StrBegin(s), key, key_len);
}- In
Str.c:245:
Zstr str_find_zstr(const Str *s, Zstr key) {
ValidateStr(s);
return ZstrFindSubstring(StrBegin(s), key);
}- In
Str.c:250:
Zstr str_find_str(const Str *s, const Str *key) {
ValidateStr(s);
ValidateStr(key);
return ZstrFindSubstringN(StrBegin(s), StrBegin(key), StrLen(key));- In
Str.c:251:
Zstr str_find_str(const Str *s, const Str *key) {
ValidateStr(s);
ValidateStr(key);
return ZstrFindSubstringN(StrBegin(s), StrBegin(key), StrLen(key));
}- In
Str.c:256:
static StrIters str_split_to_iters_impl(Str *s, Zstr key, size keylen) {
ValidateStr(s);
StrIters sv = (StrIters)VecInit(s->allocator);- In
Str.c:290:
static Strs str_split_impl(Str *s, Zstr key, size keylen) {
ValidateStr(s);
Strs sv = (Strs)VecInit(s->allocator);- In
Str.c:331:
Zstr found = NULL;
ValidateStr(s);
if (!key) {- In
Str.c:362:
}
ValidateStr(key);
if (key->length == 0) {- In
Str.c:384:
}
ValidateStr(key);
if (key->length == 0) {- In
Str.c:407:
// = 1 means from right
Str strip_str(Str *s, Zstr chars_to_strip, int split_direction) {
ValidateStr(s);
// Empty Str: `s->data` may be NULL or unallocated; forming
- In
Str.c:445:
bool str_starts_with_zstr(const Str *s, Zstr prefix) {
ValidateStr(s);
return starts_with(s->data, s->length, prefix, ZstrLen(prefix));
}- In
Str.c:450:
bool str_ends_with_zstr(const Str *s, Zstr suffix) {
ValidateStr(s);
return ends_with(s->data, s->length, suffix, ZstrLen(suffix));
}- In
Str.c:455:
bool str_starts_with_cstr(const Str *s, Zstr prefix, size prefix_len) {
ValidateStr(s);
return starts_with(s->data, s->length, prefix, prefix_len);
}- In
Str.c:460:
bool str_ends_with_cstr(const Str *s, Zstr suffix, size suffix_len) {
ValidateStr(s);
return ends_with(s->data, s->length, suffix, suffix_len);
}- In
Str.c:465:
bool str_starts_with_str(const Str *s, const Str *prefix) {
ValidateStr(s);
return starts_with(s->data, s->length, prefix->data, prefix->length);
}- In
Str.c:470:
bool str_ends_with_str(const Str *s, const Str *suffix) {
ValidateStr(s);
return ends_with(s->data, s->length, suffix->data, suffix->length);
}- In
Str.c:475:
void str_replace_cstr(Str *s, Zstr match, size match_len, Zstr replacement, size replacement_len, size count) {
ValidateStr(s);
size i = 0;
size replaced = 0;- In
Str.c:492:
void str_replace_zstr(Str *s, Zstr match, Zstr replacement, size count) {
ValidateStr(s);
str_replace_cstr(s, match, ZstrLen(match), replacement, ZstrLen(replacement), count);
}- In
Str.c:497:
void str_replace_str(Str *s, const Str *match, const Str *replacement, size count) {
ValidateStr(s);
str_replace_cstr(s, match->data, match->length, replacement->data, replacement->length, count);
}- In
Str.c:558:
Str *StrFromU64(Str *str, u64 value, const StrIntFormat *config) {
ValidateStr(str);
if (!config) {- In
Str.c:623:
Str *StrFromI64(Str *str, i64 value, const StrIntFormat *config) {
ValidateStr(str);
if (!config) {- In
Str.c:661:
Str *StrFromF64(Str *str, f64 value, const StrFloatFormat *config) {
ValidateStr(str);
if (!config) {- In
Str.c:863:
bool StrToU64(const Str *str, u64 *value, const StrParseConfig *config) {
ValidateStr(str);
if (!value) {- In
Str.c:950:
bool StrToI64(const Str *str, i64 *value, const StrParseConfig *config) {
ValidateStr(str);
if (!value) {- In
Str.c:1010:
bool StrToF64(const Str *str, f64 *value, const StrParseConfig *config) {
ValidateStr(str);
if (!value) {- In
Str.c:1148:
}
void ValidateStr(const Str *s) {
return ValidateVec(s);
}- In
Str.c:1155:
ValidateVec(vs);
VecForeachPtr(vs, sp) {
ValidateStr(sp);
}
}- In
Proc.c:639:
Str *GetCurrentExecutablePath(Str *exe_path) {
ValidateStr(exe_path);
Allocator *alloc = StrAllocator(exe_path);- In
KvConfig.c:26:
}
ValidateStr(value);
if (StrCmpIgnoreCase(value, "true") == 0 || StrCmpIgnoreCase(value, "yes") == 0 ||- In
Str.Type.c:78:
// Test ValidateStr macro
bool test_validate_str(void) {
WriteFmt("Testing ValidateStr macro\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Type.c:86:
// This should not crash
ValidateStr(&s);
// Note: We can't really test invalid strings here as ValidateStr
- In
Str.Type.c:123:
// Deadend test: Test ValidateStr with invalid string (should crash/abort)
bool test_validate_invalid_str(void) {
WriteFmt("Testing ValidateStr with invalid string (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Type.c:143:
// This should abort the program
ValidateStr(&s);
// Should never reach here
- In
Str.Init.c:31:
// Validate the string
ValidateStr(&s);
// Check that it's initialized correctly
- In
Str.Init.c:53:
// Validate the string
ValidateStr(&s);
// Check that it's initialized correctly
- In
Str.Init.c:73:
// Validate the string
ValidateStr(&s);
// Check that it's initialized correctly
- In
Str.Init.c:92:
Str s = StrZ(test_str, &alloc);
ValidateStr(&s);
bool result = (StrLen(&s) == ZstrLen(test_str) && ZstrCompare(StrBegin(&s), test_str) == 0);- In
Str.Init.c:111:
// Validate both strings
ValidateStr(&src);
ValidateStr(&dst);- In
Str.Init.c:112:
// Validate both strings
ValidateStr(&src);
ValidateStr(&dst);
// Check that dst is initialized correctly
- In
Str.Init.c:133:
// Validate both strings
ValidateStr(&src);
ValidateStr(&dst);- In
Str.Init.c:134:
// Validate both strings
ValidateStr(&src);
ValidateStr(&dst);
// Check that dst is initialized correctly
- In
Str.Init.c:155:
// Validate the string
ValidateStr(&s);
// Check that it's initialized correctly
- In
Str.Init.c:176:
StrInitStack(stack_str, 20) {
StrPushBackMany(&stack_str, "Hello, Stack!");
ValidateStr(&stack_str);
if (ZstrCompare(StrBegin(&stack_str), "Hello, Stack!") != 0) {- In
Str.Init.c:206:
// Validate both strings
ValidateStr(&src);
ValidateStr(&dst);- In
Str.Init.c:207:
// Validate both strings
ValidateStr(&src);
ValidateStr(&dst);
// Check that the copy was successful
- In
Str.Init.c:230:
bool copied = StrInitCopy(&dst, &src);
ValidateStr(&src);
ValidateStr(&dup);
ValidateStr(&dst);- In
Str.Init.c:231:
ValidateStr(&src);
ValidateStr(&dup);
ValidateStr(&dst);- In
Str.Init.c:232:
ValidateStr(&src);
ValidateStr(&dup);
ValidateStr(&dst);
bool dup_allocator_matches = (StrAllocator(&dup) == StrAllocator(&src));- In
Str.Init.c:257:
// Validate the string before deinit
ValidateStr(&s);
// Deinit the string
Last updated on