StrClear
Description
Set the string length to 0 while keeping the allocated capacity, so subsequent writes can reuse the buffer without reallocation. See VecClear for the full SUCCESS/FAILURE contract.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Sys.c:241:
Str *StrError(i32 eno, Str *err_str) {
ValidateStr(err_str);
StrClear(err_str);
StrAppendFmt(err_str, "{} (errno {})", errno_description(eno), eno);
return err_str;- In
ArgParse.c:136:
case ARG_KIND_STR : {
Str *s = (Str *)target;
StrClear(s);
StrPushBackMany(s, value);
return true;- In
Io.c:485:
return false;
}
StrClear(o);
return str_append_fmt(o, fmt, args, argc);
}- In
Str.c:569:
}
StrClear(str);
if (config->use_prefix) {- In
Str.c:672:
}
StrClear(str);
if (isnan_f64(value)) {- In
KvConfig.c:127:
if (StrLen(key) == 0) {
LOG_ERROR("Expected config key");
StrClear(key);
return saved_si;
}- In
KvConfig.c:162:
if (!StrIterPeek(&si, &c)) {
LOG_ERROR("Unexpected end of quoted config value");
StrClear(value);
return saved_si;
}- In
KvConfig.c:191:
LOG_ERROR("Missing closing quote in config value");
StrClear(value);
return saved_si;
}- In
KvConfig.c:239:
if (!StrIterPeek(&si, &c) || (c != '=' && c != ':')) {
LOG_ERROR("Expected '=' or ':' after config key");
StrClear(key);
StrClear(value);
return saved_si;- In
KvConfig.c:240:
LOG_ERROR("Expected '=' or ':' after config key");
StrClear(key);
StrClear(value);
return saved_si;
}- In
KvConfig.c:248:
if (StrIterIndex(&si) == StrIterIndex(&saved_si)) {
StrClear(key);
StrClear(value);
return saved_si;- In
KvConfig.c:249:
if (StrIterIndex(&si) == StrIterIndex(&saved_si)) {
StrClear(key);
StrClear(value);
return saved_si;
}- In
KvConfig.c:262:
} else if (c != '\n') {
LOG_ERROR("Unexpected trailing characters after config value");
StrClear(key);
StrClear(value);
return saved_si;- In
KvConfig.c:263:
LOG_ERROR("Unexpected trailing characters after config value");
StrClear(key);
StrClear(value);
return saved_si;
} else {- In
JSON.c:215:
if (!StrIterPeek(&si, &c)) {
LOG_ERROR("Unexpected end of string.");
StrClear(str);
return saved_si;
}- In
JSON.c:274:
// a well-formed \uXXXX.
LOG_ERROR("Unsupported \\uXXXX escape in JSON string; rejecting.");
StrClear(str);
return saved_si;- In
JSON.c:279:
default :
LOG_ERROR("Invalid JSON object key string.");
StrClear(str);
return saved_si;
}- In
Memory.c:453:
Str s = StrInitFromZstr("hello", &local);
StrClear(&s);
bool result = (StrLen(&s) == 0) && (ZstrCompare(StrBegin(&s), "") == 0);- In
Memory.c:471:
Str s = StrInitFromZstr("x", &local);
StrClear(&s);
bool result = (StrLen(&s) == 0) && (ZstrCompare(StrBegin(&s), "") == 0);- In
Write.c:47:
StrAppendFmt(&output, "");
success = success && (StrLen(&output) == 0);
StrClear(&output);
StrAppendFmt(&output, "Hello, world!");- In
Write.c:51:
StrAppendFmt(&output, "Hello, world!");
success = success && (ZstrCompare(StrBegin(&output), "Hello, world!") == 0);
StrClear(&output);
StrAppendFmt(&output, "{{Hello}}");- In
Write.c:55:
StrAppendFmt(&output, "{{Hello}}");
success = success && (ZstrCompare(StrBegin(&output), "{Hello}") == 0);
StrClear(&output);
StrAppendFmt(&output, "{{{{");- In
Write.c:76:
StrAppendFmt(&output, "{}", str);
success = success && (ZstrCompare(StrBegin(&output), "Hello") == 0);
StrClear(&output);
Zstr empty = "";- In
Write.c:81:
StrAppendFmt(&output, "{}", empty);
success = success && (StrLen(&output) == 0);
StrClear(&output);
StrAppendFmt(&output, "{>10}", str);- In
Write.c:85:
StrAppendFmt(&output, "{>10}", str);
success = success && (ZstrCompare(StrBegin(&output), " Hello") == 0);
StrClear(&output);
StrAppendFmt(&output, "{<10}", str);- In
Write.c:89:
StrAppendFmt(&output, "{<10}", str);
success = success && (ZstrCompare(StrBegin(&output), "Hello ") == 0);
StrClear(&output);
StrAppendFmt(&output, "{^10}", str);- In
Write.c:93:
StrAppendFmt(&output, "{^10}", str);
success = success && (ZstrCompare(StrBegin(&output), " Hello ") == 0);
StrClear(&output);
Str s = StrInitFromZstr("World", &alloc);- In
Write.c:116:
StrAppendFmt(&output, "{}", i8_val);
success = success && (ZstrCompare(StrBegin(&output), "-42") == 0);
StrClear(&output);
i16 i16_val = -1234;- In
Write.c:121:
StrAppendFmt(&output, "{}", i16_val);
success = success && (ZstrCompare(StrBegin(&output), "-1234") == 0);
StrClear(&output);
i32 i32_val = -123456;- In
Write.c:126:
StrAppendFmt(&output, "{}", i32_val);
success = success && (ZstrCompare(StrBegin(&output), "-123456") == 0);
StrClear(&output);
i64 i64_val = -1234567890LL;- In
Write.c:131:
StrAppendFmt(&output, "{}", i64_val);
success = success && (ZstrCompare(StrBegin(&output), "-1234567890") == 0);
StrClear(&output);
u8 u8_val = 42;- In
Write.c:136:
StrAppendFmt(&output, "{}", u8_val);
success = success && (ZstrCompare(StrBegin(&output), "42") == 0);
StrClear(&output);
u16 u16_val = 1234;- In
Write.c:141:
StrAppendFmt(&output, "{}", u16_val);
success = success && (ZstrCompare(StrBegin(&output), "1234") == 0);
StrClear(&output);
u32 u32_val = 123456;- In
Write.c:146:
StrAppendFmt(&output, "{}", u32_val);
success = success && (ZstrCompare(StrBegin(&output), "123456") == 0);
StrClear(&output);
u64 u64_val = 1234567890ULL;- In
Write.c:151:
StrAppendFmt(&output, "{}", u64_val);
success = success && (ZstrCompare(StrBegin(&output), "1234567890") == 0);
StrClear(&output);
i8 i8_max = 127;- In
Write.c:156:
StrAppendFmt(&output, "{}", i8_max);
success = success && (ZstrCompare(StrBegin(&output), "127") == 0);
StrClear(&output);
i8 i8_min = -128;- In
Write.c:161:
StrAppendFmt(&output, "{}", i8_min);
success = success && (ZstrCompare(StrBegin(&output), "-128") == 0);
StrClear(&output);
u8 u8_max = 255;- In
Write.c:166:
StrAppendFmt(&output, "{}", u8_max);
success = success && (ZstrCompare(StrBegin(&output), "255") == 0);
StrClear(&output);
u8 u8_min = 0;- In
Write.c:188:
StrAppendFmt(&output, "{x}", val);
success = success && (ZstrCompare(StrBegin(&output), "0xdeadbeef") == 0);
StrClear(&output);
StrAppendFmt(&output, "{X}", val);- In
Write.c:243:
StrAppendFmt(&output, "{}", f32_val);
success = success && (ZstrCompare(StrBegin(&output), "3.141590") == 0);
StrClear(&output);
f64 f64_val = 2.71828;- In
Write.c:266:
StrAppendFmt(&output, "{.2}", val);
success = success && (ZstrCompare(StrBegin(&output), "3.14") == 0);
StrClear(&output);
StrAppendFmt(&output, "{.0}", val);- In
Write.c:270:
StrAppendFmt(&output, "{.0}", val);
success = success && (ZstrCompare(StrBegin(&output), "3") == 0);
StrClear(&output);
StrAppendFmt(&output, "{.10}", val);- In
Write.c:291:
StrAppendFmt(&output, "{}", pos_inf);
success = success && (ZstrCompare(StrBegin(&output), "inf") == 0);
StrClear(&output);
f64 neg_inf = -F64_INFINITY;- In
Write.c:296:
StrAppendFmt(&output, "{}", neg_inf);
success = success && (ZstrCompare(StrBegin(&output), "-inf") == 0);
StrClear(&output);
f64 nan_val = F64_NAN;- In
Write.c:318:
StrAppendFmt(&output, "{5}", val);
success = success && (ZstrCompare(StrBegin(&output), " 42") == 0);
StrClear(&output);
StrAppendFmt(&output, "{<5}", val);- In
Write.c:322:
StrAppendFmt(&output, "{<5}", val);
success = success && (ZstrCompare(StrBegin(&output), "42 ") == 0);
StrClear(&output);
StrAppendFmt(&output, "{^5}", val);- In
Write.c:326:
StrAppendFmt(&output, "{^5}", val);
success = success && (ZstrCompare(StrBegin(&output), " 42 ") == 0);
StrClear(&output);
Zstr str = "abc";- In
Write.c:331:
StrAppendFmt(&output, "{5}", str);
success = success && (ZstrCompare(StrBegin(&output), " abc") == 0);
StrClear(&output);
StrAppendFmt(&output, "{<5}", str);- In
Write.c:335:
StrAppendFmt(&output, "{<5}", str);
success = success && (ZstrCompare(StrBegin(&output), "abc ") == 0);
StrClear(&output);
StrAppendFmt(&output, "{^5}", str);- In
Write.c:359:
StrAppendFmt(&output, "{} {} {}", hello, num, pi);
success = success && (ZstrCompare(StrBegin(&output), "Hello 42 3.140000") == 0);
StrClear(&output);
StrAppendFmt(&output, "{} {} {}", pi, hello, num);- In
Write.c:380:
StrAppendFmt(&output, "{c}", mixed_case);
success = success && (ZstrCompare(StrBegin(&output), "MiXeD CaSe") == 0);
StrClear(&output);
StrAppendFmt(&output, "{a}", mixed_case);- In
Write.c:384:
StrAppendFmt(&output, "{a}", mixed_case);
success = success && (ZstrCompare(StrBegin(&output), "mixed case") == 0);
StrClear(&output);
StrAppendFmt(&output, "{A}", mixed_case);- In
Write.c:388:
StrAppendFmt(&output, "{A}", mixed_case);
success = success && (ZstrCompare(StrBegin(&output), "MIXED CASE") == 0);
StrClear(&output);
Str s = StrInitFromZstr("MiXeD CaSe", &alloc);- In
Write.c:394:
StrAppendFmt(&output, "{c}", s);
success = success && (ZstrCompare(StrBegin(&output), "MiXeD CaSe") == 0);
StrClear(&output);
StrAppendFmt(&output, "{a}", s);- In
Write.c:398:
StrAppendFmt(&output, "{a}", s);
success = success && (ZstrCompare(StrBegin(&output), "mixed case") == 0);
StrClear(&output);
StrAppendFmt(&output, "{A}", s);- In
Write.c:402:
StrAppendFmt(&output, "{A}", s);
success = success && (ZstrCompare(StrBegin(&output), "MIXED CASE") == 0);
StrClear(&output);
u8 upper_char = 'M';- In
Write.c:409:
StrAppendFmt(&output, "{c}", upper_char);
success = success && (ZstrCompare(StrBegin(&output), "M") == 0);
StrClear(&output);
StrAppendFmt(&output, "{a}", upper_char);- In
Write.c:413:
StrAppendFmt(&output, "{a}", upper_char);
success = success && (ZstrCompare(StrBegin(&output), "m") == 0);
StrClear(&output);
StrAppendFmt(&output, "{A}", lower_char);- In
Write.c:417:
StrAppendFmt(&output, "{A}", lower_char);
success = success && (ZstrCompare(StrBegin(&output), "M") == 0);
StrClear(&output);
u16 u16_value = ('A' << 8) | 'B'; // big-endian "AB"
- In
Write.c:423:
StrAppendFmt(&output, "{c}", u16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'A' && StrBegin(&output)[1] == 'B');
StrClear(&output);
StrAppendFmt(&output, "{a}", u16_value);- In
Write.c:427:
StrAppendFmt(&output, "{a}", u16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'a' && StrBegin(&output)[1] == 'b');
StrClear(&output);
StrAppendFmt(&output, "{A}", u16_value);- In
Write.c:431:
StrAppendFmt(&output, "{A}", u16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'A' && StrBegin(&output)[1] == 'B');
StrClear(&output);
i16 i16_value = ('C' << 8) | 'd'; // big-endian "Cd"
- In
Write.c:437:
StrAppendFmt(&output, "{c}", i16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'C' && StrBegin(&output)[1] == 'd');
StrClear(&output);
StrAppendFmt(&output, "{a}", i16_value);- In
Write.c:441:
StrAppendFmt(&output, "{a}", i16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'c' && StrBegin(&output)[1] == 'd');
StrClear(&output);
StrAppendFmt(&output, "{A}", i16_value);- In
Write.c:445:
StrAppendFmt(&output, "{A}", i16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'C' && StrBegin(&output)[1] == 'D');
StrClear(&output);
u32 u32_value = ('E' << 24) | ('f' << 16) | ('G' << 8) | 'h'; // big-endian "EfGh"
- In
Write.c:452:
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'E' && StrBegin(&output)[1] == 'f' &&
StrBegin(&output)[2] == 'G' && StrBegin(&output)[3] == 'h');
StrClear(&output);
StrAppendFmt(&output, "{a}", u32_value);- In
Write.c:457:
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'e' && StrBegin(&output)[1] == 'f' &&
StrBegin(&output)[2] == 'g' && StrBegin(&output)[3] == 'h');
StrClear(&output);
StrAppendFmt(&output, "{A}", u32_value);- In
Write.c:462:
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'E' && StrBegin(&output)[1] == 'F' &&
StrBegin(&output)[2] == 'G' && StrBegin(&output)[3] == 'H');
StrClear(&output);
i32 i32_value = ('I' << 24) | ('j' << 16) | ('K' << 8) | 'l'; // big-endian "IjKl"
- In
Write.c:469:
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'I' && StrBegin(&output)[1] == 'j' &&
StrBegin(&output)[2] == 'K' && StrBegin(&output)[3] == 'l');
StrClear(&output);
StrAppendFmt(&output, "{a}", i32_value);- In
Write.c:474:
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'i' && StrBegin(&output)[1] == 'j' &&
StrBegin(&output)[2] == 'k' && StrBegin(&output)[3] == 'l');
StrClear(&output);
StrAppendFmt(&output, "{A}", i32_value);- In
Write.c:479:
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'I' && StrBegin(&output)[1] == 'J' &&
StrBegin(&output)[2] == 'K' && StrBegin(&output)[3] == 'L');
StrClear(&output);
u64 u64_value = ((u64)'M' << 56) | ((u64)'n' << 48) | ((u64)'O' << 40) | ((u64)'p' << 32) | ('Q' << 24) |- In
Write.c:488:
StrBegin(&output)[2] == 'O' && StrBegin(&output)[3] == 'p' && StrBegin(&output)[4] == 'Q' &&
StrBegin(&output)[5] == 'r' && StrBegin(&output)[6] == 'S' && StrBegin(&output)[7] == 't');
StrClear(&output);
StrAppendFmt(&output, "{a}", u64_value);- In
Write.c:494:
StrBegin(&output)[2] == 'o' && StrBegin(&output)[3] == 'p' && StrBegin(&output)[4] == 'q' &&
StrBegin(&output)[5] == 'r' && StrBegin(&output)[6] == 's' && StrBegin(&output)[7] == 't');
StrClear(&output);
StrAppendFmt(&output, "{A}", u64_value);- In
Write.c:500:
StrBegin(&output)[2] == 'O' && StrBegin(&output)[3] == 'P' && StrBegin(&output)[4] == 'Q' &&
StrBegin(&output)[5] == 'R' && StrBegin(&output)[6] == 'S' && StrBegin(&output)[7] == 'T');
StrClear(&output);
i64 i64_value = ((i64)'U' << 56) | ((i64)'v' << 48) | ((i64)'W' << 40) | ((i64)'x' << 32) | ('Y' << 24) |- In
Write.c:509:
StrBegin(&output)[2] == 'W' && StrBegin(&output)[3] == 'x' && StrBegin(&output)[4] == 'Y' &&
StrBegin(&output)[5] == 'z' && StrBegin(&output)[6] == '1' && StrBegin(&output)[7] == '2');
StrClear(&output);
StrAppendFmt(&output, "{a}", i64_value);- In
Write.c:515:
StrBegin(&output)[2] == 'w' && StrBegin(&output)[3] == 'x' && StrBegin(&output)[4] == 'y' &&
StrBegin(&output)[5] == 'z' && StrBegin(&output)[6] == '1' && StrBegin(&output)[7] == '2');
StrClear(&output);
StrAppendFmt(&output, "{A}", i64_value);- In
Write.c:540:
StrAppendFmt(&output, "{}", bv1);
success = success && (ZstrCompare(StrBegin(&output), "10110") == 0);
StrClear(&output);
BitVec bv_empty = BitVecInit(alloc_base);- In
Write.c:545:
StrAppendFmt(&output, "{}", bv_empty);
success = success && (StrLen(&output) == 0);
StrClear(&output);
BitVec bv2 = BitVecFromInteger(0xABCD, 16, alloc_base);- In
Write.c:550:
StrAppendFmt(&output, "{x}", bv2);
success = success && (ZstrCompare(StrBegin(&output), "0xabcd") == 0);
StrClear(&output);
StrAppendFmt(&output, "{X}", bv2);- In
Write.c:554:
StrAppendFmt(&output, "{X}", bv2);
success = success && (ZstrCompare(StrBegin(&output), "0xABCD") == 0);
StrClear(&output);
BitVec bv3 = BitVecFromInteger(0755, 10, alloc_base);- In
Write.c:559:
StrAppendFmt(&output, "{o}", bv3);
success = success && (ZstrCompare(StrBegin(&output), "0o755") == 0);
StrClear(&output);
StrAppendFmt(&output, "{>10}", bv1);- In
Write.c:563:
StrAppendFmt(&output, "{>10}", bv1);
success = success && (ZstrCompare(StrBegin(&output), " 10110") == 0);
StrClear(&output);
StrAppendFmt(&output, "{<10}", bv1);- In
Write.c:567:
StrAppendFmt(&output, "{<10}", bv1);
success = success && (ZstrCompare(StrBegin(&output), "10110 ") == 0);
StrClear(&output);
StrAppendFmt(&output, "{^10}", bv1);- In
Write.c:571:
StrAppendFmt(&output, "{^10}", bv1);
success = success && (ZstrCompare(StrBegin(&output), " 10110 ") == 0);
StrClear(&output);
BitVec bv_zero = BitVecFromInteger(0, 1, alloc_base);- In
Write.c:576:
StrAppendFmt(&output, "{x}", bv_zero);
success = success && (ZstrCompare(StrBegin(&output), "0x0") == 0);
StrClear(&output);
StrAppendFmt(&output, "{o}", bv_zero);- In
Write.c:580:
StrAppendFmt(&output, "{o}", bv_zero);
success = success && (ZstrCompare(StrBegin(&output), "0o0") == 0);
StrClear(&output);
BitVecDeinit(&bv1);- In
Write.c:608:
StrAppendFmt(&output, "{}", big_dec);
success = success && (ZstrCompare(StrBegin(&output), "123456789012345678901234567890") == 0);
StrClear(&output);
StrAppendFmt(&output, "{x}", hex_val);- In
Write.c:612:
StrAppendFmt(&output, "{x}", hex_val);
success = success && (ZstrCompare(StrBegin(&output), "deadbeefcafebabe1234") == 0);
StrClear(&output);
StrAppendFmt(&output, "{X}", hex_val);- In
Write.c:616:
StrAppendFmt(&output, "{X}", hex_val);
success = success && (ZstrCompare(StrBegin(&output), "DEADBEEFCAFEBABE1234") == 0);
StrClear(&output);
StrAppendFmt(&output, "{b}", bin_val);- In
Write.c:620:
StrAppendFmt(&output, "{b}", bin_val);
success = success && (ZstrCompare(StrBegin(&output), "10100011") == 0);
StrClear(&output);
StrAppendFmt(&output, "{o}", oct_val);- In
Write.c:624:
StrAppendFmt(&output, "{o}", oct_val);
success = success && (ZstrCompare(StrBegin(&output), "755") == 0);
StrClear(&output);
StrAppendFmt(&output, "{>34}", big_dec);- In
Write.c:652:
StrAppendFmt(&output, "{}", exact);
success = success && (ZstrCompare(StrBegin(&output), "1234567890.012345") == 0);
StrClear(&output);
StrAppendFmt(&output, "{e}", sci);- In
Write.c:656:
StrAppendFmt(&output, "{e}", sci);
success = success && (ZstrCompare(StrBegin(&output), "1.234567e+04") == 0);
StrClear(&output);
StrAppendFmt(&output, "{E}", sci);- In
Write.c:660:
StrAppendFmt(&output, "{E}", sci);
success = success && (ZstrCompare(StrBegin(&output), "1.234567E+04") == 0);
StrClear(&output);
StrAppendFmt(&output, "{.3}", short_v);- In
Write.c:664:
StrAppendFmt(&output, "{.3}", short_v);
success = success && (ZstrCompare(StrBegin(&output), "1.200") == 0);
StrClear(&output);
StrAppendFmt(&output, "{>18}", sci);- In
Write.c:750:
StrAppendFmt(&out, "{c}", esc);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1b") == 0);
StrClear(&out);
// 0x07 (BEL) -> "\x07".
- In
Write.c:756:
StrAppendFmt(&out, "{c}", bel);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x07") == 0);
StrClear(&out);
// 0xFF with caps spec -> uppercase hex digits "\xFF".
- In
Write.c:762:
StrAppendFmt(&out, "{A}", hi);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xFF") == 0);
StrClear(&out);
// 0xAB lowercase by default for {c}.
- In
Write.c:890:
}
// Same, but the trailing literal is an escaped '{'.
StrClear((Str *)&b);
ok = ok && BufWriteFmt(&b, "{>1r}{{", (u8)'Q');
{- In
Write.c:915:
DateTime utc = DateTimeFromUnixNs(base, 0);
StrClear(&s);
StrAppendFmt(&s, "{}", utc);
ok = ok && ZstrCompare(StrBegin(&s), "2021-01-01T00:00:00Z") == 0;- In
Write.c:920:
DateTime ist = DateTimeFromUnixNs(base, 19800); // +05:30
StrClear(&s);
StrAppendFmt(&s, "{}", ist);
ok = ok && ZstrCompare(StrBegin(&s), "2021-01-01T05:30:00+05:30") == 0;- In
Write.c:925:
DateTime neg = DateTimeFromUnixNs(base, -34200); // -09:30
StrClear(&s);
StrAppendFmt(&s, "{}", neg);
ok = ok && ZstrCompare(StrBegin(&s), "2020-12-31T14:30:00-09:30") == 0;- In
Write.c:930:
DateTime frac = DateTimeFromUnixNs(base + 123456789ull, 0);
StrClear(&s);
StrAppendFmt(&s, "{}", frac);
ok = ok && ZstrCompare(StrBegin(&s), "2021-01-01T00:00:00.123456789Z") == 0;- In
Write.c:2068:
StrAppendFmt(&output, "{e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.234567e+04") == 0);
StrClear(&output);
StrAppendFmt(&output, "{E}", v);- In
Write.c:3459:
StrAppendFmt(&out, "{5}", v); // " 7"
ok = ok && (ZstrCompare(StrBegin(&out), " 7") == 0);
StrClear(&out);
// Left-align variant so a dropped pad is unambiguous.
- In
Write.c:3969:
StrAppendFmt(&out, "{c}", src);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1a") == 0);
StrClear(&out);
StrClear(&src);- In
Write.c:3970:
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1a") == 0);
StrClear(&out);
StrClear(&src);
// 0xA1: low nibble 0x01 (<10 -> '1') -- pins the low digit on the <10 side
- In
Write.c:4003:
StrAppendFmt(&out, "{.5}", f);
ok = ok && (ZstrCompare(StrBegin(&out), "1.20000") == 0);
StrClear(&out);
Float g = FloatFromStr("3.14", alloc_base);- In
Write.c:4033:
StrAppendFmt(&out, "{03}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "255") == 0);
StrClear(&out);
// Sanity: width one wider really does pad (guards against a no-op pad).
- In
Write.c:4059:
StrAppendFmt(&out, "{3}", s);
ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);
// Left/center at the exact boundary likewise add nothing.
- In
Write.c:4064:
StrAppendFmt(&out, "{<3}", s);
ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);
StrAppendFmt(&out, "{^3}", s);- In
Write.c:4068:
StrAppendFmt(&out, "{^3}", s);
ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);
// Sanity: width 4 does pad (one space, right-aligned default).
- In
Write.c:4169:
StrAppendFmt(&out, "{}", v); // default precision 6
ok = ok && (ZstrCompare(StrBegin(&out), "3.140000") == 0);
StrClear(&out);
StrAppendFmt(&out, "{.2}", v); // explicit precision 2
- In
Write.c:4824:
StrAppendFmt(&out, "{4}", s);
bool ok = (ZstrCompare(StrBegin(&out), " ab") == 0);
StrClear(&out);
// Two-digit width exercises the width loop (151) more than once.
StrAppendFmt(&out, "{12}", s);- In
Write.c:4843:
StrAppendFmt(&out, "{.2}", v);
bool ok = (ZstrCompare(StrBegin(&out), "3.14") == 0);
StrClear(&out);
// multi-digit precision exercises the precision loop body (165).
StrAppendFmt(&out, "{.4}", v);- In
Write.c:4895:
StrAppendFmt(&out, "{03}", v);
bool ok = (ZstrCompare(StrBegin(&out), "123") == 0);
StrClear(&out);
StrAppendFmt(&out, "{05}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "00123") == 0);- In
Write.c:4911:
StrAppendFmt(&out, "{3}", s);
bool ok = (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);
StrAppendFmt(&out, "{5}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " abc") == 0);- In
Write.c:5112:
StrAppendFmt(&out, "{}", s); // width 0 default
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
StrClear(&out);
StrAppendFmt(&out, "{5}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " hi") == 0);- In
Write.c:5127:
StrAppendFmt(&out, "{}", s);
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
StrClear(&out);
StrAppendFmt(&out, "{5}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " hi") == 0);- In
Write.c:5162:
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "42") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 42") == 0);- In
Write.c:5176:
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "-42") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " -42") == 0);- In
Write.c:5208:
StrAppendFmt(&out, "{}", ninf);
bool ok = (ZstrCompare(StrBegin(&out), "-inf") == 0);
StrClear(&out);
f64 pinf = F64_INFINITY;
StrAppendFmt(&out, "{}", pinf);- In
Write.c:5227:
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.500000") == 0);
StrClear(&out);
// explicit precision 2 to contrast.
StrAppendFmt(&out, "{.2}", v);- In
Write.c:5252:
StrAppendFmt(&out, "{.1}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6.1}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 1.5") == 0);- In
Write.c:5269:
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.234567e+04") == 0);
StrClear(&out);
Float w = FloatFromStr("0.001234", ab);
StrAppendFmt(&out, "{e}", w);- In
Write.c:5334:
StrAppendFmt(&out, "{.2}", v);
bool ok = (ZstrCompare(StrBegin(&out), "3.14") == 0);
StrClear(&out);
// precision longer than frac pads with zeros.
StrAppendFmt(&out, "{.8}", v);- In
Write.c:5377:
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 1.5") == 0);- In
Write.c:5423:
StrAppendFmt(&out, "{}", bv);
bool ok = (ZstrCompare(StrBegin(&out), "101") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", bv);
ok = ok && (ZstrCompare(StrBegin(&out), " 101") == 0);- In
Write.c:5452:
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "42") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 42") == 0);- In
Read.c:358:
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);
StrClear(&s);
z = "\"Hello, World!\"";- In
Read.c:405:
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);
StrClear(&name);
f64 val = 0.0;- In
Read.c:1975:
StrAppendFmt(&out, "{c}", lo_letter);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1b") == 0);
StrClear(&out);
Zstr hi_letter = "\xb1";- In
Memory.c:129:
// Test StrClear function
bool test_str_clear(void) {
WriteFmt("Testing StrClear\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Memory.c:139:
// Clear the string
StrClear(&s);
// Length should now be 0, but capacity should remain
- In
Convert.c:46:
// Test hexadecimal conversion (lowercase)
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 0xABCD, &config);- In
Convert.c:55:
// Test hexadecimal conversion (uppercase)
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = true, .use_prefix = true};
StrFromU64(&s, 0xABCD, &config);- In
Convert.c:64:
// Test binary conversion
StrClear(&s);
config = (StrIntFormat) {.base = 2, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 42, &config);- In
Convert.c:73:
// Test octal conversion
StrClear(&s);
config = (StrIntFormat) {.base = 8, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 42, &config);- In
Convert.c:82:
// Test zero
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromU64(&s, 0, &config);- In
Convert.c:112:
// Test negative decimal conversion (only decimal supports negative sign)
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, -12345, &config);- In
Convert.c:121:
// Test hexadecimal conversion of negative number (negative non-decimal treated as unsigned)
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = false, .use_prefix = true};
StrFromI64(&s, -0xABCD, &config);- In
Convert.c:132:
// Test zero
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, 0, &config);- In
Convert.c:141:
// Test binary conversion
StrClear(&s);
config = (StrIntFormat) {.base = 2, .uppercase = false, .use_prefix = true};
StrFromI64(&s, 42, &config);- In
Convert.c:171:
// Test fractional conversion
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 123.456, &config);- In
Convert.c:180:
// Test negative number
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, -123.456, &config);- In
Convert.c:186:
// Test scientific notation (forced)
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = false};
StrFromF64(&s, 123.456, &config);- In
Convert.c:192:
// Test scientific notation (uppercase)
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = true};
StrFromF64(&s, 123.456, &config);- In
Convert.c:198:
// Test very small number (auto scientific notation)
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 0.0000123, &config);- In
Convert.c:204:
// Test very large number (auto scientific notation)
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1234567890123.0, &config);- In
Convert.c:210:
// Test zero
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 0.0, &config);- In
Convert.c:216:
// Test infinity
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, F64_INFINITY, &config);- In
Convert.c:222:
// Test negative infinity
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, -F64_INFINITY, &config);- In
Convert.c:228:
// Test NaN
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, F64_NAN, &config);- In
Convert.c:445:
// Test hex round-trip
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = false, .use_prefix = true};
StrFromU64(&s, u64_values[i], &config);- In
Convert.c:528:
// Test minimum i64 (avoid INT64_MIN due to negation UB)
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, INT64_MIN + 1, &config);- In
Convert.c:536:
// Test very small floating point
StrClear(&s);
StrFloatFormat fconfig = {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1e-300, &fconfig);- In
Convert.c:544:
// Test very large floating point
StrClear(&s);
fconfig = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1e300, &fconfig);- In
Convert.c:621:
// Test uppercase E
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = true};
StrFromF64(&s, sci_values[i], &config);- In
Access.c:35:
result = result && !StrEmpty(&s);
StrClear(&s);
result = result && (StrLen(&s) == 0);
result = result && StrEmpty(&s);
Last updated on