StrInitFromZstr
Description
Initialise a Str by value from a NUL-terminated Zstr. Length is derived from ZstrLen(zstr), so zstr is walked once to find the terminator before the copy is performed. The 1-arg form uses the enclosing MisraScope allocator; the 2-arg form takes an explicit allocator.
Success
Returns a usable Str holding the bytes of zstr up to (but not including) the terminator.
Failure
Returns an empty Str on allocator OOM. LOG_FATAL if zstr is NULL (via ZstrLen / underlying Cstr backend).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Init.c:85:
typedef Graph(Str) StrGraph;
StrGraph graph = GraphInitWithDeepCopy(str_init_copy, str_deinit, &alloc);
Str name = StrInitFromZstr("alpha", &alloc);
GraphNodeId node_id;
GraphNode node;- In
Foreach.c:89:
// hand its address through; the helpers + Map / Graph deep-copy
// callbacks own the resulting clones.
Str s_alpha = StrInitFromZstr("Alpha", &alloc);
Str s_beta = StrInitFromZstr("Beta", &alloc);
Str s_gamma = StrInitFromZstr("Gamma", &alloc);- In
Foreach.c:90:
// callbacks own the resulting clones.
Str s_alpha = StrInitFromZstr("Alpha", &alloc);
Str s_beta = StrInitFromZstr("Beta", &alloc);
Str s_gamma = StrInitFromZstr("Gamma", &alloc);
Str s_delta = StrInitFromZstr("Delta", &alloc);- In
Foreach.c:91:
Str s_alpha = StrInitFromZstr("Alpha", &alloc);
Str s_beta = StrInitFromZstr("Beta", &alloc);
Str s_gamma = StrInitFromZstr("Gamma", &alloc);
Str s_delta = StrInitFromZstr("Delta", &alloc);
Str s_echo = StrInitFromZstr("Echo", &alloc);- In
Foreach.c:92:
Str s_beta = StrInitFromZstr("Beta", &alloc);
Str s_gamma = StrInitFromZstr("Gamma", &alloc);
Str s_delta = StrInitFromZstr("Delta", &alloc);
Str s_echo = StrInitFromZstr("Echo", &alloc);
Str s_unknown = StrInitFromZstr("Unknown", &alloc);- In
Foreach.c:93:
Str s_gamma = StrInitFromZstr("Gamma", &alloc);
Str s_delta = StrInitFromZstr("Delta", &alloc);
Str s_echo = StrInitFromZstr("Echo", &alloc);
Str s_unknown = StrInitFromZstr("Unknown", &alloc);- In
Foreach.c:94:
Str s_delta = StrInitFromZstr("Delta", &alloc);
Str s_echo = StrInitFromZstr("Echo", &alloc);
Str s_unknown = StrInitFromZstr("Unknown", &alloc);
GraphNodeId alpha = city_add_intersection(&graph, &index, &s_alpha, &alloc);- In
Convert.c:419:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("not-a-number", &alloc.base);
Float value = FloatInit(&alloc.base);
bool ok = (FloatTryFromStr(&value, &text) == false);- In
Convert.c:434:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("3.14", &alloc.base);
Float value = FloatInit(&alloc.base);
bool ok = FloatTryFromStr(&value, &text);- In
Memory.c:451:
DefaultAllocator local = DefaultAllocatorInit();
Str s = StrInitFromZstr("hello", &local);
StrClear(&s);- In
Memory.c:469:
DefaultAllocator local = DefaultAllocatorInit();
Str s = StrInitFromZstr("x", &local);
StrClear(&s); bool test_blind_regex_match_str_validates(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str p = StrInitFromZstr("1", &alloc);
bitvec_regex_match_str(NULL, &p);
return false;
// "111" never appears in "101010" -> must be false.
Str pat_no = StrInitFromZstr("111", &alloc);
result = result && !BitVecRegexMatch(&source, &pat_no); // Sanity: a genuine substring still matches (guards against a trivially
// always-false implementation).
Str pat_yes = StrInitFromZstr("010", &alloc);
result = result && BitVecRegexMatch(&source, &pat_yes);- In
Convert.c:899:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("111000111", &alloc);
BitVec bv = bitvec_from_str_str(&s, ALLOCATOR_OF(&alloc));
bool result = (BitVecLen(&bv) == 9) && (BitVecCountOnes(&bv) == 6);- In
Convert.c:731:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("0b101", &alloc);
Int out = IntInit(&alloc.base);
bool ok = int_try_from_binary_str(&out, &text);- In
Convert.c:758:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("0B101", &alloc);
Int out = IntInit(&alloc.base);
bool ok = int_try_from_binary_str(&out, &text);- In
Convert.c:785:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("1101", &alloc);
Int out = IntInit(&alloc.base);
bool ok = int_try_from_binary_str(&out, &text);- In
Convert.c:819:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("0o17", &alloc);
Int out = IntInit(&alloc.base);
bool ok = int_try_from_oct_str_str(&out, &text);- In
Convert.c:845:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("0O17", &alloc);
Int out = IntInit(&alloc.base);
bool ok = int_try_from_oct_str_str(&out, &text);- In
Convert.c:870:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("17", &alloc);
Int out = IntInit(&alloc.base);
bool ok = int_try_from_oct_str_str(&out, &text);- In
Convert.c:1004:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("123", &alloc);
Int out = IntInit(&alloc.base);
bool parsed = IntTryFromStr(&out, &text);- In
Convert.c:1035:
DefaultAllocator alloc = DefaultAllocatorInit();
Str text = StrInitFromZstr("+5", &alloc);
Int out = IntInit(&alloc.base);
bool parsed = IntTryFromStr(&out, &text);- In
Convert.c:1059:
DefaultAllocator alloc = DefaultAllocatorInit();
Str digits = StrInitFromZstr("123", ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool ok = IntTryFromStrRadix(&value, &digits, 10);- In
Convert.c:1087:
DefaultAllocator alloc = DefaultAllocatorInit();
Str digits = StrInitFromZstr("+5", ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool ok = IntTryFromStrRadix(&value, &digits, 10);- In
Convert.c:1457:
DefaultAllocator alloc = DefaultAllocatorInit();
Str digits = StrInitFromZstr("12345", &alloc.base);
Int value = IntFromStr(&digits, &alloc.base);- In
Convert.c:1478:
DefaultAllocator alloc = DefaultAllocatorInit();
Str digits = StrInitFromZstr("ff", &alloc.base);
Int value = IntFromStrRadix(&digits, (u8)16u, &alloc.base);- In
Convert.c:1502:
DefaultAllocator alloc = DefaultAllocatorInit();
Str hex = StrInitFromZstr("ff", &alloc.base);
Int value = IntInit(&alloc.base);- In
Convert.c:1527:
DefaultAllocator alloc = DefaultAllocatorInit();
Str hex = StrInitFromZstr("12g3", &alloc.base);
Int value = IntInit(&alloc.base);- In
Write.c:95:
StrClear(&output);
Str s = StrInitFromZstr("World", &alloc);
StrAppendFmt(&output, "{}", s);
success = success && (ZstrCompare(StrBegin(&output), "World") == 0);- In
Write.c:390:
StrClear(&output);
Str s = StrInitFromZstr("MiXeD CaSe", &alloc);
StrAppendFmt(&output, "{c}", s);- In
Write.c:1188:
bool ok = true;
Str s = StrInitFromZstr("xyz", &alloc);
StrAppendFmt(&output, "AB");- In
Write.c:1213:
bool ok = true;
Str s = StrInitFromZstr("hi", &alloc);
StrAppendFmt(&output, "{<5}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "hi ") == 0);- In
Write.c:1315:
bool ok = true;
Str s = StrInitFromZstr("hello", &alloc);
StrAppendFmt(&output, "{.3}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "hel") == 0);- In
Write.c:1333:
bool ok = true;
Str s = StrInitFromZstr("hello", &alloc);
StrAppendFmt(&output, "{.0}", s);
ok = ok && (StrLen(&output) == 0);- In
Write.c:3750:
static bool test_m33_patch_fmt_malformed_returns_false(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str o = StrInitFromZstr("-----", &alloc);
// "AB{" pushes "AB" into the scratch then hits an unclosed spec ->
- In
Write.c:3768:
static bool test_m33_patch_fmt_empty_at_end(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str o = StrInitFromZstr("hello", &alloc);
bool r = StrPatchFmt(&o, StrLen(&o), ""); // offset == length, empty render
- In
Write.c:3784:
static bool test_m33_patch_fmt_exact_fit(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str o = StrInitFromZstr("-----", &alloc); // length 5
bool r = StrPatchFmt(&o, 0, "12345"); // renders exactly 5 chars
- In
Write.c:4142:
bool ok = true;
Str s = StrInitFromZstr("hello", &alloc);
StrAppendFmt(&out, "{}", s); // width defaults to 0 -> no padding
ok = ok && (ZstrCompare(StrBegin(&out), "hello") == 0);- In
Write.c:5109:
DefaultAllocator alloc = DefaultAllocatorInit();
Str out = StrInit(&alloc);
Str s = StrInitFromZstr("hi", &alloc);
StrAppendFmt(&out, "{}", s); // width 0 default
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);- In
Read.c:355:
StrReadFmt(z, "{}", s);
Str expected = StrInitFromZstr("Hello", &alloc);
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);- In
Read.c:363:
StrReadFmt(z, "{s}", s);
expected = StrInitFromZstr("Hello, World!", &alloc);
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);- In
Read.c:402:
success = success && (num == 42);
Str expected = StrInitFromZstr("Alice", &alloc);
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);- In
Read.c:413:
success = success && double_equals(val, 3.14);
expected = StrInitFromZstr("Bob", &alloc);
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);- In
Read.c:606:
z = "Hello";
StrReadFmt(z, "{c}", str_val);
Str expected = StrInitFromZstr("Hello", &alloc);
bool str_pass = (StrCmp(&str_val, &expected) == 0);
WriteFmt("str_val test: comparing with 'Hello', pass = {}\n", str_pass ? "true" : "false");- In
Read.c:616:
z = "\"World\"";
StrReadFmt(z, "{cs}", str_val);
expected = StrInitFromZstr("World", &alloc);
bool quoted_str_pass = (StrCmp(&str_val, &expected) == 0);
WriteFmt("quoted str_val test: comparing with 'World', pass = {}\n", quoted_str_pass ? "true" : "false");- In
Read.c:653:
// Should read "hello" (stops at first space)
Str expected = StrInitFromZstr("hello world", &alloc);
bool test1_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'hello', Pass: {}\n\n", test1_pass ? "true" : "false");- In
Read.c:678:
// Should read "hello" (stops at first space)
Str expected = StrInitFromZstr("hello", &alloc);
bool test1_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'hello', Pass: {}\n\n", test1_pass ? "true" : "false");- In
Read.c:703:
// Should read "HELLO" (stops at first space)
Str expected = StrInitFromZstr("HELLO WORLD", &alloc);
bool test2_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'HELLO', Pass: {}\n\n", test2_pass ? "true" : "false");- In
Read.c:772:
// Should read "mixed case" (converts the entire quoted string)
Str expected = StrInitFromZstr("mixed case", &alloc);
bool test3_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'mixed case', Pass: {}\n\n", test3_pass ? "true" : "false");- In
Read.c:797:
// Should read "ABC123XYZ" (only letters are converted, numbers unchanged)
Str expected = StrInitFromZstr("ABC123XYZ", &alloc);
bool test4_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'ABC123XYZ', Pass: {}\n\n", test4_pass ? "true" : "false");- In
Read.c:822:
// Should read "Hello" (stops at first space, no case conversion)
Str expected = StrInitFromZstr("Hello World", &alloc);
bool test5_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'Hello World', Pass: {}\n\n", test5_pass ? "true" : "false");- In
Read.c:1726:
StrReadFmt(z, "{}", s);
Str expected = StrInitFromZstr("ABC", &alloc);
bool ok = (StrLen(&s) == 3) && (StrCmp(&s, &expected) == 0);- In
Read.c:1747:
StrReadFmt(z, "{}", s);
Str expected = StrInitFromZstr("A", &alloc);
bool ok = (StrLen(&s) == 1) && (StrCmp(&s, &expected) == 0);- In
Read.c:1768:
StrReadFmt(z, "{A}", s);
Str expected = StrInitFromZstr("A", &alloc); // uppercased
bool ok = (StrLen(&s) == 1) && (StrCmp(&s, &expected) == 0);- In
Read.c:1792:
StrReadFmt(z, "{s}", s);
Str expected = StrInitFromZstr("ABC", &alloc);
bool ok = (StrLen(&s) == 3) && (StrCmp(&s, &expected) == 0);- In
Read.c:1812:
StrReadFmt(z, "{s}", s);
Str expected = StrInitFromZstr("A", &alloc);
bool ok = (StrLen(&s) == 1) && (StrCmp(&s, &expected) == 0);- In
Read.c:1832:
StrReadFmt(z, "{As}", s);
Str expected = StrInitFromZstr("A", &alloc); // uppercased
bool ok = (StrLen(&s) == 1) && (StrCmp(&s, &expected) == 0);- In
Ops.c:27:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("Hello", &alloc);
Str s3 = StrInitFromZstr("World", &alloc);- In
Ops.c:28:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("Hello", &alloc);
Str s3 = StrInitFromZstr("World", &alloc);
Str s4 = StrInitFromZstr("Hello World", &alloc);- In
Ops.c:29:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("Hello", &alloc);
Str s3 = StrInitFromZstr("World", &alloc);
Str s4 = StrInitFromZstr("Hello World", &alloc);- In
Ops.c:30:
Str s2 = StrInitFromZstr("Hello", &alloc);
Str s3 = StrInitFromZstr("World", &alloc);
Str s4 = StrInitFromZstr("Hello World", &alloc);
// Test StrCmp with equal strings
- In
Ops.c:65:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle1 = StrInitFromZstr("World", &alloc);
Str needle2 = StrInitFromZstr("Hello", &alloc);- In
Ops.c:66:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle1 = StrInitFromZstr("World", &alloc);
Str needle2 = StrInitFromZstr("Hello", &alloc);
Str needle3 = StrInitFromZstr("NotFound", &alloc);- In
Ops.c:67:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle1 = StrInitFromZstr("World", &alloc);
Str needle2 = StrInitFromZstr("Hello", &alloc);
Str needle3 = StrInitFromZstr("NotFound", &alloc);- In
Ops.c:68:
Str needle1 = StrInitFromZstr("World", &alloc);
Str needle2 = StrInitFromZstr("Hello", &alloc);
Str needle3 = StrInitFromZstr("NotFound", &alloc);
// Test StrFind (Str * key) with match at end
- In
Ops.c:104:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle = StrInitFromZstr("World", &alloc);- In
Ops.c:105:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle = StrInitFromZstr("World", &alloc);
bool result = StrContains(&haystack, &needle);- In
Ops.c:130:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);- In
Ops.c:131:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);- In
Ops.c:132:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);
// Test Str-form
- In
Ops.c:170:
// Test Zstr-form (string literals)
Str s1 = StrInitFromZstr("Hello World", &alloc);
StrReplace(&s1, "World", "Universe", 1);
bool result = (ZstrCompare(StrBegin(&s1), "Hello Universe") == 0);- In
Ops.c:176:
// Test multiple replacements
StrDeinit(&s1);
s1 = StrInitFromZstr("Hello Hello Hello", &alloc);
StrReplace(&s1, "Hello", "Hi", 2);
result = result && (ZstrCompare(StrBegin(&s1), "Hi Hi Hello") == 0);- In
Ops.c:182:
// Test Cstr-form (fixed-length views) - use the full "World" string instead of just "Wo"
StrDeinit(&s1);
s1 = StrInitFromZstr("Hello World", &alloc);
StrReplace(&s1, "World", 5, "Universe", 8, 1);
result = result && (ZstrCompare(StrBegin(&s1), "Hello Universe") == 0);- In
Ops.c:188:
// Test Str-form
StrDeinit(&s1);
s1 = StrInitFromZstr("Hello World", &alloc);
Str find = StrInitFromZstr("World", &alloc);
Str replace = StrInitFromZstr("Universe", &alloc);- In
Ops.c:189:
StrDeinit(&s1);
s1 = StrInitFromZstr("Hello World", &alloc);
Str find = StrInitFromZstr("World", &alloc);
Str replace = StrInitFromZstr("Universe", &alloc);
StrReplace(&s1, &find, &replace, 1);- In
Ops.c:190:
s1 = StrInitFromZstr("Hello World", &alloc);
Str find = StrInitFromZstr("World", &alloc);
Str replace = StrInitFromZstr("Universe", &alloc);
StrReplace(&s1, &find, &replace, 1);
result = result && (ZstrCompare(StrBegin(&s1), "Hello Universe") == 0);- In
Ops.c:208:
// Test StrSplit
Str s = StrInitFromZstr("Hello,World,Test", &alloc);
Strs split = StrSplit(&s, ",");- In
Ops.c:257:
// Test StrLStrip
Str s1 = StrInitFromZstr(" Hello ", &alloc);
Str stripped = StrLStrip(&s1, NULL);
bool result = (ZstrCompare(StrBegin(&stripped), "Hello ") == 0);- In
Ops.c:274:
// Test with custom strip characters
StrDeinit(&s1);
s1 = StrInitFromZstr("***Hello***", &alloc);
stripped = StrLStrip(&s1, "*");- In
Ops.c:297:
DefaultAllocator alloc = DefaultAllocatorInit();
Str hello_lc = StrInitFromZstr("hello", &alloc);
Str hello_uc = StrInitFromZstr("HELLO", &alloc);
Str hello_mc = StrInitFromZstr("HeLLo", &alloc);- In
Ops.c:298:
Str hello_lc = StrInitFromZstr("hello", &alloc);
Str hello_uc = StrInitFromZstr("HELLO", &alloc);
Str hello_mc = StrInitFromZstr("HeLLo", &alloc);
Str world = StrInitFromZstr("world", &alloc);- In
Ops.c:299:
Str hello_lc = StrInitFromZstr("hello", &alloc);
Str hello_uc = StrInitFromZstr("HELLO", &alloc);
Str hello_mc = StrInitFromZstr("HeLLo", &alloc);
Str world = StrInitFromZstr("world", &alloc);
Str hello_x = StrInitFromZstr("HelloX", &alloc); // longer
- In
Ops.c:300:
Str hello_uc = StrInitFromZstr("HELLO", &alloc);
Str hello_mc = StrInitFromZstr("HeLLo", &alloc);
Str world = StrInitFromZstr("world", &alloc);
Str hello_x = StrInitFromZstr("HelloX", &alloc); // longer
- In
Ops.c:301:
Str hello_mc = StrInitFromZstr("HeLLo", &alloc);
Str world = StrInitFromZstr("world", &alloc);
Str hello_x = StrInitFromZstr("HelloX", &alloc); // longer
// Equal under ASCII case folding.
- In
Ops.c:322:
// Non-ASCII bytes pass through verbatim (no Unicode folding).
Str non_ascii_a = StrInitFromZstr("ABC\xC0", &alloc);
Str non_ascii_b = StrInitFromZstr("abc\xC0", &alloc);
ok = ok && StrCmpIgnoreCase(&non_ascii_a, &non_ascii_b) == 0;- In
Ops.c:323:
// Non-ASCII bytes pass through verbatim (no Unicode folding).
Str non_ascii_a = StrInitFromZstr("ABC\xC0", &alloc);
Str non_ascii_b = StrInitFromZstr("abc\xC0", &alloc);
ok = ok && StrCmpIgnoreCase(&non_ascii_a, &non_ascii_b) == 0;- In
Ops.c:352:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello World", &alloc);
// A genuine suffix must report true...
Str suffix = StrInitFromZstr("World", &alloc);- In
Ops.c:354:
Str s = StrInitFromZstr("Hello World", &alloc);
// A genuine suffix must report true...
Str suffix = StrInitFromZstr("World", &alloc);
bool match = StrEndsWith(&s, &suffix); // Str* -> str_ends_with_str
// ...and a non-suffix must report false. The replace_scalar_call mutant
- In
Ops.c:359:
// forces the return to the constant 42 (true), so this false case is what
// actually pins the call's result.
Str nonsuffix = StrInitFromZstr("Hello", &alloc);
bool no_match = StrEndsWith(&s, &nonsuffix);- In
Ops.c:381:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("***", &alloc);
Str stripped = StrLStrip(&s, "*");
bool result = (StrLen(&stripped) == 0);- In
Ops.c:398:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("***", &alloc);
Str stripped = StrRStrip(&s, "*");
bool result = (StrLen(&stripped) == 0);- In
Ops.c:415:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("x", &alloc);
Str stripped = StrStrip(&s, "*");
bool result = (StrLen(&stripped) == 1) && (ZstrCompare(StrBegin(&stripped), "x") == 0);- In
Ops.c:432:
DefaultAllocator alloc = DefaultAllocatorInit();
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle = StrInitFromZstr("missing", &alloc);
bool result = (StrContains(&haystack, &needle) == false);- In
Ops.c:433:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle = StrInitFromZstr("missing", &alloc);
bool result = (StrContains(&haystack, &needle) == false);- In
Ops.c:450:
DefaultAllocator alloc = DefaultAllocatorInit();
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str present = StrInitFromZstr("World", &alloc);
Str absent = StrInitFromZstr("missing", &alloc);- In
Ops.c:451:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str present = StrInitFromZstr("World", &alloc);
Str absent = StrInitFromZstr("missing", &alloc);
bool result = (StrContains(&haystack, &present) == true) && (StrContains(&haystack, &absent) == false);- In
Ops.c:452:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str present = StrInitFromZstr("World", &alloc);
Str absent = StrInitFromZstr("missing", &alloc);
bool result = (StrContains(&haystack, &present) == true) && (StrContains(&haystack, &absent) == false);- In
Ops.c:469:
DefaultAllocator alloc = DefaultAllocatorInit();
Str haystack = StrInitFromZstr("Hello World", &alloc);
bool result = (StrContains(&haystack, "missing") == false);- In
Ops.c:485:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("a,b,", &alloc);
StrIters iters = StrSplitToIters(&s, ",");- In
Ops.c:512:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("ab", &alloc);
Strs split = StrSplit(&s, "abc");- In
Ops.c:535:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("ab", &alloc);
Strs split = StrSplit(&s, "abc");- In
Ops.c:556:
DefaultAllocator alloc = DefaultAllocatorInit();
Str hello = StrInitFromZstr("Hello", &alloc);
bool result = (StrCmp(&hello, "Hello") == 0);- In
Ops.c:576:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("abc", &alloc);
bool result = (StrIndexOf(&s, "abc", 3) == 0);- In
Ops.c:595:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello", &alloc);
bool result = (StrStartsWith(&s, "Hello") == true);- In
Ops.c:631:
StrBegin(&a)[3] = (char)0xFF;
Str b = StrInitFromZstr("abYY", &alloc); // length 4
// Call the mutated function directly: the public StrCmp wrapper
- In
Ops.c:657:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);- In
Ops.c:658:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
bool result = (StrStartsWith(&s, &prefix) == true);- In
Ops.c:680:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("World", &alloc);
bool result = (StrEndsWith(&s, "World") == true);- In
Ops.c:709:
static bool test_find_zstr_validates(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("hello", &alloc);
s.__magic = 0; // corrupt: validate_vec must LOG_FATAL.
(void)str_find_zstr(&s, "x");- In
Ops.c:721:
static bool test_starts_with_zstr_validates(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("hello", &alloc);
s.__magic = 0; // corrupt: validate_vec must LOG_FATAL.
(void)str_starts_with_zstr(&s, "he");- In
Ops.c:733:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("haystack", &alloc);
Str key = StrInitFromZstr("stack", &alloc);- In
Ops.c:734:
Str s = StrInitFromZstr("haystack", &alloc);
Str key = StrInitFromZstr("stack", &alloc);
// intentional bypass: corrupt s only.
- In
Ops.c:753:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("haystack", &alloc);
Str key = StrInitFromZstr("stack", &alloc);- In
Ops.c:754:
Str s = StrInitFromZstr("haystack", &alloc);
Str key = StrInitFromZstr("stack", &alloc);
// intentional bypass: corrupt key only.
- In
Ops.c:772:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello World", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);- In
Ops.c:773:
Str s = StrInitFromZstr("Hello World", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);
// intentional bypass: corrupt s only.
- In
Ops.c:791:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello", &alloc);
// intentional bypass: corrupt s only.
- In
Ops.c:809:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("haystack", &alloc);
Str key = StrInitFromZstr("stack", &alloc);- In
Ops.c:810:
Str s = StrInitFromZstr("haystack", &alloc);
Str key = StrInitFromZstr("stack", &alloc);
// intentional bypass: corrupt key only.
- In
Ops.c:838:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" x ", &alloc);
GENERIC_VEC(&s)->__magic ^= 0x1;
Str stripped = StrStrip(&s, NULL);- In
Ops.c:855:
DefaultAllocator alloc = DefaultAllocatorInit();
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str key = StrInitFromZstr("World", &alloc);
GENERIC_VEC(&key)->__magic ^= 0x1;- In
Ops.c:856:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str key = StrInitFromZstr("World", &alloc);
GENERIC_VEC(&key)->__magic ^= 0x1;
(void)StrContains(&haystack, &key);- In
Ops.c:873:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("a,b,c", &alloc);
GENERIC_VEC(&s)->__magic ^= 0x1;
StrIters iters = StrSplitToIters(&s, ",");- In
Ops.c:902:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("hello", &alloc);
GENERIC_VEC(&s)->__magic ^= 0x1;
(void)StrCmpIgnoreCase(&s, "HELLO");- In
Ops.c:930:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("a,b,c", &alloc);
Strs strs = StrSplit(&s, ",");
GENERIC_VEC(VecPtrAt(&strs, 0))->__magic ^= 0x1;- In
Ops.c:948:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("a,b", &alloc);
s.__magic = 0; // corrupt the magic so ValidateStr aborts
Strs split = StrSplit(&s, ",");- In
Ops.c:962:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello", &alloc);
s.__magic = 0;
int cmp = StrCmp(&s, "x");- In
Ops.c:976:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("abc", &alloc);
s.__magic = 0;
size idx = StrIndexOf(&s, "x", 1);- In
Ops.c:990:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello", &alloc);
s.__magic = 0;
int cmp = StrCmpIgnoreCase(&s, "x", 1);- In
Ops.c:1017:
DefaultAllocator alloc = DefaultAllocatorInit();
Str a = StrInitFromZstr("alpha", &alloc);
Str b = StrInitFromZstr("beta", &alloc);
a.__magic = 0; // corrupt: magic mismatch, data/length still valid
- In
Ops.c:1018:
Str a = StrInitFromZstr("alpha", &alloc);
Str b = StrInitFromZstr("beta", &alloc);
a.__magic = 0; // corrupt: magic mismatch, data/length still valid
- In
Ops.c:1034:
DefaultAllocator alloc = DefaultAllocatorInit();
Str a = StrInitFromZstr("alpha", &alloc);
Str b = StrInitFromZstr("beta", &alloc);
b.__magic = 0;- In
Ops.c:1035:
Str a = StrInitFromZstr("alpha", &alloc);
Str b = StrInitFromZstr("beta", &alloc);
b.__magic = 0;- In
Ops.c:1051:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("HELLO", &alloc);
Str other = StrInitFromZstr("hello", &alloc);
s.__magic = 0;- In
Ops.c:1052:
Str s = StrInitFromZstr("HELLO", &alloc);
Str other = StrInitFromZstr("hello", &alloc);
s.__magic = 0;- In
Ops.c:1068:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("HELLO", &alloc);
Str other = StrInitFromZstr("hello", &alloc);
other.__magic = 0;- In
Ops.c:1069:
Str s = StrInitFromZstr("HELLO", &alloc);
Str other = StrInitFromZstr("hello", &alloc);
other.__magic = 0;- In
Ops.c:1085:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
s.__magic = 0;- In
Ops.c:1086:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
s.__magic = 0;- In
Ops.c:1102:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("haystack", &alloc);
s.__magic = 0;- In
Memory.c:51:
Str s = StrInitFromZstr("Hello", &alloc);
// Swap 'H' and 'o'
- In
Memory.c:76:
Str s = StrInitFromZstr("Hello", &alloc);
// Initial length should be 5
- In
Memory.c:133:
Str s = StrInitFromZstr("Hello, World!", &alloc);
// Initial length should be 13
- In
Memory.c:158:
Str s = StrInitFromZstr("Hello", &alloc);
// Reverse the string
- In
Memory.c:168:
// Test with an even-length string
StrDeinit(&s);
s = StrInitFromZstr("abcd", &alloc);
// Reverse the string
- In
Memory.c:178:
// Test with a single-character string
StrDeinit(&s);
s = StrInitFromZstr("a", &alloc);
// Reverse the string
- In
Init.c:66:
// Test StrInitFromZstr function
bool test_str_init_from_zstr(void) {
WriteFmt("Testing StrInitFromZstr\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Init.c:71:
Zstr test_str = "Hello, World!";
Str s = StrInitFromZstr(test_str, &alloc);
// Validate the string
- In
Init.c:108:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("Hello, World!", &alloc);
Str dst = StrInitFromStr(&src, &alloc);- In
Init.c:130:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("Hello, World!", &alloc);
Str dst = StrDup(&src, &alloc);- In
Init.c:200:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("Hello, World!", &alloc);
Str dst = StrInit(&alloc);- In
Init.c:255:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello, World!", &alloc);
// Validate the string before deinit
- In
Init.c:284:
// Each piece is long enough to force its own heap buffer.
Str s = StrInitFromZstr("alphaaa,betaaaa,gammaaa,deltaaa", &dbg);
size before = DebugAllocatorLiveCount(&dbg);- In
Init.c:313:
Allocator *adbg = ALLOCATOR_OF(&dbg);
Str s = StrInitFromZstr("hello world", adbg);
StrDeinit(&s);- In
Init.c:331:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("source", &alloc);
src.__magic = 0;- In
Insert.c:33:
Str s = StrInitFromZstr("Hello", &alloc);
// Insert a character in the middle
- In
Insert.c:64:
Str s = StrInitFromZstr("Hello", &alloc);
// Insert a string in the middle: (cstr, cstr_len) adjacent, then idx
- In
Insert.c:83:
Str s = StrInitFromZstr("Hello", &alloc);
// Insert a string in the middle
- In
Insert.c:103:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at position 2
- In
Insert.c:122:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at position 2
- In
Insert.c:141:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at the back
- In
Insert.c:160:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at the back
- In
Insert.c:179:
Str s = StrInitFromZstr("World", &alloc);
// Push a string at the front
- In
Insert.c:198:
Str s = StrInitFromZstr("World", &alloc);
// Push a string at the front
- In
Insert.c:217:
Str s = StrInitFromZstr("Hello", &alloc);
// Push characters at the back
- In
Insert.c:241:
Str s = StrInitFromZstr("World", &alloc);
// Push characters at the front
- In
Insert.c:265:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);- In
Insert.c:266:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);
// Merge s2 into s1 (L-value semantics)
- In
Insert.c:293:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);- In
Insert.c:294:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);
// Merge s2 into s1 (R-value semantics)
- In
Insert.c:317:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);- In
Insert.c:318:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);
// Merge s2 into s1 (L-form; ownership of s2's storage transfers to s1)
- In
Insert.c:342:
Str s = StrInitFromZstr("Hello", &alloc);
// Append formatted suffix.
- In
Type.c:53:
// Add some strings
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("World", &alloc);- In
Type.c:54:
// Add some strings
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("World", &alloc);
VecPushBack(&sv, s1);- In
Remove.c:26:
Str s = StrInitFromZstr("Hello", &alloc);
// Pop a character from the back
- In
Remove.c:53:
Str s = StrInitFromZstr("Hello", &alloc);
// Pop a character from the front
- In
Remove.c:80:
Str s = StrInitFromZstr("Hello", &alloc);
// Remove a character from the middle
- In
Remove.c:107:
Str s = StrInitFromZstr("Hello World", &alloc);
// Create a buffer to store the removed characters
- In
Remove.c:137:
Str s = StrInitFromZstr("Hello", &alloc);
// Delete the last character
- In
Remove.c:162:
Str s = StrInitFromZstr("Hello", &alloc);
// Delete a character from the middle
- In
Remove.c:187:
Str s = StrInitFromZstr("Hello World", &alloc);
// Delete a range of characters
- In
Convert.c:245:
// Test decimal conversion
Str s = StrInitFromZstr("12345", &alloc);
u64 value = 0;
bool success = StrToU64(&s, &value, NULL);- In
Convert.c:252:
// Test hexadecimal conversion with explicit base
StrDeinit(&s);
s = StrInitFromZstr("ABCD", &alloc); // No 0x prefix when base is explicitly 16
StrParseConfig config = {.base = 16};
success = StrToU64(&s, &value, &config);- In
Convert.c:259:
// Test hexadecimal conversion (auto-detect base with 0)
StrDeinit(&s);
s = StrInitFromZstr("0xABCD", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 0xABCD);- In
Convert.c:265:
// Test binary conversion
StrDeinit(&s);
s = StrInitFromZstr("0b101010", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 42);- In
Convert.c:271:
// Test octal conversion
StrDeinit(&s);
s = StrInitFromZstr("0o52", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 42);- In
Convert.c:277:
// Test zero
StrDeinit(&s);
s = StrInitFromZstr("0", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 0);- In
Convert.c:283:
// Test invalid input
StrDeinit(&s);
s = StrInitFromZstr("not a number", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (!success);- In
Convert.c:289:
// Test negative number (should fail for unsigned)
StrDeinit(&s);
s = StrInitFromZstr("-123", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (!success);- In
Convert.c:305:
// Test positive decimal conversion
Str s = StrInitFromZstr("12345", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL);- In
Convert.c:312:
// Test negative decimal conversion
StrDeinit(&s);
s = StrInitFromZstr("-12345", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == -12345);- In
Convert.c:318:
// Test hexadecimal conversion
StrDeinit(&s);
s = StrInitFromZstr("0xABCD", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == 0xABCD);- In
Convert.c:324:
// Test binary conversion
StrDeinit(&s);
s = StrInitFromZstr("0b101010", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == 42);- In
Convert.c:330:
// Test zero
StrDeinit(&s);
s = StrInitFromZstr("0", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == 0);- In
Convert.c:336:
// Test invalid input
StrDeinit(&s);
s = StrInitFromZstr("not a number", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (!success);- In
Convert.c:352:
// Test integer conversion
Str s = StrInitFromZstr("123", &alloc);
f64 value = 0.0;
bool success = StrToF64(&s, &value, NULL);- In
Convert.c:359:
// Test fractional conversion
StrDeinit(&s);
s = StrInitFromZstr("123.456", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value - 123.456) < 0.0001);- In
Convert.c:365:
// Test negative number
StrDeinit(&s);
s = StrInitFromZstr("-123.456", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value - (-123.456)) < 0.0001);- In
Convert.c:371:
// Test scientific notation
StrDeinit(&s);
s = StrInitFromZstr("1.23e2", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value - 123.0) < 0.0001);- In
Convert.c:377:
// Test zero
StrDeinit(&s);
s = StrInitFromZstr("0", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value) < 0.0001);- In
Convert.c:383:
// Test infinity
StrDeinit(&s);
s = StrInitFromZstr("inf", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64IsInf(value) && value > 0);- In
Convert.c:389:
// Test negative infinity
StrDeinit(&s);
s = StrInitFromZstr("-inf", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64IsInf(value) && value < 0);- In
Convert.c:395:
// Test NaN
StrDeinit(&s);
s = StrInitFromZstr("nan", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64IsNan(value));- In
Convert.c:401:
// Test invalid input
StrDeinit(&s);
s = StrInitFromZstr("not a number", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (!success);- In
Convert.c:568:
for (size i = 0; i < sizeof(prefix_tests) / sizeof(prefix_tests[0]); i++) {
Str test_str = StrInitFromZstr(prefix_tests[i].input, &alloc);
u64 value = 0;
StrParseConfig config = {.base = prefix_tests[i].base};- In
Convert.c:781:
MemCopy(long_number, "12345678901234567890123456789012345678901234567890", 51);
Str long_str = StrInitFromZstr(long_number, &alloc);
u64 long_value = 0;
bool success = StrToU64(&long_str, &long_value, NULL);- In
Convert.c:845:
static bool test_leading_space_skip_condition(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" 1.5", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:858:
static bool test_leading_space_advances(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" 1.0", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:872:
static bool test_nan_exact_accept_with_offset(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" nan", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:885:
static bool test_inf_exact_accept_with_offset(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" inf", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:940:
static bool test_minus_sign_makes_negative(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("-5", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:953:
static bool test_plus_sign_advances(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("+5", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:966:
static bool test_integer_digits_set_flag(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:979:
static bool test_fractional_digits_set_flag(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(".5", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:993:
static bool test_exponent_gate_not_widened(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("5x", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL); // non-strict default
- In
Convert.c:1006:
static bool test_negative_exponent_sign(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("1e-2", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:1019:
static bool test_exponent_digits_set_flag(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("1e5", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Convert.c:1033:
static bool test_trailing_space_skip_condition(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("5 ", &alloc);
f64 value = 0.0;
StrParseConfig config = {.strict = true, .trim_space = true, .base = 0};- In
Convert.c:1048:
static bool test_trailing_space_advances(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("5 ", &alloc);
f64 value = 0.0;
StrParseConfig config = {.strict = true, .trim_space = true, .base = 0};- In
Convert.c:1063:
static bool test_strict_trailing_check_ge(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("5", &alloc);
f64 value = 0.0;
StrParseConfig config = {.strict = true, .trim_space = true, .base = 0};- In
Convert.c:1077:
static bool test_strict_trailing_check_le(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42", &alloc);
f64 value = 0.0;
StrParseConfig config = {.strict = true, .trim_space = true, .base = 0};- In
Convert.c:1098:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("5", &alloc);
u64 value = 0;
StrParseConfig config = {.base = 99};- In
Convert.c:1116:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("ff", &alloc);
u64 value = 0;
StrParseConfig config = {.base = 16};- In
Convert.c:1134:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" 42", &alloc);
u64 value = 0;
bool ok = StrToU64(&s, &value, NULL);- In
Convert.c:1151:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" 42", &alloc);
u64 value = 0;
bool ok = StrToU64(&s, &value, NULL);- In
Convert.c:1169:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("05", &alloc);
u64 value = 0;
bool ok = StrToU64(&s, &value, NULL);- In
Convert.c:1186:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0x", &alloc);
u64 value = 0;
bool ok = StrToU64(&s, &value, NULL);- In
Convert.c:1203:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("18446744073709551616", &alloc);
u64 value = 0;
bool ok = StrToU64(&s, &value, NULL);- In
Convert.c:1220:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42", &alloc);
u64 value = 0;
bool ok = StrToU64(&s, &value, NULL);- In
Convert.c:1237:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42 ", &alloc);
u64 value = 0;
StrParseConfig config = {.strict = true};- In
Convert.c:1255:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42 ", &alloc);
u64 value = 0;
StrParseConfig config = {.strict = true};- In
Convert.c:1273:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42x", &alloc);
u64 value = 0;
StrParseConfig config = {.strict = true};- In
Convert.c:1291:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("42", &alloc);
u64 value = 0;
StrParseConfig config = {.strict = true};- In
Convert.c:1561:
static bool test_skip_prefix_len_guard_hex(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0x1F", &alloc);
StrParseConfig cfg = {.base = 16};
u64 out = 0;- In
Convert.c:1576:
static bool test_skip_prefix_char_init_hex(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0x5", &alloc);
StrParseConfig cfg = {.base = 16};
u64 out = 0;- In
Convert.c:1591:
static bool test_skip_prefix_char_index_hex(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0x5", &alloc);
StrParseConfig cfg = {.base = 16};
u64 out = 0;- In
Convert.c:1604:
static bool test_skip_prefix_bin_lower(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0b1", &alloc);
StrParseConfig cfg = {.base = 2};
u64 out = 0;- In
Convert.c:1618:
static bool test_skip_prefix_bin_return(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0b1", &alloc);
StrParseConfig cfg = {.base = 2};
u64 out = 0;- In
Convert.c:1631:
static bool test_skip_prefix_oct_lower(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0o7", &alloc);
StrParseConfig cfg = {.base = 8};
u64 out = 0;- In
Convert.c:1644:
static bool test_skip_prefix_oct_upper(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0O7", &alloc);
StrParseConfig cfg = {.base = 8};
u64 out = 0;- In
Convert.c:1657:
static bool test_skip_prefix_oct_return(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0o7", &alloc);
StrParseConfig cfg = {.base = 8};
u64 out = 0;- In
Convert.c:1670:
static bool test_skip_prefix_hex_lower(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0x1F", &alloc);
StrParseConfig cfg = {.base = 16};
u64 out = 0;- In
Convert.c:1683:
static bool test_skip_prefix_hex_upper(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0X1F", &alloc);
StrParseConfig cfg = {.base = 16};
u64 out = 0;- In
Convert.c:1696:
static bool test_skip_prefix_hex_return(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0x1F", &alloc);
StrParseConfig cfg = {.base = 16};
u64 out = 0;- In
Convert.c:1715:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" -5", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL);- In
Convert.c:1732:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr(" 5", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL);- In
Convert.c:1748:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("-5", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL);- In
Convert.c:1764:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("+5", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL);- In
Convert.c:1787:
// 43 '0' characters: a valid parse (value 0) whose length exceeds the
// mutated constant capacity of 42.
Str s = StrInitFromZstr("0000000000000000000000000000000000000000000", &alloc);
i64 value = 7; // sentinel that must be overwritten to 0
- In
Convert.c:1805:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("-9223372036854775808", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL);- In
Convert.c:1822:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("2", &alloc);
u64 value = 999; // sentinel
StrParseConfig config = {.base = 2};- In
Convert.c:1841:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("123", &alloc);
// intentional bypass: plant an inconsistent (length, capacity) pair that
// ValidateStr must reject; mark dirty so the body re-runs.
- In
Convert.c:2079:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("0B101", &alloc);
StrParseConfig config = {.base = 2};
u64 value = 0;- In
Convert.c:2101:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("1e", &alloc);
f64 value = 0.0;
bool ok = StrToF64(&s, &value, NULL);- In
Foreach.c:39:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character with its index
- In
Foreach.c:62:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character in reverse with its index
- In
Foreach.c:87:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer with its index
- In
Foreach.c:119:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer in reverse with its index
- In
Foreach.c:151:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character
- In
Foreach.c:175:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character in reverse
- In
Foreach.c:209:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer
- In
Foreach.c:241:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer in reverse
- In
Foreach.c:283:
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of characters with indices
- In
Foreach.c:318:
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of characters
- In
Foreach.c:353:
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of character pointers with indices
- In
Foreach.c:385:
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of character pointers
- In
Foreach.c:417:
Str s = StrInitFromZstr("Hello World!", &alloc); // 12 characters
// Use StrForeachInRangeIdx which captures the 'end' parameter at the start
- In
Foreach.c:454:
Str s = StrInitFromZstr("Programming", &alloc); // 11 characters
// Use StrForeachInRangeIdx with a fixed range that will become invalid
- In
Foreach.c:491:
Str s = StrInitFromZstr("Beautiful Weather", &alloc); // 17 characters
// StrForeachReverseIdx (VecForeachReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
- In
Foreach.c:526:
Str s = StrInitFromZstr("Programming Test", &alloc); // 16 characters
// StrForeachPtrIdx (VecForeachPtrIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
- In
Foreach.c:561:
Str s = StrInitFromZstr("Excellent Example", &alloc); // 17 characters
// StrForeachReversePtrIdx (VecForeachPtrReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
- In
Foreach.c:595:
Str s = StrInitFromZstr("Comprehensive Testing Framework", &alloc); // 31 characters
// Use StrForeachPtrInRangeIdx with a fixed range that becomes invalid when we modify the string
- In
Foreach.c:630:
Str s = StrInitFromZstr("Testing Basic", &alloc); // 13 characters
// Basic StrForeachIdx (VecForeachIdx) now has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
- In
Access.c:50:
Str s = StrInitFromZstr("Hello", &alloc);
// Get the first character
- In
Access.c:69:
Str s = StrInitFromZstr("Hello", &alloc);
// Get the last character
- In
Access.c:88:
Str s = StrInitFromZstr("Hello", &alloc);
// Get a pointer to the first character using StrBegin
- In
Access.c:107:
Str s = StrInitFromZstr("Hello", &alloc);
// Get a pointer to one past the last character using StrEnd
- In
Access.c:127:
Str s = StrInitFromZstr("Hello", &alloc);
// Access characters at different indices
- In
Access.c:151:
Str s = StrInitFromZstr("Hello", &alloc);
// Access character pointers at different indices
- In
SysDns.c:1703:
resolver_init_crafted(&r, a);
Str name = StrInitFromZstr("multi", a);
DnsAddrs out = VecInitT(out, a);
bool got = dns_resolve_5_str(&r, &name, 7000, SOCKET_KIND_TCP, &out);- In
SysDns.c:1896:
resolver_init_crafted(&r, a);
Str spec = StrInitFromZstr("multi:8080", a);
DnsAddrs out = VecInitT(out, a);
bool got = dns_resolve_4_vec_str(&r, &spec, SOCKET_KIND_TCP, &out);- In
SysDns.c:1968:
resolver_init_crafted(&r, a);
Str spec = StrInitFromZstr("multi:80", a);
SocketAddr one;
bool got = dns_resolve_4_one_str(&r, &spec, SOCKET_KIND_TCP, &one);- In
Dns.c:471:
Allocator *a = ALLOCATOR_OF(&alloc);
Str name = StrInitFromZstr("example.com", a);
DnsWireBuf buf = VecInitT(buf, a);
bool ok = DnsBuildQuery(&buf, 0x1234, &name, DNS_TYPE_A);- In
Read.Simple.c:67:
bool success = true;
Str json = StrInitFromZstr("{\"name\": \"Alice\", \"city\": \"New York\"}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr("{\"count\": 42, \"score\": 95.5, \"year\": 2024}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr("{\"enabled\": true, \"visible\": false}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr(
"{\"id\": 1001, \"name\": \"Bob\", \"age\": 25, \"is_active\": true, \"salary\": 50000.0}",
&alloc
bool success = true;
Str json = StrInitFromZstr("{\"debug_mode\": false, \"timeout\": 30, \"log_level\": \"INFO\"}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr("{\"languages\": [\"C\", \"Python\", \"Rust\"]}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr(
"{\"user\": {\"name\": \"Charlie\", \"email\": \"charlie@example.com\"}, \"active\": true}",
&alloc
bool success = true;
Str json = StrInitFromZstr(
"{\"id\": 12345, \"name\": \"Laptop\", \"price\": 999.99, \"tags\": [\"electronics\", \"computers\", "
"\"portable\"]}", bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
// Create a copy of expected without spaces for comparison
Str expected_str = StrInitFromZstr(expected, alloc);
Str output_clean = StrInit(alloc);
Str expected_clean = StrInit(alloc);
// Note: These are the actual characters, not escape sequences
Str path = StrInitFromZstr("C:\\Program Files\\App", &alloc);
Str message = StrInitFromZstr("Hello, \"World\"!", &alloc);
Str data = StrInitFromZstr("line1\nline2\ttab", &alloc); // Note: These are the actual characters, not escape sequences
Str path = StrInitFromZstr("C:\\Program Files\\App", &alloc);
Str message = StrInitFromZstr("Hello, \"World\"!", &alloc);
Str data = StrInitFromZstr("line1\nline2\ttab", &alloc); Str path = StrInitFromZstr("C:\\Program Files\\App", &alloc);
Str message = StrInitFromZstr("Hello, \"World\"!", &alloc);
Str data = StrInitFromZstr("line1\nline2\ttab", &alloc);
JW_OBJ(json, {
// These contain actual special characters that should be escaped
Str quotes = StrInitFromZstr("\"quotes\"", &alloc);
Str backslash = StrInitFromZstr("\\", &alloc);
Str newline = StrInitFromZstr("\n", &alloc); // These contain actual special characters that should be escaped
Str quotes = StrInitFromZstr("\"quotes\"", &alloc);
Str backslash = StrInitFromZstr("\\", &alloc);
Str newline = StrInitFromZstr("\n", &alloc);
Str tab = StrInitFromZstr("\t", &alloc); Str quotes = StrInitFromZstr("\"quotes\"", &alloc);
Str backslash = StrInitFromZstr("\\", &alloc);
Str newline = StrInitFromZstr("\n", &alloc);
Str tab = StrInitFromZstr("\t", &alloc); Str backslash = StrInitFromZstr("\\", &alloc);
Str newline = StrInitFromZstr("\n", &alloc);
Str tab = StrInitFromZstr("\t", &alloc);
JW_OBJ(json, {
// Single string
Str single_str = StrInitFromZstr("hello", &alloc);
JW_OBJ(json2, { JW_STR_KV(json2, "text", single_str); }); // Helper function to compare JSON output (removes whitespace for comparison)
bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
Str expected_str = StrInitFromZstr(expected, alloc);
Str output_clean = StrInit(alloc);
Str expected_clean = StrInit(alloc); Str status;
} data = {
{123, {StrInitFromZstr("Alice", &alloc), 30}},
StrInitFromZstr("active", &alloc)
}; } data = {
{123, {StrInitFromZstr("Alice", &alloc), 30}},
StrInitFromZstr("active", &alloc)
}; } company;
} data = {
{{{StrInitFromZstr("John", &alloc), 25, 150000.0}}, StrInitFromZstr("TechCorp", &alloc)}
}; ApiResponse response = {
true,
StrInitFromZstr("Success", &alloc),
VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)
}; // Add sample data
AnnSymbol sym = {0};
sym.analysis_name = StrInitFromZstr("test_analysis", &alloc);
sym.function_name = StrInitFromZstr("main_func", &alloc);
sym.sha256 = StrInitFromZstr("abc123", &alloc); AnnSymbol sym = {0};
sym.analysis_name = StrInitFromZstr("test_analysis", &alloc);
sym.function_name = StrInitFromZstr("main_func", &alloc);
sym.sha256 = StrInitFromZstr("abc123", &alloc);
sym.function_mangled_name = StrInitFromZstr("_Z4main", &alloc); sym.analysis_name = StrInitFromZstr("test_analysis", &alloc);
sym.function_name = StrInitFromZstr("main_func", &alloc);
sym.sha256 = StrInitFromZstr("abc123", &alloc);
sym.function_mangled_name = StrInitFromZstr("_Z4main", &alloc);
sym.source_function_id = 12345; sym.function_name = StrInitFromZstr("main_func", &alloc);
sym.sha256 = StrInitFromZstr("abc123", &alloc);
sym.function_mangled_name = StrInitFromZstr("_Z4main", &alloc);
sym.source_function_id = 12345;
sym.target_function_id = 67890; Vec(FunctionInfo) functions = VecInitWithDeepCopy(NULL, FunctionInfoDeinit, &alloc);
FunctionInfo func1 = {12345, StrInitFromZstr("test_func", &alloc), 1024, 4096};
FunctionInfo func2 = {54321, StrInitFromZstr("helper_func", &alloc), 512, 8192};
VecPushBack(&functions, func1);
FunctionInfo func1 = {12345, StrInitFromZstr("test_func", &alloc), 1024, 4096};
FunctionInfo func2 = {54321, StrInitFromZstr("helper_func", &alloc), 512, 8192};
VecPushBack(&functions, func1);
VecPushBack(&functions, func2); SearchResult result = {0};
result.binary_id = 888;
result.binary_name = StrInitFromZstr("test_binary", &alloc);
result.analysis_id = 999;
result.sha256 = StrInitFromZstr("abc123", &alloc); result.binary_name = StrInitFromZstr("test_binary", &alloc);
result.analysis_id = 999;
result.sha256 = StrInitFromZstr("abc123", &alloc);
result.tags = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit, &alloc);
// Create strings and push them properly
Str tag1 = StrInitFromZstr("malware", &alloc);
Str tag2 = StrInitFromZstr("x86", &alloc); // Create strings and push them properly
Str tag1 = StrInitFromZstr("malware", &alloc);
Str tag2 = StrInitFromZstr("x86", &alloc);
VecPushBack(&result.tags, tag1); VecPushBack(&result.tags, tag2);
result.created_at = StrInitFromZstr("2024-04-01", &alloc);
result.model_id = 12345;
result.model_name = StrInitFromZstr("test_model", &alloc); result.created_at = StrInitFromZstr("2024-04-01", &alloc);
result.model_id = 12345;
result.model_name = StrInitFromZstr("test_model", &alloc);
result.owned_by = StrInitFromZstr("user1", &alloc); result.model_id = 12345;
result.model_name = StrInitFromZstr("test_model", &alloc);
result.owned_by = StrInitFromZstr("user1", &alloc);
JW_OBJ(json, {
AnnSymbol sym1 = {0};
sym1.analysis_name = StrInitFromZstr("analysis1", &alloc);
sym1.function_name = StrInitFromZstr("func1", &alloc);
sym1.sha256 = StrInitFromZstr("hash1", &alloc); AnnSymbol sym1 = {0};
sym1.analysis_name = StrInitFromZstr("analysis1", &alloc);
sym1.function_name = StrInitFromZstr("func1", &alloc);
sym1.sha256 = StrInitFromZstr("hash1", &alloc);
sym1.function_mangled_name = StrInitFromZstr("_Z5func1", &alloc); sym1.analysis_name = StrInitFromZstr("analysis1", &alloc);
sym1.function_name = StrInitFromZstr("func1", &alloc);
sym1.sha256 = StrInitFromZstr("hash1", &alloc);
sym1.function_mangled_name = StrInitFromZstr("_Z5func1", &alloc);
sym1.source_function_id = 111; sym1.function_name = StrInitFromZstr("func1", &alloc);
sym1.sha256 = StrInitFromZstr("hash1", &alloc);
sym1.function_mangled_name = StrInitFromZstr("_Z5func1", &alloc);
sym1.source_function_id = 111;
sym1.target_function_id = 222;
AnnSymbol sym2 = {0};
sym2.analysis_name = StrInitFromZstr("analysis2", &alloc);
sym2.function_name = StrInitFromZstr("func2", &alloc);
sym2.sha256 = StrInitFromZstr("hash2", &alloc); AnnSymbol sym2 = {0};
sym2.analysis_name = StrInitFromZstr("analysis2", &alloc);
sym2.function_name = StrInitFromZstr("func2", &alloc);
sym2.sha256 = StrInitFromZstr("hash2", &alloc);
sym2.function_mangled_name = StrInitFromZstr("_Z5func2", &alloc); sym2.analysis_name = StrInitFromZstr("analysis2", &alloc);
sym2.function_name = StrInitFromZstr("func2", &alloc);
sym2.sha256 = StrInitFromZstr("hash2", &alloc);
sym2.function_mangled_name = StrInitFromZstr("_Z5func2", &alloc);
sym2.source_function_id = 333; sym2.function_name = StrInitFromZstr("func2", &alloc);
sym2.sha256 = StrInitFromZstr("hash2", &alloc);
sym2.function_mangled_name = StrInitFromZstr("_Z5func2", &alloc);
sym2.source_function_id = 333;
sym2.target_function_id = 444;
// Create strings for the nested structure
Str deep_message = StrInitFromZstr("deep", &alloc);
Str test_name = StrInitFromZstr("test", &alloc); // Create strings for the nested structure
Str deep_message = StrInitFromZstr("deep", &alloc);
Str test_name = StrInitFromZstr("test", &alloc);
JW_OBJ(json, {
// Create strings and push them properly
Str str1 = StrInitFromZstr("a", &alloc);
Str str2 = StrInitFromZstr("b", &alloc);
Str str3 = StrInitFromZstr("c", &alloc); // Create strings and push them properly
Str str1 = StrInitFromZstr("a", &alloc);
Str str2 = StrInitFromZstr("b", &alloc);
Str str3 = StrInitFromZstr("c", &alloc); Str str1 = StrInitFromZstr("a", &alloc);
Str str2 = StrInitFromZstr("b", &alloc);
Str str3 = StrInitFromZstr("c", &alloc);
VecPushBack(&strings, str1); DefaultAllocator alloc = DefaultAllocatorInit();
Str json = StrInitFromZstr("{\"test\": \"value\"}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr("{\"id\": 12345, \"name\": \"test\", \"active\": true, \"score\": 98.5}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr(
"{\"user\": {\"id\": 123, \"profile\": {\"name\": \"Alice\", \"age\": 30}}, \"status\": \"active\"}",
&alloc
bool success = true;
Str json = StrInitFromZstr(
"{\"company\": {\"departments\": {\"engineering\": {\"head\": \"John\", \"count\": 25, \"budget\": 150000.0}}, "
"\"name\": \"TechCorp\"}}",
bool success = true;
Str json = StrInitFromZstr(
"{\"functions\": {\"12345\": {\"67890\": {\"distance\": 0.85, \"name\": \"main\"}}, \"54321\": {\"98765\": "
"{\"distance\": 0.92, \"name\": \"helper\"}}}}",
bool success = true;
Str json = StrInitFromZstr(
"{\"status\": true, \"message\": \"Success\", \"data\": {\"12345\": {\"67890\": {\"distance\": 0.85, "
"\"nearest_neighbor_analysis_id\": 999, \"nearest_neighbor_binary_id\": 888, "
bool success = true;
Str json = StrInitFromZstr("{\"id\": 12345, \"name\": \"test_func\", \"size\": 1024, \"vaddr\": 4096}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr("{\"id\": 54321, \"name\": \"test_model\"}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true;
Str json = StrInitFromZstr(
"{\"binary_id\": 888, \"binary_name\": \"test_binary\", \"analysis_id\": 999, \"sha256\": \"abc123\", "
"\"created_at\": \"2024-04-01\", \"model_id\": 12345, \"model_name\": \"test_model\", \"owned_by\": \"user1\"}",
bool success = true;
Str json = StrInitFromZstr(
"{\"status\": true, \"message\": \"Success\", \"data\": {\"12345\": {\"67890\": {\"distance\": 0.85, "
"\"nearest_neighbor_analysis_id\": 999, \"nearest_neighbor_binary_id\": 888, "
bool success = true;
Str json = StrInitFromZstr(
"{\"status\": true, \"message\": \"Success\", \"data\": {\"12345\": {\"67890\": {\"distance\": 0.85, "
"\"nearest_neighbor_analysis_id\": 999, \"nearest_neighbor_binary_id\": 888, " bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
// Create a copy of expected without spaces for comparison
Str expected_str = StrInitFromZstr(expected, alloc);
Str output_clean = StrInit(alloc);
Str expected_clean = StrInit(alloc); Str json = StrInit(&alloc);
Str name = StrInitFromZstr("Alice", &alloc);
Str city = StrInitFromZstr("New York", &alloc);
Str name = StrInitFromZstr("Alice", &alloc);
Str city = StrInitFromZstr("New York", &alloc);
JW_OBJ(json, { Str json = StrInit(&alloc);
Person person = {1001, StrInitFromZstr("Bob", &alloc), 25, true, 50000.0};
JW_OBJ(json, { Str json = StrInit(&alloc);
Config config = {false, 30, StrInitFromZstr("INFO", &alloc)};
JW_OBJ(json, {
// Create strings and push them properly
Str lang1 = StrInitFromZstr("C", &alloc);
Str lang2 = StrInitFromZstr("Python", &alloc);
Str lang3 = StrInitFromZstr("Rust", &alloc); // Create strings and push them properly
Str lang1 = StrInitFromZstr("C", &alloc);
Str lang2 = StrInitFromZstr("Python", &alloc);
Str lang3 = StrInitFromZstr("Rust", &alloc); Str lang1 = StrInitFromZstr("C", &alloc);
Str lang2 = StrInitFromZstr("Python", &alloc);
Str lang3 = StrInitFromZstr("Rust", &alloc);
VecPushBack(&languages, lang1); bool active;
} data = {
{StrInitFromZstr("Charlie", &alloc), StrInitFromZstr("charlie@example.com", &alloc)},
true
}; SimpleProduct product = {0};
product.id = 12345;
product.name = StrInitFromZstr("Laptop", &alloc);
product.price = 999.99;
product.tags = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit, &alloc);
// Create strings and push them properly
Str tag1 = StrInitFromZstr("electronics", &alloc);
Str tag2 = StrInitFromZstr("computers", &alloc);
Str tag3 = StrInitFromZstr("portable", &alloc); // Create strings and push them properly
Str tag1 = StrInitFromZstr("electronics", &alloc);
Str tag2 = StrInitFromZstr("computers", &alloc);
Str tag3 = StrInitFromZstr("portable", &alloc); Str tag1 = StrInitFromZstr("electronics", &alloc);
Str tag2 = StrInitFromZstr("computers", &alloc);
Str tag3 = StrInitFromZstr("portable", &alloc);
VecPushBack(&product.tags, tag1);
// Test completely empty object
Str json1 = StrInitFromZstr("{}", &alloc);
StrIter si1 = StrIterFromStr(json1);
// Test empty object with whitespace
Str json2 = StrInitFromZstr(" { } ", &alloc);
StrIter si2 = StrIterFromStr(json2);
// Test completely empty array
Str json1 = StrInitFromZstr("{\"items\":[]}", &alloc);
StrIter si1 = StrIterFromStr(json1);
// Test empty array with whitespace
Str json2 = StrInitFromZstr("{\"data\": [ ] }", &alloc);
StrIter si2 = StrIterFromStr(json2); bool success = true;
Str json = StrInitFromZstr("{\"name\":\"\",\"description\":\"\"}", &alloc);
StrIter si = StrIterFromStr(json); bool success = true;
Str json = StrInitFromZstr("{\"temp\":-25,\"balance\":-1000.50,\"delta\":-0.001}", &alloc);
StrIter si = StrIterFromStr(json); bool success = true;
Str json = StrInitFromZstr(
"{\"big_int\":9223372036854775807,\"big_float\":1.7976931348623157e+308,\"small_float\":2.2250738585072014e-"
"308}", bool success = true;
Str json = StrInitFromZstr("{\"int_zero\":0,\"float_zero\":0.0,\"bool_false\":false}", &alloc);
StrIter si = StrIterFromStr(json);
// Test with various special characters that might be problematic
Str json = StrInitFromZstr(
"{\"path\":\"C:\\\\Program Files\\\\App\",\"message\":\"Hello, "
"\\\"World\\\"!\",\"data\":\"line1\\nline2\\ttab\"}", // In a C source literal each backslash is doubled, so e.g. the JSON token
// `\n` is spelled "\\n" here.
Str json = StrInitFromZstr(
"{"
"\"quote\":\"\\\"\","
// Test with lots of different whitespace patterns
Str json = StrInitFromZstr(" {\n\t\"name\" : \"test\" ,\n \"value\": 42\t,\"flag\"\n:\ntrue\n}\t", &alloc);
StrIter si = StrIterFromStr(json); bool success = true;
Str json = StrInitFromZstr("{\"outer\":{},\"list\":[],\"deep\":{\"inner\":{}}}", &alloc);
StrIter si = StrIterFromStr(json);
Str json =
StrInitFromZstr("{\"empty_obj\":{},\"filled_obj\":{\"x\":1},\"empty_arr\":[],\"filled_arr\":[1,2]}", &alloc);
StrIter si = StrIterFromStr(json);
// Using smaller values that are safer to work with
Str json = StrInitFromZstr("{\"max_int\":2147483647,\"min_int\":-2147483648,\"one\":1,\"minus_one\":-1}", &alloc);
StrIter si = StrIterFromStr(json);
Str json =
StrInitFromZstr("{\"tiny\":0.000001,\"huge\":999999.999999,\"zero\":0.0,\"negative_tiny\":-0.000001}", &alloc);
StrIter si = StrIterFromStr(json); // JReadBool on a token that starts like a bool but isn't.
{
Str j = StrInitFromZstr("tru3", &alloc);
StrIter si = StrIterFromStr(j);
bool b = true; }
{
Str j = StrInitFromZstr("fXlse", &alloc);
StrIter si = StrIterFromStr(j);
bool b = true; // Input too short to spell a bool -- must fail (the >= length guard).
{
Str j = StrInitFromZstr("tr", &alloc);
StrIter si = StrIterFromStr(j);
bool b = true; // JReadNull on a 'n...' token that isn't "null".
{
Str j = StrInitFromZstr("nuXX", &alloc);
StrIter si = StrIterFromStr(j);
bool is_null = true;
{
Str j = StrInitFromZstr("true rest", &alloc);
StrIter si = StrIterFromStr(j);
bool b = false; }
{
Str j = StrInitFromZstr("false rest", &alloc);
StrIter si = StrIterFromStr(j);
bool b = true; }
{
Str j = StrInitFromZstr("null rest", &alloc);
StrIter si = StrIterFromStr(j);
bool is_null = false; // boundary case for the minimum-length guard.
{
Str j = StrInitFromZstr("true", &alloc);
StrIter si = StrIterFromStr(j);
bool b = false; }
{
Str j = StrInitFromZstr("false", &alloc);
StrIter si = StrIterFromStr(j);
bool b = true; }
{
Str j = StrInitFromZstr("null", &alloc);
StrIter si = StrIterFromStr(j);
bool is_null = false; Zstr cases[] = {"\"\\u\"", "\"\\u12\"", "\"ab\\u\""};
for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
Str j = StrInitFromZstr(cases[i], &alloc);
StrIter si = StrIterFromStr(j);
Str out = StrInit(&alloc); // reject -> iterator rewinds to start, output cleared.
{
Str j = StrInitFromZstr("\"a\\u00e9b\"", &alloc);
StrIter si = StrIterFromStr(j);
Str out = StrInit(&alloc); // is specific to \u, not a blanket failure.
{
Str j = StrInitFromZstr("\"plain\"", &alloc);
StrIter si = StrIterFromStr(j);
Str out = StrInit(&alloc); bool success = true;
Str json = StrInitFromZstr(
"{"
"\"u_str\":\"ignore\","
for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
Str json = StrInitFromZstr(cases[i], &alloc);
StrIter si = StrIterFromStr(json);
i64 a = 0;
{
Str j = StrInitFromZstr("-12345", &alloc);
StrIter si = StrIterFromStr(j);
i64 v = 0; {
// Positive control: a sign-flip mutation would make this negative.
Str j = StrInitFromZstr("12345", &alloc);
StrIter si = StrIterFromStr(j);
i64 v = 0; }
{
Str j = StrInitFromZstr("-2.5", &alloc);
StrIter si = StrIterFromStr(j);
f64 v = 0.0; bool success = true;
Str j = StrInitFromZstr("7", &alloc);
StrIter si = StrIterFromStr(j);
f64 val = 0.0; bool success = true;
Str j = StrInitFromZstr("13", &alloc);
StrIter si = StrIterFromStr(j);
f64 val = 0.0; // 'n' lead-in but not "null": ZstrCompareN fails -> *is_null stays the
// value the unconditional clear set it to, which must be false.
Str j = StrInitFromZstr("nuII", &alloc);
StrIter si = StrIterFromStr(j);
bool is_null = true; // poison: must be overwritten to false
bool success = true;
Str j = StrInitFromZstr("null", &alloc);
StrIter si = StrIterFromStr(j);
bool is_null = false;- In
RoundTrip.c:101:
bool enabled;
Str message;
} original = {42, 25.5, true, StrInitFromZstr("hello world", &alloc)};
// Write to JSON
- In
RoundTrip.c:306:
} original = {
StrInit(&alloc),
StrInitFromZstr("hello", &alloc),
StrInitFromZstr("hello world with spaces", &alloc),
StrInitFromZstr("special: !@#$%^&*()", &alloc)- In
RoundTrip.c:307:
StrInit(&alloc),
StrInitFromZstr("hello", &alloc),
StrInitFromZstr("hello world with spaces", &alloc),
StrInitFromZstr("special: !@#$%^&*()", &alloc)
};- In
RoundTrip.c:308:
StrInitFromZstr("hello", &alloc),
StrInitFromZstr("hello world with spaces", &alloc),
StrInitFromZstr("special: !@#$%^&*()", &alloc)
};- In
RoundTrip.c:379:
// Create strings and push them properly
Str str1 = StrInitFromZstr("first", &alloc);
Str str2 = StrInitFromZstr("second", &alloc);
Str str3 = StrInitFromZstr("", &alloc);- In
RoundTrip.c:380:
// Create strings and push them properly
Str str1 = StrInitFromZstr("first", &alloc);
Str str2 = StrInitFromZstr("second", &alloc);
Str str3 = StrInitFromZstr("", &alloc);
Str str4 = StrInitFromZstr("last", &alloc);- In
RoundTrip.c:381:
Str str1 = StrInitFromZstr("first", &alloc);
Str str2 = StrInitFromZstr("second", &alloc);
Str str3 = StrInitFromZstr("", &alloc);
Str str4 = StrInitFromZstr("last", &alloc);- In
RoundTrip.c:382:
Str str2 = StrInitFromZstr("second", &alloc);
Str str3 = StrInitFromZstr("", &alloc);
Str str4 = StrInitFromZstr("last", &alloc);
VecPushBack(&original_strings, str1);- In
RoundTrip.c:475:
// Original data
TestPerson original_person = {12345, StrInitFromZstr("John Doe", &alloc), 30, true, 75000.50};
// Write to JSON
- In
RoundTrip.c:530:
ComplexData original = {0};
original.user.id = 999;
original.user.name = StrInitFromZstr("Complex User", &alloc);
original.user.age = 25;
original.user.is_active = true;- In
RoundTrip.c:537:
original.config.debug_mode = false;
original.config.timeout = 30;
original.config.log_level = StrInitFromZstr("INFO", &alloc);
original.config.features = VecInitWithDeepCopyT(original.config.features, NULL, StrDeinit, &alloc);- In
RoundTrip.c:541:
// Create strings and push them properly
Str feature1 = StrInitFromZstr("auth", &alloc);
Str feature2 = StrInitFromZstr("logging", &alloc);- In
RoundTrip.c:542:
// Create strings and push them properly
Str feature1 = StrInitFromZstr("auth", &alloc);
Str feature2 = StrInitFromZstr("logging", &alloc);
VecPushBack(&original.config.features, feature1);- In
Parse.c:16:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str text = StrInitFromZstr(src, &alloc);
StrIter input = StrIterFromStr(text);
Str *got = NULL;- In
Parse.c:38:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("flag = yes\n", &alloc);
StrIter input = StrIterFromStr(src);
bool v = false;- In
Parse.c:64:
static bool test_kv_skipline_consumes_lf(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("xy\nZ", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigSkipLine(input);- In
Parse.c:86:
static bool test_kv_skipline_consumes_one_line_end(void) {
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("a\n\nZ", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigSkipLine(input);- In
Parse.c:107:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("a=1\r\nb=2\r\n", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);- In
Parse.c:170:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("k = # just a comment\n", &alloc);
StrIter input = StrIterFromStr(src);
Str *v = NULL;- In
Parse.c:198:
// skipped (fine) but the branch also mis-handles the bare-newline
// case. Pair with a trailing-comment line so both branches matter.
Str src = StrInitFromZstr("a = 1 # c\nb = 2\n", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);- In
Parse.c:223:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("k = \"v\" junk\n", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);- In
Parse.c:246:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(" k = v\n", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);- In
Parse.c:271:
KvConfig cfg = KvConfigInit(&alloc);
// A line with only spaces, then a real pair.
Str src = StrInitFromZstr(" \nk = v\n", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);- In
Parse.c:294:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("k = v\n \n", &alloc);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);- In
Parse.c:312:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"host = localhost\n"
"port = 8080\n"- In
Parse.c:341:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"# comment line\n"
"path = \"/srv/my app\" # keep spaces in quotes\n"- In
Parse.c:375:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("host = localhost\n", &alloc);
StrIter input = StrIterFromStr(src);
Str host_copy = StrInit(&alloc);- In
Parse.c:408:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"workers = 16\n"
"pi = 3.14159\n"- In
Parse.c:442:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"valid = yes\n"
"broken line\n"- In
Parse.c:469:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"t1 = true\n"
"t2 = YES\n"- In
Parse.c:512:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"name = misra\n"
"workers = 16\n"- In
Parse.c:524:
(void)KvConfigParse(input, &cfg);
Str k_name = StrInitFromZstr("name", &alloc);
Str k_missing = StrInitFromZstr("missing", &alloc);
Str k_workers = StrInitFromZstr("workers", &alloc);- In
Parse.c:525:
Str k_name = StrInitFromZstr("name", &alloc);
Str k_missing = StrInitFromZstr("missing", &alloc);
Str k_workers = StrInitFromZstr("workers", &alloc);
Str k_ratio = StrInitFromZstr("ratio", &alloc);- In
Parse.c:526:
Str k_name = StrInitFromZstr("name", &alloc);
Str k_missing = StrInitFromZstr("missing", &alloc);
Str k_workers = StrInitFromZstr("workers", &alloc);
Str k_ratio = StrInitFromZstr("ratio", &alloc);
Str k_enabled = StrInitFromZstr("enabled", &alloc);- In
Parse.c:527:
Str k_missing = StrInitFromZstr("missing", &alloc);
Str k_workers = StrInitFromZstr("workers", &alloc);
Str k_ratio = StrInitFromZstr("ratio", &alloc);
Str k_enabled = StrInitFromZstr("enabled", &alloc);- In
Parse.c:528:
Str k_workers = StrInitFromZstr("workers", &alloc);
Str k_ratio = StrInitFromZstr("ratio", &alloc);
Str k_enabled = StrInitFromZstr("enabled", &alloc);
// contains via Str*
- In
Parse.c:563:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"a = value one # trailing comment\n"
"b = value two\t\t; tab-spaced comment\n"- In
Parse.c:596:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"host = localhost\r\n"
"port = 8080\r\n"- In
Parse.c:643:
KvConfig cfg = KvConfigInit(base);
Str text = StrInitFromZstr(src, base);
StrIter input = StrIterFromStr(text);- In
Parse.c:705:
// NEW buffer and the old one to be released at L215. A long-ish value
// keeps both buffers off any small-string fast path.
Str text = StrInitFromZstr("key = spaced-out-value-here \n", adbg);
StrIter input = StrIterFromStr(text);- In
Parse.c:736:
KvConfig cfg = KvConfigInit(adbg);
Str text = StrInitFromZstr("a-reasonably-long-config-key = v\n", adbg);
StrIter input = StrIterFromStr(text);- In
Parse.c:766:
KvConfig cfg = KvConfigInit(adbg);
Str text = StrInitFromZstr("k = a-reasonably-long-config-value\n", adbg);
StrIter input = StrIterFromStr(text);- In
Parse.c:798:
KvConfig cfg = KvConfigInit(adbg);
Str text = StrInitFromZstr("present-config-key = value\n", adbg);
StrIter input = StrIterFromStr(text);
Last updated on