ZstrCompare
- Function
- October 8, 2025
Table of Contents
ZstrCompare
ZstrCompareDescription
Compare two strings lexicographically.
Parameters
| Name | Direction | Description |
|---|---|---|
s1 | in | First string. |
s2 | in | Second string. |
Success
Returns 0 if equal, <0 if s1<s2, >0 if s1>s2.
Failure
Function cannot fail if strings are valid.
Usage example (Cross-references)
- In
Memory.c:85:
}
i32 ZstrCompare(const char *s1, const char *s2) {
if (!s1 || !s2) {
LOG_FATAL("Invalid arguments");
- In
Dir.c:93:
do {
// Skip "." and ".." entries
if (ZstrCompare(findFileData.cFileName, ".") == 0 || ZstrCompare(findFileData.cFileName, "..") == 0) {
continue;
}
- In
Str.Convert.c:36:
StrIntFormat config = {.base = 10, .uppercase = false};
StrFromU64(&s, 12345, &config);
bool result = (ZstrCompare(s.data, "12345") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '12345', got '{}'\n", s);
- In
Str.Convert.c:45:
config = (StrIntFormat) {.base = 16, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 0xABCD, &config);
result = result && (ZstrCompare(s.data, "0xabcd") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0xabcd', got '{}'\n", s);
- In
Str.Convert.c:54:
config = (StrIntFormat) {.base = 16, .uppercase = true, .use_prefix = true};
StrFromU64(&s, 0xABCD, &config);
result = result && (ZstrCompare(s.data, "0xABCD") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0xABCD', got '{}'\n", s);
- In
Str.Convert.c:63:
config = (StrIntFormat) {.base = 2, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 42, &config);
result = result && (ZstrCompare(s.data, "0b101010") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0b101010', got '{}'\n", s);
- In
Str.Convert.c:72:
config = (StrIntFormat) {.base = 8, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 42, &config);
result = result && (ZstrCompare(s.data, "0o52") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0o52', got '{}'\n", s);
- In
Str.Convert.c:81:
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromU64(&s, 0, &config);
result = result && (ZstrCompare(s.data, "0") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0', got '{}'\n", s);
- In
Str.Convert.c:99:
StrIntFormat config = {.base = 10, .uppercase = false};
StrFromI64(&s, 12345, &config);
bool result = (ZstrCompare(s.data, "12345") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '12345', got '{}'\n", s.data);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, -12345, &config);
result = result && (ZstrCompare(s.data, "-12345") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '-12345', got '{}'\n", s.data);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, 0, &config);
result = result && (ZstrCompare(s.data, "0") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0', got '{}'\n", s.data);
config = (StrIntFormat) {.base = 2, .uppercase = false, .use_prefix = true};
StrFromI64(&s, 42, &config);
result = result && (ZstrCompare(s.data, "0b101010") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '0b101010', got '{}'\n", s.data);
StrFloatFormat config = {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 123.0, &config);
bool result = (ZstrCompare(s.data, "123.00") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '123.00', got '{}'\n", s.data);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 123.456, &config);
result = result && (ZstrCompare(s.data, "123.456") == 0);
if (!result) {
WriteFmt(" FAIL: Expected '123.456', got '{}'\n", s.data);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, -123.456, &config);
result = result && (ZstrCompare(s.data, "-123.456") == 0);
// Test scientific notation (forced)
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = false};
StrFromF64(&s, 123.456, &config);
result = result && (ZstrCompare(s.data, "1.235e+02") == 0);
// Test scientific notation (uppercase)
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = true};
StrFromF64(&s, 123.456, &config);
result = result && (ZstrCompare(s.data, "1.235E+02") == 0);
// Test very small number (auto scientific notation)
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 0.0000123, &config);
result = result && (ZstrCompare(s.data, "1.230e-05") == 0);
// Test very large number (auto scientific notation)
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1234567890123.0, &config);
result = result && (ZstrCompare(s.data, "1.23e+12") == 0);
// Test zero
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 0.0, &config);
result = result && (ZstrCompare(s.data, "0.00") == 0);
// Test infinity
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, INFINITY, &config);
result = result && (ZstrCompare(s.data, "inf") == 0);
// Test negative infinity
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, -INFINITY, &config);
result = result && (ZstrCompare(s.data, "-inf") == 0);
// Test NaN
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, NAN, &config);
result = result && (ZstrCompare(s.data, "nan") == 0);
StrDeinit(&s);
- In
Io.Read.c:829:
StrReadFmt(z, "{}", bv1);
Str result1 = BitVecToStr(&bv1);
success = success && (ZstrCompare(result1.data, "10110") == 0);
WriteFmt(
"Test 1 - Binary: {}, Success: {}\n",
- In
Io.Read.c:833:
"Test 1 - Binary: {}, Success: {}\n",
result1,
(ZstrCompare(result1.data, "10110") == 0) ? "true" : "false"
);
StrDeinit(&result1);
- In
Io.Read.c:861:
StrReadFmt(z, "{}", bv4);
Str result4 = BitVecToStr(&bv4);
success = success && (ZstrCompare(result4.data, "1101") == 0);
WriteFmt(
"Test 4 - Whitespace: {}, Success: {}\n",
- In
Io.Read.c:865:
"Test 4 - Whitespace: {}, Success: {}\n",
result4,
(ZstrCompare(result4.data, "1101") == 0) ? "true" : "false"
);
StrDeinit(&result4);
- In
Io.Read.c:875:
StrReadFmt(z, "{}", bv5);
Str result5 = BitVecToStr(&bv5);
success = success && (ZstrCompare(result5.data, "0") == 0);
WriteFmt("Test 5 - Zero: {}, Success: {}\n", result5, (ZstrCompare(result5.data, "0") == 0) ? "true" : "false");
StrDeinit(&result5);
- In
Io.Read.c:876:
Str result5 = BitVecToStr(&bv5);
success = success && (ZstrCompare(result5.data, "0") == 0);
WriteFmt("Test 5 - Zero: {}, Success: {}\n", result5, (ZstrCompare(result5.data, "0") == 0) ? "true" : "false");
StrDeinit(&result5);
BitVecDeinit(&bv5);
- In
Str.Type.c:34:
StrPushBack(&s, 'o');
bool result = (s.length == 5 && ZstrCompare(s.data, "Hello") == 0);
StrDeinit(&s);
- In
Str.Type.c:62:
Str *str2 = &VecAt(&sv, 1);
result = result && (ZstrCompare(str1->data, "Hello") == 0);
result = result && (ZstrCompare(str2->data, "World") == 0);
}
- In
Str.Type.c:63:
result = result && (ZstrCompare(str1->data, "Hello") == 0);
result = result && (ZstrCompare(str2->data, "World") == 0);
}
- In
Io.Write.c:43:
// Test literal text
StrWriteFmt(&output, "Hello, world!");
success = success && (ZstrCompare(output.data, "Hello, world!") == 0);
StrClear(&output);
- In
Io.Write.c:48:
// Test escaped braces
StrWriteFmt(&output, "{{Hello}}");
success = success && (ZstrCompare(output.data, "{Hello}") == 0);
StrClear(&output);
- In
Io.Write.c:53:
// Test double escaped braces
StrWriteFmt(&output, "{{{{");
success = success && (ZstrCompare(output.data, "{{") == 0);
StrDeinit(&output);
- In
Io.Write.c:69:
const char *str = "Hello";
StrWriteFmt(&output, "{}", str);
success = success && (ZstrCompare(output.data, "Hello") == 0);
StrClear(&output);
- In
Io.Write.c:80:
// Test string with width and alignment
StrWriteFmt(&output, "{>10}", str);
success = success && (ZstrCompare(output.data, " Hello") == 0);
StrClear(&output);
- In
Io.Write.c:84:
StrWriteFmt(&output, "{<10}", str);
success = success && (ZstrCompare(output.data, "Hello ") == 0);
StrClear(&output);
- In
Io.Write.c:88:
StrWriteFmt(&output, "{^10}", str);
success = success && (ZstrCompare(output.data, " Hello ") == 0);
StrClear(&output);
- In
Io.Write.c:94:
Str s = StrInitFromZstr("World");
StrWriteFmt(&output, "{}", s);
success = success && (ZstrCompare(output.data, "World") == 0);
StrDeinit(&s);
- In
Io.Write.c:111:
i8 i8_val = -42;
StrWriteFmt(&output, "{}", i8_val);
success = success && (ZstrCompare(output.data, "-42") == 0);
StrClear(&output);
- In
Io.Write.c:116:
i16 i16_val = -1234;
StrWriteFmt(&output, "{}", i16_val);
success = success && (ZstrCompare(output.data, "-1234") == 0);
StrClear(&output);
- In
Io.Write.c:121:
i32 i32_val = -123456;
StrWriteFmt(&output, "{}", i32_val);
success = success && (ZstrCompare(output.data, "-123456") == 0);
StrClear(&output);
- In
Io.Write.c:126:
i64 i64_val = -1234567890LL;
StrWriteFmt(&output, "{}", i64_val);
success = success && (ZstrCompare(output.data, "-1234567890") == 0);
StrClear(&output);
- In
Io.Write.c:132:
u8 u8_val = 42;
StrWriteFmt(&output, "{}", u8_val);
success = success && (ZstrCompare(output.data, "42") == 0);
StrClear(&output);
- In
Io.Write.c:137:
u16 u16_val = 1234;
StrWriteFmt(&output, "{}", u16_val);
success = success && (ZstrCompare(output.data, "1234") == 0);
StrClear(&output);
- In
Io.Write.c:142:
u32 u32_val = 123456;
StrWriteFmt(&output, "{}", u32_val);
success = success && (ZstrCompare(output.data, "123456") == 0);
StrClear(&output);
- In
Io.Write.c:147:
u64 u64_val = 1234567890ULL;
StrWriteFmt(&output, "{}", u64_val);
success = success && (ZstrCompare(output.data, "1234567890") == 0);
StrClear(&output);
- In
Io.Write.c:153:
i8 i8_max = 127;
StrWriteFmt(&output, "{}", i8_max);
success = success && (ZstrCompare(output.data, "127") == 0);
StrClear(&output);
- In
Io.Write.c:158:
i8 i8_min = -128;
StrWriteFmt(&output, "{}", i8_min);
success = success && (ZstrCompare(output.data, "-128") == 0);
StrClear(&output);
- In
Io.Write.c:163:
u8 u8_max = 255;
StrWriteFmt(&output, "{}", u8_max);
success = success && (ZstrCompare(output.data, "255") == 0);
StrClear(&output);
- In
Io.Write.c:168:
u8 u8_min = 0;
StrWriteFmt(&output, "{}", u8_min);
success = success && (ZstrCompare(output.data, "0") == 0);
StrDeinit(&output);
- In
Io.Write.c:183:
u32 val = 0xDEADBEEF;
StrWriteFmt(&output, "{x}", val);
success = success && (ZstrCompare(output.data, "0xdeadbeef") == 0);
StrClear(&output);
- In
Io.Write.c:187:
StrWriteFmt(&output, "{X}", val);
success = success && (ZstrCompare(output.data, "0xDEADBEEF") == 0);
StrDeinit(&output);
- In
Io.Write.c:202:
u8 val = 0xA5; // 10100101 in binary
StrWriteFmt(&output, "{b}", val);
success = success && (ZstrCompare(output.data, "0b10100101") == 0);
StrDeinit(&output);
- In
Io.Write.c:217:
u16 val = 0777;
StrWriteFmt(&output, "{o}", val);
success = success && (ZstrCompare(output.data, "0o777") == 0);
StrDeinit(&output);
- In
Io.Write.c:232:
f32 f32_val = 3.14159f;
StrWriteFmt(&output, "{}", f32_val);
success = success && (ZstrCompare(output.data, "3.141590") == 0);
StrClear(&output);
- In
Io.Write.c:237:
f64 f64_val = 2.71828;
StrWriteFmt(&output, "{}", f64_val);
success = success && (ZstrCompare(output.data, "2.718280") == 0);
StrDeinit(&output);
- In
Io.Write.c:254:
// Test different precisions
StrWriteFmt(&output, "{.2}", val);
success = success && (ZstrCompare(output.data, "3.14") == 0);
StrClear(&output);
- In
Io.Write.c:258:
StrWriteFmt(&output, "{.0}", val);
success = success && (ZstrCompare(output.data, "3") == 0);
StrClear(&output);
- In
Io.Write.c:262:
StrWriteFmt(&output, "{.10}", val);
success = success && (ZstrCompare(output.data, "3.1415926536") == 0);
StrDeinit(&output);
- In
Io.Write.c:278:
f64 pos_inf = INFINITY;
StrWriteFmt(&output, "{}", pos_inf);
success = success && (ZstrCompare(output.data, "inf") == 0);
StrClear(&output);
- In
Io.Write.c:283:
f64 neg_inf = -INFINITY;
StrWriteFmt(&output, "{}", neg_inf);
success = success && (ZstrCompare(output.data, "-inf") == 0);
StrClear(&output);
- In
Io.Write.c:289:
f64 nan_val = NAN;
StrWriteFmt(&output, "{}", nan_val);
success = success && (ZstrCompare(output.data, "nan") == 0);
StrDeinit(&output);
- In
Io.Write.c:305:
i32 val = 42;
StrWriteFmt(&output, "{5}", val);
success = success && (ZstrCompare(output.data, " 42") == 0);
StrClear(&output);
- In
Io.Write.c:309:
StrWriteFmt(&output, "{<5}", val);
success = success && (ZstrCompare(output.data, "42 ") == 0);
StrClear(&output);
- In
Io.Write.c:313:
StrWriteFmt(&output, "{^5}", val);
success = success && (ZstrCompare(output.data, " 42 ") == 0);
StrClear(&output);
- In
Io.Write.c:319:
const char *str = "abc";
StrWriteFmt(&output, "{5}", str);
success = success && (ZstrCompare(output.data, " abc") == 0);
StrClear(&output);
- In
Io.Write.c:323:
StrWriteFmt(&output, "{<5}", str);
success = success && (ZstrCompare(output.data, "abc ") == 0);
StrClear(&output);
- In
Io.Write.c:327:
StrWriteFmt(&output, "{^5}", str);
success = success && (ZstrCompare(output.data, " abc ") == 0);
StrDeinit(&output);
- In
Io.Write.c:345:
StrWriteFmt(&output, "{} {} {}", hello, num, pi);
success = success && (ZstrCompare(output.data, "Hello 42 3.140000") == 0);
StrClear(&output);
- In
Io.Write.c:350:
// Instead of using positional arguments, we'll just reorder the arguments themselves
StrWriteFmt(&output, "{} {} {}", pi, hello, num);
success = success && (ZstrCompare(output.data, "3.140000 Hello 42") == 0);
StrDeinit(&output);
- In
Io.Write.c:366:
const char *mixed_case = "MiXeD CaSe";
StrWriteFmt(&output, "{c}", mixed_case);
success = success && (ZstrCompare(output.data, "MiXeD CaSe") == 0);
StrClear(&output);
- In
Io.Write.c:371:
// Test mixed case string with :a (lowercase)
StrWriteFmt(&output, "{a}", mixed_case);
success = success && (ZstrCompare(output.data, "mixed case") == 0);
StrClear(&output);
- In
Io.Write.c:376:
// Test mixed case string with :A (uppercase)
StrWriteFmt(&output, "{A}", mixed_case);
success = success && (ZstrCompare(output.data, "MIXED CASE") == 0);
StrClear(&output);
- In
Io.Write.c:384:
// Test with :c (preserve case)
StrWriteFmt(&output, "{c}", s);
success = success && (ZstrCompare(output.data, "MiXeD CaSe") == 0);
StrClear(&output);
- In
Io.Write.c:389:
// Test with :a (lowercase)
StrWriteFmt(&output, "{a}", s);
success = success && (ZstrCompare(output.data, "mixed case") == 0);
StrClear(&output);
- In
Io.Write.c:394:
// Test with :A (uppercase)
StrWriteFmt(&output, "{A}", s);
success = success && (ZstrCompare(output.data, "MIXED CASE") == 0);
StrClear(&output);
- In
Io.Write.c:403:
// Test uppercase char with :c (preserve case)
StrWriteFmt(&output, "{c}", upper_char);
success = success && (ZstrCompare(output.data, "M") == 0);
StrClear(&output);
- In
Io.Write.c:408:
// Test uppercase char with :a (lowercase)
StrWriteFmt(&output, "{a}", upper_char);
success = success && (ZstrCompare(output.data, "m") == 0);
StrClear(&output);
- In
Io.Write.c:413:
// Test lowercase char with :A (uppercase)
StrWriteFmt(&output, "{A}", lower_char);
success = success && (ZstrCompare(output.data, "M") == 0);
StrClear(&output);
- In
Io.Write.c:558:
BitVec bv1 = BitVecFromStr("10110");
StrWriteFmt(&output, "{}", bv1);
success = success && (ZstrCompare(output.data, "10110") == 0);
StrClear(&output);
- In
Io.Write.c:570:
BitVec bv2 = BitVecFromInteger(0xABCD, 16);
StrWriteFmt(&output, "{x}", bv2);
success = success && (ZstrCompare(output.data, "0xabcd") == 0);
StrClear(&output);
- In
Io.Write.c:575:
// Test 4: Uppercase hex formatting
StrWriteFmt(&output, "{X}", bv2);
success = success && (ZstrCompare(output.data, "0xABCD") == 0);
StrClear(&output);
- In
Io.Write.c:581:
BitVec bv3 = BitVecFromInteger(0755, 10);
StrWriteFmt(&output, "{o}", bv3);
success = success && (ZstrCompare(output.data, "0o755") == 0);
StrClear(&output);
- In
Io.Write.c:586:
// Test 6: Width and alignment
StrWriteFmt(&output, "{>10}", bv1);
success = success && (ZstrCompare(output.data, " 10110") == 0);
StrClear(&output);
- In
Io.Write.c:590:
StrWriteFmt(&output, "{<10}", bv1);
success = success && (ZstrCompare(output.data, "10110 ") == 0);
StrClear(&output);
- In
Io.Write.c:594:
StrWriteFmt(&output, "{^10}", bv1);
success = success && (ZstrCompare(output.data, " 10110 ") == 0);
StrClear(&output);
- In
Io.Write.c:600:
BitVec bv_zero = BitVecFromInteger(0, 1);
StrWriteFmt(&output, "{x}", bv_zero);
success = success && (ZstrCompare(output.data, "0x0") == 0);
StrClear(&output);
- In
Io.Write.c:604:
StrWriteFmt(&output, "{o}", bv_zero);
success = success && (ZstrCompare(output.data, "0o0") == 0);
StrClear(&output);
- In
Str.Remove.c:30:
// Check that the character was popped correctly
bool result = (c == 'o' && ZstrCompare(s.data, "Hell") == 0);
// Pop another character without storing it - avoid passing NULL directly
- In
Str.Remove.c:37:
// Check that the character was removed
result = result && (ZstrCompare(s.data, "Hel") == 0);
StrDeinit(&s);
- In
Str.Remove.c:54:
// Check that the character was popped correctly
bool result = (c == 'H' && ZstrCompare(s.data, "ello") == 0);
// Pop another character without storing it - avoid passing NULL directly
- In
Str.Remove.c:61:
// Check that the character was removed
result = result && (ZstrCompare(s.data, "llo") == 0);
StrDeinit(&s);
- In
Str.Remove.c:78:
// Check that the character was removed correctly
bool result = (c == 'l' && ZstrCompare(s.data, "Helo") == 0);
// Remove another character without storing it - avoid passing NULL directly
- In
Str.Remove.c:85:
// Check that the character was removed
result = result && (ZstrCompare(s.data, "Hlo") == 0);
StrDeinit(&s);
- In
Str.Remove.c:105:
// Check that the characters were removed correctly
bool result = (ZstrCompare(buffer, " Worl") == 0 && ZstrCompare(s.data, "Hellod") == 0);
// Remove another range without storing it - use a temporary buffer instead of NULL
- In
Str.Remove.c:112:
// Check that the characters were removed
result = result && (ZstrCompare(s.data, "Hell") == 0);
StrDeinit(&s);
- In
Str.Remove.c:128:
// Check that the character was deleted
bool result = (ZstrCompare(s.data, "Hell") == 0);
// Delete another character
- In
Str.Remove.c:134:
// Check that the character was deleted
result = result && (ZstrCompare(s.data, "Hel") == 0);
StrDeinit(&s);
- In
Str.Remove.c:150:
// Check that the character was deleted
bool result = (ZstrCompare(s.data, "Helo") == 0);
// Delete another character
- In
Str.Remove.c:156:
// Check that the character was deleted
result = result && (ZstrCompare(s.data, "Hlo") == 0);
StrDeinit(&s);
- In
Str.Remove.c:172:
// Check that the characters were deleted
bool result = (ZstrCompare(s.data, "Hello") == 0);
// Delete another range
- In
Str.Remove.c:178:
// Check that the characters were deleted
result = result && (ZstrCompare(s.data, "Heo") == 0);
StrDeinit(&s);
- In
Str.Foreach.c:45:
// The result should be "H0e1l2l3o4"
bool success = (ZstrCompare(result.data, "H0e1l2l3o4") == 0);
StrDeinit(&s);
- In
Str.Foreach.c:66:
}
bool success = (ZstrCompare(result.data, "o4l3l2e1H0") == 0);
WriteFmt(" (Index 0 was processed)\n");
- In
Str.Foreach.c:93:
// The result should be "H0e1l2l3o4"
bool success = (ZstrCompare(result.data, "H0e1l2l3o4") == 0);
// The original string should now be "HELLO" (all uppercase)
- In
Str.Foreach.c:96:
// The original string should now be "HELLO" (all uppercase)
success = success && (ZstrCompare(s.data, "HELLO") == 0);
StrDeinit(&s);
bool success = false;
success = (ZstrCompare(result.data, "o4l3l2e1H0") == 0);
success = success && (ZstrCompare(s.data, "HELLO") == 0); // All uppercase
WriteFmt(" (Index 0 was processed)\n");
bool success = false;
success = (ZstrCompare(result.data, "o4l3l2e1H0") == 0);
success = success && (ZstrCompare(s.data, "HELLO") == 0); // All uppercase
WriteFmt(" (Index 0 was processed)\n");
// The result should be "Hello"
bool success = (ZstrCompare(result.data, "Hello") == 0);
StrDeinit(&s);
bool success = false;
if (char_count == s.length) {
success = (ZstrCompare(result.data, "olleH") == 0);
WriteFmt(" (All characters were processed)\n");
} else {
WriteFmt(" (All characters were processed)\n");
} else {
success = (ZstrCompare(result.data, "olle") == 0);
WriteFmt(" (First character was NOT processed - bug in macro)\n");
}
// The result should be "Hello" (original values before modification)
bool success = (ZstrCompare(result.data, "Hello") == 0);
// The original string should now be "HELLO" (all uppercase)
// The original string should now be "HELLO" (all uppercase)
success = success && (ZstrCompare(s.data, "HELLO") == 0);
StrDeinit(&s);
bool success = false;
if (char_count == s.length) {
success = (ZstrCompare(result.data, "olleH") == 0);
success = success && (ZstrCompare(s.data, "HELLO") == 0); // All uppercase
WriteFmt(" (All characters were processed)\n");
if (char_count == s.length) {
success = (ZstrCompare(result.data, "olleH") == 0);
success = success && (ZstrCompare(s.data, "HELLO") == 0); // All uppercase
WriteFmt(" (All characters were processed)\n");
} else {
WriteFmt(" (All characters were processed)\n");
} else {
success = (ZstrCompare(result.data, "olle") == 0);
success = success && (ZstrCompare(s.data, "HELLo") == 0); // All uppercase except first char
WriteFmt(" (First character was NOT processed - bug in macro)\n");
} else {
success = (ZstrCompare(result.data, "olle") == 0);
success = success && (ZstrCompare(s.data, "HELLo") == 0); // All uppercase except first char
WriteFmt(" (First character was NOT processed - bug in macro)\n");
}
// The result should be "W6o7r8l9d10" (characters from index 6-10 with their indices)
bool success = (ZstrCompare(result.data, "W6o7r8l9d10") == 0);
// Test with empty range
// The result should be "Hello" (first 5 characters)
bool success = (ZstrCompare(result.data, "Hello") == 0);
// Test with range at the end of the string
// The end_result should be "World" (last 5 characters)
success = success && (ZstrCompare(end_result.data, "World") == 0);
StrDeinit(&s);
// The result should be "W6o7r8l9d10" (characters from index 6-10 with their indices)
bool success = (ZstrCompare(result.data, "W6o7r8l9d10") == 0);
// The original string should now have "WORLD" in uppercase
// The original string should now have "WORLD" in uppercase
success = success && (ZstrCompare(s.data, "Hello WORLD") == 0);
StrDeinit(&s);
// The result should be "Hello" (first 5 characters)
bool success = (ZstrCompare(result.data, "Hello") == 0);
// The original string should now have "HELLO" in uppercase
// The original string should now have "HELLO" in uppercase
success = success && (ZstrCompare(s.data, "HELLO World") == 0);
StrDeinit(&s);
- In
Str.Init.c:67:
// Check that it's initialized correctly
bool result = (s.length == strlen(test_str) && ZstrCompare(s.data, test_str) == 0);
StrDeinit(&s);
- In
Str.Init.c:85:
// Check that dst is initialized correctly
bool result = (dst.length == src.length && ZstrCompare(dst.data, src.data) == 0);
StrDeinit(&src);
- In
Str.Init.c:104:
// Check that dst is initialized correctly
bool result = (dst.length == src.length && ZstrCompare(dst.data, src.data) == 0);
StrDeinit(&src);
- In
Str.Init.c:122:
// Check that it's initialized correctly
bool result = (ZstrCompare(s.data, "Hello, World!") == 0);
StrDeinit(&s);
- In
Str.Init.c:144:
// Check that it works correctly
if (ZstrCompare(stack_str.data, "Hello, Stack!") != 0) {
result = false;
}
- In
Str.Init.c:177:
// Check that the copy was successful
bool result = (success && dst.length == src.length && ZstrCompare(dst.data, src.data) == 0);
StrDeinit(&src);
- In
Str.Ops.c:65:
// Test StrFindStr with match at end
const char *found1 = StrFindStr(&haystack, &needle1);
bool result = (found1 != NULL && ZstrCompare(found1, "World") == 0);
// Test StrFindStr with match at beginning
- In
Str.Ops.c:69:
// Test StrFindStr with match at beginning
const char *found2 = StrFindStr(&haystack, &needle2);
result = result && (found2 != NULL && ZstrCompare(found2, "Hello World") == 0);
// Test StrFindStr with no match
- In
Str.Ops.c:77:
// Test StrFindZstr
const char *found4 = StrFindZstr(&haystack, "World");
result = result && (found4 != NULL && ZstrCompare(found4, "World") == 0);
// Test StrFindCstr
- In
Str.Ops.c:133:
Str s1 = StrInitFromZstr("Hello World");
StrReplaceZstr(&s1, "World", "Universe", 1);
bool result = (ZstrCompare(s1.data, "Hello Universe") == 0);
// Test multiple replacements
- In
Str.Ops.c:139:
s1 = StrInitFromZstr("Hello Hello Hello");
StrReplaceZstr(&s1, "Hello", "Hi", 2);
result = result && (ZstrCompare(s1.data, "Hi Hi Hello") == 0);
// Test StrReplaceCstr - use the full "World" string instead of just "Wo"
- In
Str.Ops.c:145:
s1 = StrInitFromZstr("Hello World");
StrReplaceCstr(&s1, "World", 5, "Universe", 8, 1);
result = result && (ZstrCompare(s1.data, "Hello Universe") == 0);
// Test StrReplace
- In
Str.Ops.c:153:
Str replace = StrInitFromZstr("Universe");
StrReplace(&s1, &find, &replace, 1);
result = result && (ZstrCompare(s1.data, "Hello Universe") == 0);
StrDeinit(&s1);
- In
Str.Ops.c:171:
bool result = (split.length == 3);
if (split.length >= 3) {
result = result && (ZstrCompare(split.data[0].data, "Hello") == 0);
result = result && (ZstrCompare(split.data[1].data, "World") == 0);
result = result && (ZstrCompare(split.data[2].data, "Test") == 0);
- In
Str.Ops.c:172:
if (split.length >= 3) {
result = result && (ZstrCompare(split.data[0].data, "Hello") == 0);
result = result && (ZstrCompare(split.data[1].data, "World") == 0);
result = result && (ZstrCompare(split.data[2].data, "Test") == 0);
}
- In
Str.Ops.c:173:
result = result && (ZstrCompare(split.data[0].data, "Hello") == 0);
result = result && (ZstrCompare(split.data[1].data, "World") == 0);
result = result && (ZstrCompare(split.data[2].data, "Test") == 0);
}
- In
Str.Ops.c:187:
char buffer1[10] = {0};
memcpy(buffer1, iter1->data, iter1->length);
result = result && (ZstrCompare(buffer1, "Hello") == 0);
// Check second iterator
- In
Str.Ops.c:193:
char buffer2[10] = {0};
memcpy(buffer2, iter2->data, iter2->length);
result = result && (ZstrCompare(buffer2, "World") == 0);
// Check third iterator
- In
Str.Ops.c:199:
char buffer3[10] = {0};
memcpy(buffer3, iter3->data, iter3->length);
result = result && (ZstrCompare(buffer3, "Test") == 0);
}
- In
Str.Ops.c:214:
Str s1 = StrInitFromZstr(" Hello ");
Str stripped = StrLStrip(&s1, NULL);
bool result = (ZstrCompare(stripped.data, "Hello ") == 0);
StrDeinit(&stripped);
- In
Str.Ops.c:219:
// Test StrRStrip
stripped = StrRStrip(&s1, NULL);
result = result && (ZstrCompare(stripped.data, " Hello") == 0);
StrDeinit(&stripped);
- In
Str.Ops.c:224:
// Test StrStrip
stripped = StrStrip(&s1, NULL);
result = result && (ZstrCompare(stripped.data, "Hello") == 0);
StrDeinit(&stripped);
- In
Str.Ops.c:232:
stripped = StrLStrip(&s1, "*");
result = result && (ZstrCompare(stripped.data, "Hello***") == 0);
StrDeinit(&stripped);
- In
Str.Ops.c:236:
stripped = StrRStrip(&s1, "*");
result = result && (ZstrCompare(stripped.data, "***Hello") == 0);
StrDeinit(&stripped);
- In
Str.Ops.c:240:
stripped = StrStrip(&s1, "*");
result = result && (ZstrCompare(stripped.data, "Hello") == 0);
StrDeinit(&stripped);
- In
Str.Insert.c:38:
// Check that the character was inserted correctly
bool result = (ZstrCompare(s.data, "He!llo") == 0);
// Insert a character at the beginning
- In
Str.Insert.c:44:
// Check that the character was inserted correctly
result = result && (ZstrCompare(s.data, "?He!llo") == 0);
// Insert a character at the end
- In
Str.Insert.c:50:
// Check that the character was inserted correctly
result = result && (ZstrCompare(s.data, "?He!llo.") == 0);
StrDeinit(&s);
- In
Str.Insert.c:66:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
StrDeinit(&s);
- In
Str.Insert.c:82:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
StrDeinit(&s);
- In
Str.Insert.c:99:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s1.data, "He Worldllo") == 0);
StrDeinit(&s1);
- In
Str.Insert.c:116:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
StrDeinit(&s);
- In
Str.Insert.c:132:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
StrDeinit(&s);
- In
Str.Insert.c:148:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "Hello World") == 0);
StrDeinit(&s);
- In
Str.Insert.c:164:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "Hello World") == 0);
StrDeinit(&s);
- In
Str.Insert.c:180:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "Hello World") == 0);
StrDeinit(&s);
- In
Str.Insert.c:196:
// Check that the string was inserted correctly
bool result = (ZstrCompare(s.data, "Hello World") == 0);
StrDeinit(&s);
- In
Str.Insert.c:217:
// Check that the characters were inserted correctly
bool result = (ZstrCompare(s.data, "Hello World") == 0);
StrDeinit(&s);
- In
Str.Insert.c:238:
// Check that the characters were inserted correctly
bool result = (ZstrCompare(s.data, "Hello World") == 0);
StrDeinit(&s);
- In
Str.Insert.c:259:
// Check that the strings were merged correctly
bool result = (ZstrCompare(s1.data, "Hello World") == 0);
// Check that s2 was reset - data should be NULL, length should be 0
- In
Str.Insert.c:280:
// Check that the strings were merged correctly
bool result = (ZstrCompare(s1.data, "Hello World") == 0);
// Check that s2 was not reset
- In
Str.Insert.c:283:
// Check that s2 was not reset
result = result && (s2.length == 6 && ZstrCompare(s2.data, " World") == 0);
StrDeinit(&s1);
- In
Str.Insert.c:301:
// Check that the strings were merged correctly
bool result = (ZstrCompare(s1.data, "Hello World") == 0);
// Check that s2 was not reset (since StrMerge is an alias for StrMergeR)
- In
Str.Insert.c:304:
// Check that s2 was not reset (since StrMerge is an alias for StrMergeR)
result = result && (s2.length == 6 && ZstrCompare(s2.data, " World") == 0);
StrDeinit(&s1);
- In
Str.Insert.c:321:
// Check that the string was appended correctly
bool result = (ZstrCompare(s.data, "Hello World 2023") == 0);
StrDeinit(&s);
- In
Str.Memory.c:147:
// Check that the string was reversed
bool result = (ZstrCompare(s.data, "olleH") == 0);
// Test with an even-length string
- In
Str.Memory.c:157:
// Check that the string was reversed
result = result && (ZstrCompare(s.data, "dcba") == 0);
// Test with a single-character string
- In
Str.Memory.c:167:
// Check that the string is unchanged
result = result && (ZstrCompare(s.data, "a") == 0);
// Test with an empty string
// Should get exact same string back
result = result && (ZstrCompare(str.data, patterns[i]) == 0);
StrDeinit(&str);
// Test string conversion consistency
Str str = BitVecToStr(&bv);
result = result && (ZstrCompare(str.data, test_cases[i].pattern) == 0);
StrDeinit(&str);
u64 value = BitVecToInteger(&bv);
// We test that we get a consistent value (not necessarily the exact expected one)
result = result && (value > 0 || ZstrCompare(test_cases[i].pattern, "00000000") == 0);
// Test byte conversion
// At least two of them should match (bit order might affect one)
bool cross_match = (ZstrCompare(str1.data, str2.data) == 0) || (ZstrCompare(str1.data, str3.data) == 0) ||
(ZstrCompare(str2.data, str3.data) == 0);
result = result && cross_match;
// At least two of them should match (bit order might affect one)
bool cross_match = (ZstrCompare(str1.data, str2.data) == 0) || (ZstrCompare(str1.data, str3.data) == 0) ||
(ZstrCompare(str2.data, str3.data) == 0);
result = result && cross_match;
- In
Ops.h:30:
/// RETURN : 0 if both are equal
///
#define StrCmp(str, ostr) ZstrCompare((str)->data, (ostr)->data)
///
- In
Ops.h:53:
/// RETURN : 0 if both are equal
///
#define StrCmpZstr(str, zstr) ZstrCompare((str)->data, (zstr))
//