StrCmp
- Macro
- August 22, 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)
}
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
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) {
printf("[DEBUG] Simple round-trip test passed\n");
} 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) {
printf("[DEBUG] String round-trip test passed\n");
- 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) {
printf("[DEBUG] String round-trip test passed\n");
} 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;
- In
Io.Read.c:288
:
Str expected = StrInitFromZstr("Hello");
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);
StrClear(&s);
- In
Io.Read.c:296
:
expected = StrInitFromZstr("Hello, World!");
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);
- In
Io.Read.c:317
:
Str expected = StrInitFromZstr("Alice");
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);
StrClear(&name);
- In
Io.Read.c:328
:
expected = StrInitFromZstr("Bob");
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);
- In
Io.Read.c:506
:
Str expected = StrInitFromZstr("Hello");
bool str_pass = (StrCmp(&str_val, &expected) == 0);
printf("str_val test: comparing with 'Hello', pass = %s\n", str_pass ? "true" : "false");
success = success && str_pass;
- In
Io.Read.c:517
:
expected = StrInitFromZstr("World");
bool quoted_str_pass = (StrCmp(&str_val, &expected) == 0);
printf("quoted str_val test: comparing with 'World', pass = %s\n", quoted_str_pass ? "true" : "false");
success = success && quoted_str_pass;
- In
Io.Read.c:549
:
// Should read "hello" (stops at first space)
Str expected = StrInitFromZstr("hello");
bool test1_pass = (StrCmp(&result, &expected) == 0);
printf("Expected: 'hello', Pass: %s\n\n", test1_pass ? "true" : "false");
success = success && test1_pass;
- In
Io.Read.c:573
:
// Should read "HELLO" (stops at first space)
Str expected = StrInitFromZstr("HELLO");
bool test2_pass = (StrCmp(&result, &expected) == 0);
printf("Expected: 'HELLO', Pass: %s\n\n", test2_pass ? "true" : "false");
success = success && test2_pass;
- In
Io.Read.c:597
:
// Should read "mixed case" (converts the entire quoted string)
Str expected = StrInitFromZstr("mixed case");
bool test3_pass = (StrCmp(&result, &expected) == 0);
printf("Expected: 'mixed case', Pass: %s\n\n", test3_pass ? "true" : "false");
success = success && test3_pass;
- In
Io.Read.c:621
:
// Should read "ABC123XYZ" (only letters are converted, numbers unchanged)
Str expected = StrInitFromZstr("ABC123XYZ");
bool test4_pass = (StrCmp(&result, &expected) == 0);
printf("Expected: 'ABC123XYZ', Pass: %s\n\n", test4_pass ? "true" : "false");
success = success && test4_pass;
- In
Io.Read.c:645
:
// Should read "Hello" (stops at first space, no case conversion)
Str expected = StrInitFromZstr("Hello");
bool test5_pass = (StrCmp(&result, &expected) == 0);
printf("Expected: 'Hello', Pass: %s\n\n", test5_pass ? "true" : "false");
success = success && test5_pass;
- In
Str.Ops.c:21
:
// Test string comparison functions
bool test_str_cmp(void) {
printf("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