Skip to content

ZstrCompare

ZstrCompare

Description

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)

Usage examples (Cross-references)
    }
    
    i32 ZstrCompare(const char *s1, const char *s2) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
        do {
            // Skip "." and ".." entries
            if (ZstrCompare(findFileData.cFileName, ".") == 0 || ZstrCompare(findFileData.cFileName, "..") == 0) {
                continue;
            }
        custom_policy.max_probe_count = 0;
    
        return ZstrCompare(map.policy.name, "custom-linear") == 0 &&
               map.policy.should_rehash == custom_should_rehash_snapshot &&
               map.policy.next_capacity == custom_next_capacity && map.policy.first_index == custom_first_index &&
    
        // Check that the character was inserted correctly
        bool result = (ZstrCompare(s.data, "He!llo") == 0);
    
        // Insert a character at the beginning
    
        // Check that the character was inserted correctly
        result = result && (ZstrCompare(s.data, "?He!llo") == 0);
    
        // Insert a character at the end
    
        // Check that the character was inserted correctly
        result = result && (ZstrCompare(s.data, "?He!llo.") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s1.data, "He Worldllo") == 0);
    
        StrDeinit(&s1);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "He Worldllo") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "Hello World") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "Hello World") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "Hello World") == 0);
    
        StrDeinit(&s);
    
        // Check that the string was inserted correctly
        bool result = (ZstrCompare(s.data, "Hello World") == 0);
    
        StrDeinit(&s);
    
        // Check that the characters were inserted correctly
        bool result = (ZstrCompare(s.data, "Hello World") == 0);
    
        StrDeinit(&s);
    
        // Check that the characters were inserted correctly
        bool result = (ZstrCompare(s.data, "Hello World") == 0);
    
        StrDeinit(&s);
    
        // 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
    
        // Check that the strings were merged correctly
        bool result = (ZstrCompare(s1.data, "Hello World") == 0);
    
        // Check that s2 was not reset
    
        // Check that s2 was not reset
        result = result && (s2.length == 6 && ZstrCompare(s2.data, " World") == 0);
    
        StrDeinit(&s1);
    
        // 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)
    
        // 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);
    
        // Check that the string was appended correctly
        bool result = (ZstrCompare(s.data, "Hello World 2023") == 0);
    
        StrDeinit(&s);
        StrReadFmt(z, "{}", bv1);
        Str result1 = BitVecToStr(&bv1);
        success     = success && (ZstrCompare(result1.data, "10110") == 0);
        WriteFmt(
            "Test 1 - Binary: {}, Success: {}\n",
            "Test 1 - Binary: {}, Success: {}\n",
            result1,
            (ZstrCompare(result1.data, "10110") == 0) ? "true" : "false"
        );
        StrDeinit(&result1);
        StrReadFmt(z, "{}", bv4);
        Str result4 = BitVecToStr(&bv4);
        success     = success && (ZstrCompare(result4.data, "1101") == 0);
        WriteFmt(
            "Test 4 - Whitespace: {}, Success: {}\n",
            "Test 4 - Whitespace: {}, Success: {}\n",
            result4,
            (ZstrCompare(result4.data, "1101") == 0) ? "true" : "false"
        );
        StrDeinit(&result4);
        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);
        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);
        StrReadFmt(z, "{}", dec);
        dec_text = IntToStr(&dec);
        success  = success && (ZstrCompare(dec_text.data, "123456789012345678901234567890") == 0);
    
        z = "deadbeefcafebabe1234";
        StrReadFmt(z, "{x}", hex);
        hex_text = IntToHexStr(&hex);
        success  = success && (ZstrCompare(hex_text.data, "deadbeefcafebabe1234") == 0);
    
        z = "10100011";
        StrReadFmt(z, "{b}", bin);
        bin_text = IntToBinary(&bin);
        success  = success && (ZstrCompare(bin_text.data, "10100011") == 0);
    
        z = "755";
        StrReadFmt(z, "{o}", oct);
        oct_text = IntToOctStr(&oct);
        success  = success && (ZstrCompare(oct_text.data, "755") == 0);
    
        StrDeinit(&dec_text);
        StrReadFmt(z, "{}", dec);
        dec_text = FloatToStr(&dec);
        success  = success && (ZstrCompare(dec_text.data, "1234567890.012345") == 0);
    
        z = "1.234567e+04";
        StrReadFmt(z, "{e}", sci);
        sci_text = FloatToStr(&sci);
        success  = success && (ZstrCompare(sci_text.data, "12345.67") == 0);
    
        z = "-0.00125";
        StrReadFmt(z, "{}", neg);
        neg_text = FloatToStr(&neg);
        success  = success && (ZstrCompare(neg_text.data, "-0.00125") == 0);
    
        StrDeinit(&dec_text);
        StrPushBack(&s, 'o');
    
        bool result = (s.length == 5 && ZstrCompare(s.data, "Hello") == 0);
    
        StrDeinit(&s);
            Str *str2 = &VecAt(&sv, 1);
    
            result = result && (ZstrCompare(str1->data, "Hello") == 0);
            result = result && (ZstrCompare(str2->data, "World") == 0);
        }
    
            result = result && (ZstrCompare(str1->data, "Hello") == 0);
            result = result && (ZstrCompare(str2->data, "World") == 0);
        }
        // Test literal text
        StrWriteFmt(&output, "Hello, world!");
        success = success && (ZstrCompare(output.data, "Hello, world!") == 0);
        StrClear(&output);
        // Test escaped braces
        StrWriteFmt(&output, "{{Hello}}");
        success = success && (ZstrCompare(output.data, "{Hello}") == 0);
        StrClear(&output);
        // Test double escaped braces
        StrWriteFmt(&output, "{{{{");
        success = success && (ZstrCompare(output.data, "{{") == 0);
    
        StrDeinit(&output);
        const char *str = "Hello";
        StrWriteFmt(&output, "{}", str);
        success = success && (ZstrCompare(output.data, "Hello") == 0);
        StrClear(&output);
        // Test string with width and alignment
        StrWriteFmt(&output, "{>10}", str);
        success = success && (ZstrCompare(output.data, "     Hello") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{<10}", str);
        success = success && (ZstrCompare(output.data, "Hello     ") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{^10}", str);
        success = success && (ZstrCompare(output.data, "  Hello   ") == 0);
        StrClear(&output);
        Str s = StrInitFromZstr("World");
        StrWriteFmt(&output, "{}", s);
        success = success && (ZstrCompare(output.data, "World") == 0);
        StrDeinit(&s);
        i8 i8_val = -42;
        StrWriteFmt(&output, "{}", i8_val);
        success = success && (ZstrCompare(output.data, "-42") == 0);
        StrClear(&output);
        i16 i16_val = -1234;
        StrWriteFmt(&output, "{}", i16_val);
        success = success && (ZstrCompare(output.data, "-1234") == 0);
        StrClear(&output);
        i32 i32_val = -123456;
        StrWriteFmt(&output, "{}", i32_val);
        success = success && (ZstrCompare(output.data, "-123456") == 0);
        StrClear(&output);
        i64 i64_val = -1234567890LL;
        StrWriteFmt(&output, "{}", i64_val);
        success = success && (ZstrCompare(output.data, "-1234567890") == 0);
        StrClear(&output);
        u8 u8_val = 42;
        StrWriteFmt(&output, "{}", u8_val);
        success = success && (ZstrCompare(output.data, "42") == 0);
        StrClear(&output);
        u16 u16_val = 1234;
        StrWriteFmt(&output, "{}", u16_val);
        success = success && (ZstrCompare(output.data, "1234") == 0);
        StrClear(&output);
        u32 u32_val = 123456;
        StrWriteFmt(&output, "{}", u32_val);
        success = success && (ZstrCompare(output.data, "123456") == 0);
        StrClear(&output);
        u64 u64_val = 1234567890ULL;
        StrWriteFmt(&output, "{}", u64_val);
        success = success && (ZstrCompare(output.data, "1234567890") == 0);
        StrClear(&output);
        i8 i8_max = 127;
        StrWriteFmt(&output, "{}", i8_max);
        success = success && (ZstrCompare(output.data, "127") == 0);
        StrClear(&output);
        i8 i8_min = -128;
        StrWriteFmt(&output, "{}", i8_min);
        success = success && (ZstrCompare(output.data, "-128") == 0);
        StrClear(&output);
        u8 u8_max = 255;
        StrWriteFmt(&output, "{}", u8_max);
        success = success && (ZstrCompare(output.data, "255") == 0);
        StrClear(&output);
        u8 u8_min = 0;
        StrWriteFmt(&output, "{}", u8_min);
        success = success && (ZstrCompare(output.data, "0") == 0);
    
        StrDeinit(&output);
        u32 val = 0xDEADBEEF;
        StrWriteFmt(&output, "{x}", val);
        success = success && (ZstrCompare(output.data, "0xdeadbeef") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{X}", val);
        success = success && (ZstrCompare(output.data, "0xDEADBEEF") == 0);
    
        StrDeinit(&output);
        u8 val = 0xA5; // 10100101 in binary
        StrWriteFmt(&output, "{b}", val);
        success = success && (ZstrCompare(output.data, "0b10100101") == 0);
    
        StrDeinit(&output);
        u16 val = 0777;
        StrWriteFmt(&output, "{o}", val);
        success = success && (ZstrCompare(output.data, "0o777") == 0);
    
        StrDeinit(&output);
        f32 f32_val = 3.14159f;
        StrWriteFmt(&output, "{}", f32_val);
        success = success && (ZstrCompare(output.data, "3.141590") == 0);
        StrClear(&output);
        f64 f64_val = 2.71828;
        StrWriteFmt(&output, "{}", f64_val);
        success = success && (ZstrCompare(output.data, "2.718280") == 0);
    
        StrDeinit(&output);
        // Test different precisions
        StrWriteFmt(&output, "{.2}", val);
        success = success && (ZstrCompare(output.data, "3.14") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{.0}", val);
        success = success && (ZstrCompare(output.data, "3") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{.10}", val);
        success = success && (ZstrCompare(output.data, "3.1415926536") == 0);
    
        StrDeinit(&output);
        f64 pos_inf = INFINITY;
        StrWriteFmt(&output, "{}", pos_inf);
        success = success && (ZstrCompare(output.data, "inf") == 0);
        StrClear(&output);
        f64 neg_inf = -INFINITY;
        StrWriteFmt(&output, "{}", neg_inf);
        success = success && (ZstrCompare(output.data, "-inf") == 0);
        StrClear(&output);
        f64 nan_val = NAN;
        StrWriteFmt(&output, "{}", nan_val);
        success = success && (ZstrCompare(output.data, "nan") == 0);
    
        StrDeinit(&output);
        i32 val = 42;
        StrWriteFmt(&output, "{5}", val);
        success = success && (ZstrCompare(output.data, "   42") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{<5}", val);
        success = success && (ZstrCompare(output.data, "42   ") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{^5}", val);
        success = success && (ZstrCompare(output.data, " 42  ") == 0);
        StrClear(&output);
        const char *str = "abc";
        StrWriteFmt(&output, "{5}", str);
        success = success && (ZstrCompare(output.data, "  abc") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{<5}", str);
        success = success && (ZstrCompare(output.data, "abc  ") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{^5}", str);
        success = success && (ZstrCompare(output.data, " abc ") == 0);
    
        StrDeinit(&output);
    
        StrWriteFmt(&output, "{} {} {}", hello, num, pi);
        success = success && (ZstrCompare(output.data, "Hello 42 3.140000") == 0);
        StrClear(&output);
        // 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);
        const char *mixed_case = "MiXeD CaSe";
        StrWriteFmt(&output, "{c}", mixed_case);
        success = success && (ZstrCompare(output.data, "MiXeD CaSe") == 0);
        StrClear(&output);
        // Test mixed case string with :a (lowercase)
        StrWriteFmt(&output, "{a}", mixed_case);
        success = success && (ZstrCompare(output.data, "mixed case") == 0);
        StrClear(&output);
        // Test mixed case string with :A (uppercase)
        StrWriteFmt(&output, "{A}", mixed_case);
        success = success && (ZstrCompare(output.data, "MIXED CASE") == 0);
        StrClear(&output);
        // Test with :c (preserve case)
        StrWriteFmt(&output, "{c}", s);
        success = success && (ZstrCompare(output.data, "MiXeD CaSe") == 0);
        StrClear(&output);
        // Test with :a (lowercase)
        StrWriteFmt(&output, "{a}", s);
        success = success && (ZstrCompare(output.data, "mixed case") == 0);
        StrClear(&output);
        // Test with :A (uppercase)
        StrWriteFmt(&output, "{A}", s);
        success = success && (ZstrCompare(output.data, "MIXED CASE") == 0);
        StrClear(&output);
        // Test uppercase char with :c (preserve case)
        StrWriteFmt(&output, "{c}", upper_char);
        success = success && (ZstrCompare(output.data, "M") == 0);
        StrClear(&output);
        // Test uppercase char with :a (lowercase)
        StrWriteFmt(&output, "{a}", upper_char);
        success = success && (ZstrCompare(output.data, "m") == 0);
        StrClear(&output);
        // Test lowercase char with :A (uppercase)
        StrWriteFmt(&output, "{A}", lower_char);
        success = success && (ZstrCompare(output.data, "M") == 0);
        StrClear(&output);
        BitVec bv1 = BitVecFromStr("10110");
        StrWriteFmt(&output, "{}", bv1);
        success = success && (ZstrCompare(output.data, "10110") == 0);
        StrClear(&output);
        BitVec bv2 = BitVecFromInteger(0xABCD, 16);
        StrWriteFmt(&output, "{x}", bv2);
        success = success && (ZstrCompare(output.data, "0xabcd") == 0);
        StrClear(&output);
        // Test 4: Uppercase hex formatting
        StrWriteFmt(&output, "{X}", bv2);
        success = success && (ZstrCompare(output.data, "0xABCD") == 0);
        StrClear(&output);
        BitVec bv3 = BitVecFromInteger(0755, 10);
        StrWriteFmt(&output, "{o}", bv3);
        success = success && (ZstrCompare(output.data, "0o755") == 0);
        StrClear(&output);
        // Test 6: Width and alignment
        StrWriteFmt(&output, "{>10}", bv1);
        success = success && (ZstrCompare(output.data, "     10110") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{<10}", bv1);
        success = success && (ZstrCompare(output.data, "10110     ") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{^10}", bv1);
        success = success && (ZstrCompare(output.data, "  10110   ") == 0);
        StrClear(&output);
        BitVec bv_zero = BitVecFromInteger(0, 1);
        StrWriteFmt(&output, "{x}", bv_zero);
        success = success && (ZstrCompare(output.data, "0x0") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{o}", bv_zero);
        success = success && (ZstrCompare(output.data, "0o0") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{}", big_dec);
        success = success && (ZstrCompare(output.data, "123456789012345678901234567890") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{x}", hex_val);
        success = success && (ZstrCompare(output.data, "deadbeefcafebabe1234") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{X}", hex_val);
        success = success && (ZstrCompare(output.data, "DEADBEEFCAFEBABE1234") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{b}", bin_val);
        success = success && (ZstrCompare(output.data, "10100011") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{o}", oct_val);
        success = success && (ZstrCompare(output.data, "755") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{>34}", big_dec);
        success = success && (ZstrCompare(output.data, "    123456789012345678901234567890") == 0);
    
        IntDeinit(&big_dec);
    
        StrWriteFmt(&output, "{}", exact);
        success = success && (ZstrCompare(output.data, "1234567890.012345") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{e}", sci);
        success = success && (ZstrCompare(output.data, "1.234567e+04") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{E}", sci);
        success = success && (ZstrCompare(output.data, "1.234567E+04") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{.3}", short_v);
        success = success && (ZstrCompare(output.data, "1.200") == 0);
        StrClear(&output);
    
        StrWriteFmt(&output, "{>18}", sci);
        success = success && (ZstrCompare(output.data, "          12345.67") == 0);
    
        FloatDeinit(&exact);
    
        // The result should be "H0e1l2l3o4"
        bool success = (ZstrCompare(result.data, "H0e1l2l3o4") == 0);
    
        StrDeinit(&s);
        }
    
        bool success = (ZstrCompare(result.data, "o4l3l2e1H0") == 0);
        WriteFmt("  (Index 0 was processed)\n");
    
        // The result should be "H0e1l2l3o4"
        bool success = (ZstrCompare(result.data, "H0e1l2l3o4") == 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;
        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);
        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);
        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);
        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);
        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);
        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);
        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);
        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);
    
        // Check that the string was reversed
        bool result = (ZstrCompare(s.data, "olleH") == 0);
    
        // Test with an even-length string
    
        // Check that the string was reversed
        result = result && (ZstrCompare(s.data, "dcba") == 0);
    
        // Test with a single-character string
    
        // Check that the string is unchanged
        result = result && (ZstrCompare(s.data, "a") == 0);
    
        // Test with an empty string
        const char *a = *(const char *const *)lhs;
        const char *b = *(const char *const *)rhs;
        return ZstrCompare(a, b);
    }
        result       = result && (MapValueCountForKey(&map, "alpha") == 2);
        stored_value = MapGetFirstPtr(&map, "alpha");
        result       = result && stored_value && (*stored_value != value) && (ZstrCompare(*stored_value, "first") == 0);
        MapForeachValueForKey(&map, "alpha", entry_value) {
            if ((ZstrCompare(entry_value, "first") == 0) || (ZstrCompare(entry_value, "second") == 0)) {
        result       = result && stored_value && (*stored_value != value) && (ZstrCompare(*stored_value, "first") == 0);
        MapForeachValueForKey(&map, "alpha", entry_value) {
            if ((ZstrCompare(entry_value, "first") == 0) || (ZstrCompare(entry_value, "second") == 0)) {
                value_count += 1;
            }
                      (map.policy.should_rehash == MisraMapPolicyQuadratic.should_rehash);
        result = result && (MapValueCountForKey(&map, "red") == 2);
        result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);
        result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        result = result && (MapValueCountForKey(&map, "red") == 2);
        result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);
        result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        MapForeachValueForKey(&map, "red", red_value) {
        result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);
        result = result && MapGetFirstPtr(&map, "yellow") && (ZstrCompare(*MapGetFirstPtr(&map, "yellow"), "banana") == 0);
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        MapForeachValueForKey(&map, "red", red_value) {
            if ((ZstrCompare(red_value, "apple") == 0) || (ZstrCompare(red_value, "cherry") == 0)) {
        result = result && MapGetFirstPtr(&map, "green") && (ZstrCompare(*MapGetFirstPtr(&map, "green"), "pear") == 0);
        MapForeachValueForKey(&map, "red", red_value) {
            if ((ZstrCompare(red_value, "apple") == 0) || (ZstrCompare(red_value, "cherry") == 0)) {
                red_count += 1;
            }
        // 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
        // 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
        // Test StrFindZstr
        const char *found4 = StrFindZstr(&haystack, "World");
        result             = result && (found4 != NULL && ZstrCompare(found4, "World") == 0);
    
        // Test StrFindCstr
        Str s1 = StrInitFromZstr("Hello World");
        StrReplaceZstr(&s1, "World", "Universe", 1);
        bool result = (ZstrCompare(s1.data, "Hello Universe") == 0);
    
        // Test multiple replacements
        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"
        s1 = StrInitFromZstr("Hello World");
        StrReplaceCstr(&s1, "World", 5, "Universe", 8, 1);
        result = result && (ZstrCompare(s1.data, "Hello Universe") == 0);
    
        // Test StrReplace
        Str replace = StrInitFromZstr("Universe");
        StrReplace(&s1, &find, &replace, 1);
        result = result && (ZstrCompare(s1.data, "Hello Universe") == 0);
    
        StrDeinit(&s1);
        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);
        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);
        }
            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);
        }
            char     buffer1[10] = {0};
            memcpy(buffer1, iter1->data, iter1->length);
            result = result && (ZstrCompare(buffer1, "Hello") == 0);
    
            // Check second iterator
            char     buffer2[10] = {0};
            memcpy(buffer2, iter2->data, iter2->length);
            result = result && (ZstrCompare(buffer2, "World") == 0);
    
            // Check third iterator
            char     buffer3[10] = {0};
            memcpy(buffer3, iter3->data, iter3->length);
            result = result && (ZstrCompare(buffer3, "Test") == 0);
        }
        Str  s1       = StrInitFromZstr("  Hello  ");
        Str  stripped = StrLStrip(&s1, NULL);
        bool result   = (ZstrCompare(stripped.data, "Hello  ") == 0);
        StrDeinit(&stripped);
        // Test StrRStrip
        stripped = StrRStrip(&s1, NULL);
        result   = result && (ZstrCompare(stripped.data, "  Hello") == 0);
        StrDeinit(&stripped);
        // Test StrStrip
        stripped = StrStrip(&s1, NULL);
        result   = result && (ZstrCompare(stripped.data, "Hello") == 0);
        StrDeinit(&stripped);
    
        stripped = StrLStrip(&s1, "*");
        result   = result && (ZstrCompare(stripped.data, "Hello***") == 0);
        StrDeinit(&stripped);
    
        stripped = StrRStrip(&s1, "*");
        result   = result && (ZstrCompare(stripped.data, "***Hello") == 0);
        StrDeinit(&stripped);
    
        stripped = StrStrip(&s1, "*");
        result   = result && (ZstrCompare(stripped.data, "Hello") == 0);
        StrDeinit(&stripped);
    
            // 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;
    
        // Check that it's initialized correctly
        bool result = (s.length == strlen(test_str) && ZstrCompare(s.data, test_str) == 0);
    
        StrDeinit(&s);
    
        // Check that dst is initialized correctly
        bool result = (dst.length == src.length && ZstrCompare(dst.data, src.data) == 0);
    
        StrDeinit(&src);
    
        // Check that dst is initialized correctly
        bool result = (dst.length == src.length && ZstrCompare(dst.data, src.data) == 0);
    
        StrDeinit(&src);
    
        // Check that it's initialized correctly
        bool result = (ZstrCompare(s.data, "Hello, World!") == 0);
    
        StrDeinit(&s);
    
            // Check that it works correctly
            if (ZstrCompare(stack_str.data, "Hello, Stack!") != 0) {
                result = false;
            }
    
        // Check that the copy was successful
        bool result = (success && dst.length == src.length && ZstrCompare(dst.data, src.data) == 0);
    
        StrDeinit(&src);
    
        // 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
    
        // Check that the character was removed
        result = result && (ZstrCompare(s.data, "Hel") == 0);
    
        StrDeinit(&s);
    
        // 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
    
        // Check that the character was removed
        result = result && (ZstrCompare(s.data, "llo") == 0);
    
        StrDeinit(&s);
    
        // 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
    
        // Check that the character was removed
        result = result && (ZstrCompare(s.data, "Hlo") == 0);
    
        StrDeinit(&s);
    
        // 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
    
        // Check that the characters were removed
        result = result && (ZstrCompare(s.data, "Hell") == 0);
    
        StrDeinit(&s);
    
        // Check that the character was deleted
        bool result = (ZstrCompare(s.data, "Hell") == 0);
    
        // Delete another character
    
        // Check that the character was deleted
        result = result && (ZstrCompare(s.data, "Hel") == 0);
    
        StrDeinit(&s);
    
        // Check that the character was deleted
        bool result = (ZstrCompare(s.data, "Helo") == 0);
    
        // Delete another character
    
        // Check that the character was deleted
        result = result && (ZstrCompare(s.data, "Hlo") == 0);
    
        StrDeinit(&s);
    
        // Check that the characters were deleted
        bool result = (ZstrCompare(s.data, "Hello") == 0);
    
        // Delete another range
    
        // Check that the characters were deleted
        result = result && (ZstrCompare(s.data, "Heo") == 0);
    
        StrDeinit(&s);
    /// RETURN : 0 if both are equal
    ///
    #define StrCmp(str, ostr) ZstrCompare((str)->data, (ostr)->data)
    
    ///
    /// RETURN : 0 if both are equal
    ///
    #define StrCmpZstr(str, zstr) ZstrCompare((str)->data, (zstr))
    
    //
Last updated on