StrCmp
- Macro
- October 8, 2025
Table of Contents
StrCmp
StrCmp
Description
Compare two Str objects
Parameters
Name | Direction | Description |
---|---|---|
str | in | First string |
ostr | in | Other string |
Usage example (Cross-references)
- In
Io.Read.c:345
:
Str expected = StrInitFromZstr("Hello");
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);
StrClear(&s);
- In
Io.Read.c:354
:
expected = StrInitFromZstr("Hello, World!");
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);
- In
Io.Read.c:378
:
Str expected = StrInitFromZstr("Alice");
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);
StrClear(&name);
- In
Io.Read.c:390
:
expected = StrInitFromZstr("Bob");
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);
- In
Io.Read.c:590
:
StrReadFmt(z, "{c}", str_val);
Str expected = StrInitFromZstr("Hello");
bool str_pass = (StrCmp(&str_val, &expected) == 0);
WriteFmt("str_val test: comparing with 'Hello', pass = {}\n", str_pass ? "true" : "false");
success = success && str_pass;
- In
Io.Read.c:600
:
StrReadFmt(z, "{cs}", str_val);
expected = StrInitFromZstr("World");
bool quoted_str_pass = (StrCmp(&str_val, &expected) == 0);
WriteFmt("quoted str_val test: comparing with 'World', pass = {}\n", quoted_str_pass ? "true" : "false");
success = success && quoted_str_pass;
- In
Io.Read.c:635
:
// Should read "hello" (stops at first space)
Str expected = StrInitFromZstr("hello world");
bool test1_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'hello', Pass: {}\n\n", test1_pass ? "true" : "false");
success = success && test1_pass;
- In
Io.Read.c:660
:
// Should read "hello" (stops at first space)
Str expected = StrInitFromZstr("hello");
bool test1_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'hello', Pass: {}\n\n", test1_pass ? "true" : "false");
success = success && test1_pass;
- In
Io.Read.c:685
:
// Should read "HELLO" (stops at first space)
Str expected = StrInitFromZstr("HELLO WORLD");
bool test2_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'HELLO', Pass: {}\n\n", test2_pass ? "true" : "false");
success = success && test2_pass;
- In
Io.Read.c:754
:
// Should read "mixed case" (converts the entire quoted string)
Str expected = StrInitFromZstr("mixed case");
bool test3_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'mixed case', Pass: {}\n\n", test3_pass ? "true" : "false");
success = success && test3_pass;
- In
Io.Read.c:779
:
// Should read "ABC123XYZ" (only letters are converted, numbers unchanged)
Str expected = StrInitFromZstr("ABC123XYZ");
bool test4_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'ABC123XYZ', Pass: {}\n\n", test4_pass ? "true" : "false");
success = success && test4_pass;
- In
Io.Read.c:804
:
// Should read "Hello" (stops at first space, no case conversion)
Str expected = StrInitFromZstr("Hello World");
bool test5_pass = (StrCmp(&result, &expected) == 0);
WriteFmt("Expected: 'Hello World', Pass: {}\n\n", test5_pass ? "true" : "false");
success = success && test5_pass;
- In
Str.Ops.c:21
:
// Test string comparison functions
bool test_str_cmp(void) {
WriteFmt("Testing StrCmp and StrCmpCstr\n");
Str s1 = StrInitFromZstr("Hello");
- In
Str.Ops.c:29
:
// Test StrCmp with equal strings
int cmp1 = StrCmp(&s1, &s2);
bool result = (cmp1 == 0);
- In
Str.Ops.c:33
:
// Test StrCmp with different strings (H < W in ASCII)
int cmp2 = StrCmp(&s1, &s3);
result = result && (cmp2 < 0);
- In
Str.Ops.c:37
:
// Test StrCmp with string prefix - ZstrCompare compares the entire strings
int cmp3 = StrCmp(&s1, &s4);
result = result && (cmp3 < 0); // "Hello" comes before "Hello World" lexicographically
- In
RoundTrip.c:65
:
// Helper function to compare persons
bool compare_persons(const TestPerson *a, const TestPerson *b) {
return a->id == b->id && StrCmp(&a->name, &b->name) == 0 && a->age == b->age && a->is_active == b->is_active &&
a->salary == b->salary;
}
- In
RoundTrip.c:71
:
// Helper function to compare configs
bool compare_configs(const TestConfig *a, const TestConfig *b) {
if (a->debug_mode != b->debug_mode || a->timeout != b->timeout || StrCmp(&a->log_level, &b->log_level) != 0 ||
VecLen(&a->features) != VecLen(&b->features)) {
return false;
- In
RoundTrip.c:77
:
for (size i = 0; i < VecLen(&a->features); i++) {
if (StrCmp(&VecAt(&a->features, i), &VecAt(&b->features, i)) != 0) {
return false;
}
- In
RoundTrip.c:127
:
// Compare values
if (original.count == parsed.count && original.temperature == parsed.temperature &&
original.enabled == parsed.enabled && StrCmp(&original.message, &parsed.message) == 0) {
WriteFmtLn("[DEBUG] Simple round-trip test passed");
} else {
- In
RoundTrip.c:323
:
// Compare values
if (parsed.empty.length == original.empty.length && StrCmp(&original.simple, &parsed.simple) == 0 &&
StrCmp(&original.with_spaces, &parsed.with_spaces) == 0 &&
StrCmp(&original.with_special, &parsed.with_special) == 0) {
- In
RoundTrip.c:324
:
// Compare values
if (parsed.empty.length == original.empty.length && StrCmp(&original.simple, &parsed.simple) == 0 &&
StrCmp(&original.with_spaces, &parsed.with_spaces) == 0 &&
StrCmp(&original.with_special, &parsed.with_special) == 0) {
WriteFmtLn("[DEBUG] String round-trip test passed");
- In
RoundTrip.c:325
:
if (parsed.empty.length == original.empty.length && StrCmp(&original.simple, &parsed.simple) == 0 &&
StrCmp(&original.with_spaces, &parsed.with_spaces) == 0 &&
StrCmp(&original.with_special, &parsed.with_special) == 0) {
WriteFmtLn("[DEBUG] String round-trip test passed");
} else {
- In
RoundTrip.c:413
:
if (VecAt(&original_strings, i).length != VecAt(&parsed_strings, i).length ||
(VecAt(&original_strings, i).length &&
StrCmp(&VecAt(&original_strings, i), &VecAt(&parsed_strings, i)) != 0)) {
strings_match = false;
break;
}
bool result = StrCmp(&output_clean, &expected_clean) == 0;
if (!result) {
}
bool result = StrCmp(&output_clean, &expected_clean) == 0;
if (!result) {
}
bool result = StrCmp(&output_clean, &expected_clean) == 0;
if (!result) {
- In
Str.c:185
:
if (VecLen(str) > 0) {
Str temp = generate_str_from_input(data, offset, size, 20);
int result = StrCmp(str, &temp);
(void)result; // Suppress unused variable warning
StrDeinit(&temp);