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)
// 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\"}", bool success = true;
Str json = StrInitFromZstr(
"{\"escaped\":\"\\\"quotes\\\"\",\"backslash\":\"\\\\\",\"newline\":\"\\n\",\"tab\":\"\\t\"}",
&alloc
// 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); // 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); 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); 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); }); 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, "- 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\"]}",- In
RoundTrip.c:102:
bool enabled;
Str message;
} original = {42, 25.5, true, StrInitFromZstr("hello world", &alloc)};
// Write to JSON
- In
RoundTrip.c:307:
} original = {
StrInit(&alloc),
StrInitFromZstr("hello", &alloc),
StrInitFromZstr("hello world with spaces", &alloc),
StrInitFromZstr("special: !@#$%^&*()", &alloc)- In
RoundTrip.c:308:
StrInit(&alloc),
StrInitFromZstr("hello", &alloc),
StrInitFromZstr("hello world with spaces", &alloc),
StrInitFromZstr("special: !@#$%^&*()", &alloc)
};- In
RoundTrip.c:309:
StrInitFromZstr("hello", &alloc),
StrInitFromZstr("hello world with spaces", &alloc),
StrInitFromZstr("special: !@#$%^&*()", &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);- In
RoundTrip.c:381:
// 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:382:
Str str1 = StrInitFromZstr("first", &alloc);
Str str2 = StrInitFromZstr("second", &alloc);
Str str3 = StrInitFromZstr("", &alloc);
Str str4 = StrInitFromZstr("last", &alloc);- In
RoundTrip.c:383:
Str str2 = StrInitFromZstr("second", &alloc);
Str str3 = StrInitFromZstr("", &alloc);
Str str4 = StrInitFromZstr("last", &alloc);
VecPushBack(&original_strings, str1);- In
RoundTrip.c:476:
// Original data
TestPerson original_person = {12345, StrInitFromZstr("John Doe", &alloc), 30, true, 75000.50};
// Write to JSON
- In
RoundTrip.c:531:
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:538:
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:542:
// Create strings and push them properly
Str feature1 = StrInitFromZstr("auth", &alloc);
Str feature2 = StrInitFromZstr("logging", &alloc);- In
RoundTrip.c:543:
// Create strings and push them properly
Str feature1 = StrInitFromZstr("auth", &alloc);
Str feature2 = StrInitFromZstr("logging", &alloc);
VecPushBack(&original.config.features, feature1);- In
Parse.c:10:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"host = localhost\n"
"port = 8080\n"- In
Parse.c:39:
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:73:
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:106:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"workers = 16\n"
"pi = 3.14159\n"- In
Parse.c:140:
DefaultAllocator alloc = DefaultAllocatorInit();
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr(
"valid = yes\n"
"broken line\n"- In
Str.Remove.c:26:
Str s = StrInitFromZstr("Hello", &alloc);
// Pop a character from the back
- In
Str.Remove.c:53:
Str s = StrInitFromZstr("Hello", &alloc);
// Pop a character from the front
- In
Str.Remove.c:80:
Str s = StrInitFromZstr("Hello", &alloc);
// Remove a character from the middle
- In
Str.Remove.c:107:
Str s = StrInitFromZstr("Hello World", &alloc);
// Create a buffer to store the removed characters
- In
Str.Remove.c:137:
Str s = StrInitFromZstr("Hello", &alloc);
// Delete the last character
- In
Str.Remove.c:162:
Str s = StrInitFromZstr("Hello", &alloc);
// Delete a character from the middle
- In
Str.Remove.c:187:
Str s = StrInitFromZstr("Hello World", &alloc);
// Delete a range of characters
- In
Str.Memory.c:51:
Str s = StrInitFromZstr("Hello", &alloc);
// Swap 'H' and 'o'
- In
Str.Memory.c:76:
Str s = StrInitFromZstr("Hello", &alloc);
// Initial length should be 5
- In
Str.Memory.c:133:
Str s = StrInitFromZstr("Hello, World!", &alloc);
// Initial length should be 13
- In
Str.Memory.c:158:
Str s = StrInitFromZstr("Hello", &alloc);
// Reverse the string
- In
Str.Memory.c:168:
// Test with an even-length string
StrDeinit(&s);
s = StrInitFromZstr("abcd", &alloc);
// Reverse the string
- In
Str.Memory.c:178:
// Test with a single-character string
StrDeinit(&s);
s = StrInitFromZstr("a", &alloc);
// Reverse the string
- In
Str.Ops.c:27:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("Hello", &alloc);
Str s3 = StrInitFromZstr("World", &alloc);- In
Str.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
Str.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
Str.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
Str.Ops.c:65:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle1 = StrInitFromZstr("World", &alloc);
Str needle2 = StrInitFromZstr("Hello", &alloc);- In
Str.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
Str.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
Str.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
Str.Ops.c:104:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle = StrInitFromZstr("World", &alloc);- In
Str.Ops.c:105:
Str haystack = StrInitFromZstr("Hello World", &alloc);
Str needle = StrInitFromZstr("World", &alloc);
bool result = StrContains(&haystack, &needle);- In
Str.Ops.c:130:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);- In
Str.Ops.c:131:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);- In
Str.Ops.c:132:
Str s = StrInitFromZstr("Hello World", &alloc);
Str prefix = StrInitFromZstr("Hello", &alloc);
Str suffix = StrInitFromZstr("World", &alloc);
// Test Str-form
- In
Str.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
Str.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
Str.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
Str.Ops.c:188:
// Test Str-form
StrDeinit(&s1);
s1 = StrInitFromZstr("Hello World", &alloc);
Str find = StrInitFromZstr("World", &alloc);
Str replace = StrInitFromZstr("Universe", &alloc);- In
Str.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
Str.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
Str.Ops.c:208:
// Test StrSplit
Str s = StrInitFromZstr("Hello,World,Test", &alloc);
Strs split = StrSplit(&s, ",");- In
Str.Ops.c:257:
// Test StrLStrip
Str s1 = StrInitFromZstr(" Hello ", &alloc);
Str stripped = StrLStrip(&s1, NULL);
bool result = (ZstrCompare(StrBegin(&stripped), "Hello ") == 0);- In
Str.Ops.c:274:
// Test with custom strip characters
StrDeinit(&s1);
s1 = StrInitFromZstr("***Hello***", &alloc);
stripped = StrLStrip(&s1, "*");- In
Str.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
Str.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
Str.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
Str.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
Str.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
Str.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
Str.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;
// Test decimal conversion
Str s = StrInitFromZstr("12345", &alloc);
u64 value = 0;
bool success = StrToU64(&s, &value, NULL); // 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); // Test hexadecimal conversion (auto-detect base with 0)
StrDeinit(&s);
s = StrInitFromZstr("0xABCD", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 0xABCD); // Test binary conversion
StrDeinit(&s);
s = StrInitFromZstr("0b101010", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 42); // Test octal conversion
StrDeinit(&s);
s = StrInitFromZstr("0o52", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 42); // Test zero
StrDeinit(&s);
s = StrInitFromZstr("0", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (success && value == 0); // Test invalid input
StrDeinit(&s);
s = StrInitFromZstr("not a number", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (!success); // Test negative number (should fail for unsigned)
StrDeinit(&s);
s = StrInitFromZstr("-123", &alloc);
success = StrToU64(&s, &value, NULL);
result = result && (!success);
// Test positive decimal conversion
Str s = StrInitFromZstr("12345", &alloc);
i64 value = 0;
bool success = StrToI64(&s, &value, NULL); // Test negative decimal conversion
StrDeinit(&s);
s = StrInitFromZstr("-12345", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == -12345); // Test hexadecimal conversion
StrDeinit(&s);
s = StrInitFromZstr("0xABCD", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == 0xABCD); // Test binary conversion
StrDeinit(&s);
s = StrInitFromZstr("0b101010", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == 42); // Test zero
StrDeinit(&s);
s = StrInitFromZstr("0", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (success && value == 0); // Test invalid input
StrDeinit(&s);
s = StrInitFromZstr("not a number", &alloc);
success = StrToI64(&s, &value, NULL);
result = result && (!success);
// Test integer conversion
Str s = StrInitFromZstr("123", &alloc);
f64 value = 0.0;
bool success = StrToF64(&s, &value, NULL); // Test fractional conversion
StrDeinit(&s);
s = StrInitFromZstr("123.456", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value - 123.456) < 0.0001); // Test negative number
StrDeinit(&s);
s = StrInitFromZstr("-123.456", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value - (-123.456)) < 0.0001); // Test scientific notation
StrDeinit(&s);
s = StrInitFromZstr("1.23e2", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value - 123.0) < 0.0001); // Test zero
StrDeinit(&s);
s = StrInitFromZstr("0", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64Abs(value) < 0.0001); // Test infinity
StrDeinit(&s);
s = StrInitFromZstr("inf", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64IsInf(value) && value > 0); // Test negative infinity
StrDeinit(&s);
s = StrInitFromZstr("-inf", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64IsInf(value) && value < 0); // Test NaN
StrDeinit(&s);
s = StrInitFromZstr("nan", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (success && F64IsNan(value)); // Test invalid input
StrDeinit(&s);
s = StrInitFromZstr("not a number", &alloc);
success = StrToF64(&s, &value, NULL);
result = result && (!success);
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}; 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
Str.Access.c:50:
Str s = StrInitFromZstr("Hello", &alloc);
// Get the first character
- In
Str.Access.c:69:
Str s = StrInitFromZstr("Hello", &alloc);
// Get the last character
- In
Str.Access.c:88:
Str s = StrInitFromZstr("Hello", &alloc);
// Get a pointer to the first character using StrBegin
- In
Str.Access.c:107:
Str s = StrInitFromZstr("Hello", &alloc);
// Get a pointer to one past the last character using StrEnd
- In
Str.Access.c:127:
Str s = StrInitFromZstr("Hello", &alloc);
// Access characters at different indices
- In
Str.Access.c:151:
Str s = StrInitFromZstr("Hello", &alloc);
// Access character pointers at different indices
- In
Io.Read.c:327:
StrReadFmt(z, "{}", s);
Str expected = StrInitFromZstr("Hello", &alloc);
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);- In
Io.Read.c:335:
StrReadFmt(z, "{s}", s);
expected = StrInitFromZstr("Hello, World!", &alloc);
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);- In
Io.Read.c:374:
success = success && (num == 42);
Str expected = StrInitFromZstr("Alice", &alloc);
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);- In
Io.Read.c:385:
success = success && double_equals(val, 3.14);
expected = StrInitFromZstr("Bob", &alloc);
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);- In
Io.Read.c:578:
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
Io.Read.c:588:
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
Io.Read.c:625:
// 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
Io.Read.c:650:
// 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
Io.Read.c:675:
// 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
Io.Read.c:744:
// 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
Io.Read.c:769:
// 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
Io.Read.c:794:
// 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
Graph.Init.c:80:
typedef Graph(Str) StrGraph;
StrGraph graph = GraphInitWithDeepCopy(str_init_copy, str_deinit, &alloc);
Str name = StrInitFromZstr("alpha", &alloc);
GraphNodeId node_id;
GraphNode node;- In
Io.Write.c:88:
StrClear(&output);
Str s = StrInitFromZstr("World", &alloc);
StrAppendFmt(&output, "{}", s);
success = success && (ZstrCompare(StrBegin(&output), "World") == 0);- In
Io.Write.c:383:
StrClear(&output);
Str s = StrInitFromZstr("MiXeD CaSe", &alloc);
StrAppendFmt(&output, "{c}", s);- In
Str.Insert.c:33:
Str s = StrInitFromZstr("Hello", &alloc);
// Insert a character in the middle
- In
Str.Insert.c:64:
Str s = StrInitFromZstr("Hello", &alloc);
// Insert a string in the middle: (cstr, cstr_len) adjacent, then idx
- In
Str.Insert.c:83:
Str s = StrInitFromZstr("Hello", &alloc);
// Insert a string in the middle
- In
Str.Insert.c:103:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at position 2
- In
Str.Insert.c:122:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at position 2
- In
Str.Insert.c:141:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at the back
- In
Str.Insert.c:160:
Str s = StrInitFromZstr("Hello", &alloc);
// Push a string at the back
- In
Str.Insert.c:179:
Str s = StrInitFromZstr("World", &alloc);
// Push a string at the front
- In
Str.Insert.c:198:
Str s = StrInitFromZstr("World", &alloc);
// Push a string at the front
- In
Str.Insert.c:217:
Str s = StrInitFromZstr("Hello", &alloc);
// Push characters at the back
- In
Str.Insert.c:241:
Str s = StrInitFromZstr("World", &alloc);
// Push characters at the front
- In
Str.Insert.c:265:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);- In
Str.Insert.c:266:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);
// Merge s2 into s1 (L-value semantics)
- In
Str.Insert.c:293:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);- In
Str.Insert.c:294:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);
// Merge s2 into s1 (R-value semantics)
- In
Str.Insert.c:317:
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr(" World", &alloc);- In
Str.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
Str.Insert.c:342:
Str s = StrInitFromZstr("Hello", &alloc);
// Append formatted suffix.
- In
Str.Type.c:53:
// Add some strings
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("World", &alloc);- In
Str.Type.c:54:
// Add some strings
Str s1 = StrInitFromZstr("Hello", &alloc);
Str s2 = StrInitFromZstr("World", &alloc);
VecPushBack(&sv, s1); // 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); // 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); 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); 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); Str s_gamma = StrInitFromZstr("Gamma", &alloc);
Str s_delta = StrInitFromZstr("Delta", &alloc);
Str s_echo = StrInitFromZstr("Echo", &alloc);
Str s_unknown = StrInitFromZstr("Unknown", &alloc); 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
Str.Init.c:65:
// Test StrInitFromZstr function
bool test_str_init_from_zstr(void) {
WriteFmt("Testing StrInitFromZstr\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Init.c:70:
Zstr test_str = "Hello, World!";
Str s = StrInitFromZstr(test_str, &alloc);
// Validate the string
- In
Str.Init.c:107:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("Hello, World!", &alloc);
Str dst = StrInitFromStr(&src, &alloc);- In
Str.Init.c:129:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("Hello, World!", &alloc);
Str dst = StrDup(&src, &alloc);- In
Str.Init.c:199:
DefaultAllocator alloc = DefaultAllocatorInit();
Str src = StrInitFromZstr("Hello, World!", &alloc);
Str dst = StrInit(&alloc);- In
Str.Init.c:254:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInitFromZstr("Hello, World!", &alloc);
// Validate the string before deinit
- In
Str.Foreach.c:39:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character with its index
- In
Str.Foreach.c:62:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character in reverse with its index
- In
Str.Foreach.c:87:
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer with its index
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer in reverse with its index
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character in reverse
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer
Str s = StrInitFromZstr("Hello", &alloc);
// Build a new string by iterating through each character pointer in reverse
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of characters with indices
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of characters
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of character pointers with indices
Str s = StrInitFromZstr("Hello World", &alloc);
// Build a new string by iterating through a range of character pointers
Str s = StrInitFromZstr("Hello World!", &alloc); // 12 characters
// Use StrForeachInRangeIdx which captures the 'end' parameter at the start
Str s = StrInitFromZstr("Programming", &alloc); // 11 characters
// Use StrForeachInRangeIdx with a fixed range that will become invalid
Str s = StrInitFromZstr("Beautiful Weather", &alloc); // 17 characters
// StrForeachReverseIdx (VecForeachReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
Str s = StrInitFromZstr("Programming Test", &alloc); // 16 characters
// StrForeachPtrIdx (VecForeachPtrIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
Str s = StrInitFromZstr("Excellent Example", &alloc); // 17 characters
// StrForeachReversePtrIdx (VecForeachPtrReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
Str s = StrInitFromZstr("Comprehensive Testing Framework", &alloc); // 31 characters
// Use StrForeachPtrInRangeIdx with a fixed range that becomes invalid when we modify the string
Str s = StrInitFromZstr("Testing Basic", &alloc); // 13 characters
// Basic StrForeachIdx (VecForeachIdx) now has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
Last updated on