StrClear
- Macro
- October 8, 2025
Table of Contents
StrClear
StrClearDescription
Set string length to 0.
Parameters
| Name | Direction | Description |
|---|---|---|
vec | in,out | Str to be cleared. |
Failure
NULL
Usage example (Cross-references)
- In
JSON.c:200:
if (!StrIterRemainingLength(&si)) {
LOG_ERROR("Unexpected end of string.");
StrClear(str);
return saved_si;
}
- In
JSON.c:257:
default :
LOG_ERROR("Invalid JSON object key string.");
StrClear(str);
return saved_si;
}
- In
Str.c:22:
ValidateStr(str);
StrClear(str);
va_list args;
- In
Str.c:341:
}
StrClear(str);
// Add prefix if requested
- In
Str.c:422:
}
StrClear(str);
// Handle special cases
- In
Str.Convert.c:42:
// Test hexadecimal conversion (lowercase)
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 0xABCD, &config);
- In
Str.Convert.c:51:
// Test hexadecimal conversion (uppercase)
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = true, .use_prefix = true};
StrFromU64(&s, 0xABCD, &config);
- In
Str.Convert.c:60:
// Test binary conversion
StrClear(&s);
config = (StrIntFormat) {.base = 2, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 42, &config);
- In
Str.Convert.c:69:
// Test octal conversion
StrClear(&s);
config = (StrIntFormat) {.base = 8, .uppercase = false, .use_prefix = true};
StrFromU64(&s, 42, &config);
- In
Str.Convert.c:78:
// Test zero
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromU64(&s, 0, &config);
// Test negative decimal conversion (only decimal supports negative sign)
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, -12345, &config);
// 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);
// Test zero
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, 0, &config);
// Test binary conversion
StrClear(&s);
config = (StrIntFormat) {.base = 2, .uppercase = false, .use_prefix = true};
StrFromI64(&s, 42, &config);
// Test fractional conversion
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 123.456, &config);
// Test negative number
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, -123.456, &config);
// Test scientific notation (forced)
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = false};
StrFromF64(&s, 123.456, &config);
// Test scientific notation (uppercase)
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = true};
StrFromF64(&s, 123.456, &config);
// Test very small number (auto scientific notation)
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 0.0000123, &config);
// Test very large number (auto scientific notation)
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1234567890123.0, &config);
// Test zero
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, 0.0, &config);
// Test infinity
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, INFINITY, &config);
// Test negative infinity
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, -INFINITY, &config);
// Test NaN
StrClear(&s);
config = (StrFloatFormat) {.precision = 2, .force_sci = false, .uppercase = false};
StrFromF64(&s, NAN, &config);
// Test hex round-trip
StrClear(&s);
config = (StrIntFormat) {.base = 16, .uppercase = false, .use_prefix = true};
StrFromU64(&s, u64_values[i], &config);
// Test minimum i64 (avoid INT64_MIN due to negation UB)
StrClear(&s);
config = (StrIntFormat) {.base = 10, .uppercase = false};
StrFromI64(&s, INT64_MIN + 1, &config);
// Test very small floating point
StrClear(&s);
StrFloatFormat fconfig = {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1e-300, &fconfig);
// Test very large floating point
StrClear(&s);
fconfig = (StrFloatFormat) {.precision = 3, .force_sci = false, .uppercase = false};
StrFromF64(&s, 1e300, &fconfig);
// Test uppercase E
StrClear(&s);
config = (StrFloatFormat) {.precision = 3, .force_sci = true, .uppercase = true};
StrFromF64(&s, sci_values[i], &config);
- In
Io.Read.c:347:
success = success && (StrCmp(&s, &expected) == 0);
StrDeinit(&expected);
StrClear(&s);
// Test quoted string reading
- In
Io.Read.c:380:
success = success && (StrCmp(&name, &expected) == 0);
StrDeinit(&expected);
StrClear(&name);
// Test with different order
- In
Io.Write.c:39:
StrWriteFmt(&output, "");
success = success && (output.length == 0);
StrClear(&output);
// Test literal text
- In
Io.Write.c:44:
StrWriteFmt(&output, "Hello, world!");
success = success && (ZstrCompare(output.data, "Hello, world!") == 0);
StrClear(&output);
// Test escaped braces
- In
Io.Write.c:49:
StrWriteFmt(&output, "{{Hello}}");
success = success && (ZstrCompare(output.data, "{Hello}") == 0);
StrClear(&output);
// Test double escaped braces
- In
Io.Write.c:70:
StrWriteFmt(&output, "{}", str);
success = success && (ZstrCompare(output.data, "Hello") == 0);
StrClear(&output);
// Test empty string
- In
Io.Write.c:76:
StrWriteFmt(&output, "{}", empty);
success = success && (output.length == 0);
StrClear(&output);
// Test string with width and alignment
- In
Io.Write.c:81:
StrWriteFmt(&output, "{>10}", str);
success = success && (ZstrCompare(output.data, " Hello") == 0);
StrClear(&output);
StrWriteFmt(&output, "{<10}", str);
- In
Io.Write.c:85:
StrWriteFmt(&output, "{<10}", str);
success = success && (ZstrCompare(output.data, "Hello ") == 0);
StrClear(&output);
StrWriteFmt(&output, "{^10}", str);
- In
Io.Write.c:89:
StrWriteFmt(&output, "{^10}", str);
success = success && (ZstrCompare(output.data, " Hello ") == 0);
StrClear(&output);
// Test Str object
- In
Io.Write.c:112:
StrWriteFmt(&output, "{}", i8_val);
success = success && (ZstrCompare(output.data, "-42") == 0);
StrClear(&output);
i16 i16_val = -1234;
- In
Io.Write.c:117:
StrWriteFmt(&output, "{}", i16_val);
success = success && (ZstrCompare(output.data, "-1234") == 0);
StrClear(&output);
i32 i32_val = -123456;
- In
Io.Write.c:122:
StrWriteFmt(&output, "{}", i32_val);
success = success && (ZstrCompare(output.data, "-123456") == 0);
StrClear(&output);
i64 i64_val = -1234567890LL;
- In
Io.Write.c:127:
StrWriteFmt(&output, "{}", i64_val);
success = success && (ZstrCompare(output.data, "-1234567890") == 0);
StrClear(&output);
// Test unsigned integers
- In
Io.Write.c:133:
StrWriteFmt(&output, "{}", u8_val);
success = success && (ZstrCompare(output.data, "42") == 0);
StrClear(&output);
u16 u16_val = 1234;
- In
Io.Write.c:138:
StrWriteFmt(&output, "{}", u16_val);
success = success && (ZstrCompare(output.data, "1234") == 0);
StrClear(&output);
u32 u32_val = 123456;
- In
Io.Write.c:143:
StrWriteFmt(&output, "{}", u32_val);
success = success && (ZstrCompare(output.data, "123456") == 0);
StrClear(&output);
u64 u64_val = 1234567890ULL;
- In
Io.Write.c:148:
StrWriteFmt(&output, "{}", u64_val);
success = success && (ZstrCompare(output.data, "1234567890") == 0);
StrClear(&output);
// Test edge cases
- In
Io.Write.c:154:
StrWriteFmt(&output, "{}", i8_max);
success = success && (ZstrCompare(output.data, "127") == 0);
StrClear(&output);
i8 i8_min = -128;
- In
Io.Write.c:159:
StrWriteFmt(&output, "{}", i8_min);
success = success && (ZstrCompare(output.data, "-128") == 0);
StrClear(&output);
u8 u8_max = 255;
- In
Io.Write.c:164:
StrWriteFmt(&output, "{}", u8_max);
success = success && (ZstrCompare(output.data, "255") == 0);
StrClear(&output);
u8 u8_min = 0;
- In
Io.Write.c:184:
StrWriteFmt(&output, "{x}", val);
success = success && (ZstrCompare(output.data, "0xdeadbeef") == 0);
StrClear(&output);
StrWriteFmt(&output, "{X}", val);
- In
Io.Write.c:233:
StrWriteFmt(&output, "{}", f32_val);
success = success && (ZstrCompare(output.data, "3.141590") == 0);
StrClear(&output);
f64 f64_val = 2.71828;
- In
Io.Write.c:255:
StrWriteFmt(&output, "{.2}", val);
success = success && (ZstrCompare(output.data, "3.14") == 0);
StrClear(&output);
StrWriteFmt(&output, "{.0}", val);
- In
Io.Write.c:259:
StrWriteFmt(&output, "{.0}", val);
success = success && (ZstrCompare(output.data, "3") == 0);
StrClear(&output);
StrWriteFmt(&output, "{.10}", val);
- In
Io.Write.c:279:
StrWriteFmt(&output, "{}", pos_inf);
success = success && (ZstrCompare(output.data, "inf") == 0);
StrClear(&output);
f64 neg_inf = -INFINITY;
- In
Io.Write.c:284:
StrWriteFmt(&output, "{}", neg_inf);
success = success && (ZstrCompare(output.data, "-inf") == 0);
StrClear(&output);
// Test NaN
- In
Io.Write.c:306:
StrWriteFmt(&output, "{5}", val);
success = success && (ZstrCompare(output.data, " 42") == 0);
StrClear(&output);
StrWriteFmt(&output, "{<5}", val);
- In
Io.Write.c:310:
StrWriteFmt(&output, "{<5}", val);
success = success && (ZstrCompare(output.data, "42 ") == 0);
StrClear(&output);
StrWriteFmt(&output, "{^5}", val);
- In
Io.Write.c:314:
StrWriteFmt(&output, "{^5}", val);
success = success && (ZstrCompare(output.data, " 42 ") == 0);
StrClear(&output);
// Test with strings
- In
Io.Write.c:320:
StrWriteFmt(&output, "{5}", str);
success = success && (ZstrCompare(output.data, " abc") == 0);
StrClear(&output);
StrWriteFmt(&output, "{<5}", str);
- In
Io.Write.c:324:
StrWriteFmt(&output, "{<5}", str);
success = success && (ZstrCompare(output.data, "abc ") == 0);
StrClear(&output);
StrWriteFmt(&output, "{^5}", str);
- In
Io.Write.c:346:
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
- In
Io.Write.c:367:
StrWriteFmt(&output, "{c}", mixed_case);
success = success && (ZstrCompare(output.data, "MiXeD CaSe") == 0);
StrClear(&output);
// Test mixed case string with :a (lowercase)
- In
Io.Write.c:372:
StrWriteFmt(&output, "{a}", mixed_case);
success = success && (ZstrCompare(output.data, "mixed case") == 0);
StrClear(&output);
// Test mixed case string with :A (uppercase)
- In
Io.Write.c:377:
StrWriteFmt(&output, "{A}", mixed_case);
success = success && (ZstrCompare(output.data, "MIXED CASE") == 0);
StrClear(&output);
// Test with Str object
- In
Io.Write.c:385:
StrWriteFmt(&output, "{c}", s);
success = success && (ZstrCompare(output.data, "MiXeD CaSe") == 0);
StrClear(&output);
// Test with :a (lowercase)
- In
Io.Write.c:390:
StrWriteFmt(&output, "{a}", s);
success = success && (ZstrCompare(output.data, "mixed case") == 0);
StrClear(&output);
// Test with :A (uppercase)
- In
Io.Write.c:395:
StrWriteFmt(&output, "{A}", s);
success = success && (ZstrCompare(output.data, "MIXED CASE") == 0);
StrClear(&output);
// Test with character values (u8)
- In
Io.Write.c:404:
StrWriteFmt(&output, "{c}", upper_char);
success = success && (ZstrCompare(output.data, "M") == 0);
StrClear(&output);
// Test uppercase char with :a (lowercase)
- In
Io.Write.c:409:
StrWriteFmt(&output, "{a}", upper_char);
success = success && (ZstrCompare(output.data, "m") == 0);
StrClear(&output);
// Test lowercase char with :A (uppercase)
- In
Io.Write.c:414:
StrWriteFmt(&output, "{A}", lower_char);
success = success && (ZstrCompare(output.data, "M") == 0);
StrClear(&output);
// Test with u16 (containing ASCII values)
- In
Io.Write.c:422:
StrWriteFmt(&output, "{c}", u16_value);
success = success && (output.length == 2 && output.data[0] == 'A' && output.data[1] == 'B');
StrClear(&output);
// Test u16 with :a (lowercase)
- In
Io.Write.c:427:
StrWriteFmt(&output, "{a}", u16_value);
success = success && (output.length == 2 && output.data[0] == 'a' && output.data[1] == 'b');
StrClear(&output);
// Test u16 with :A (uppercase)
- In
Io.Write.c:432:
StrWriteFmt(&output, "{A}", u16_value);
success = success && (output.length == 2 && output.data[0] == 'A' && output.data[1] == 'B');
StrClear(&output);
// Test with i16 (containing ASCII values)
- In
Io.Write.c:440:
StrWriteFmt(&output, "{c}", i16_value);
success = success && (output.length == 2 && output.data[0] == 'C' && output.data[1] == 'd');
StrClear(&output);
// Test i16 with :a (lowercase)
- In
Io.Write.c:445:
StrWriteFmt(&output, "{a}", i16_value);
success = success && (output.length == 2 && output.data[0] == 'c' && output.data[1] == 'd');
StrClear(&output);
// Test i16 with :A (uppercase)
- In
Io.Write.c:450:
StrWriteFmt(&output, "{A}", i16_value);
success = success && (output.length == 2 && output.data[0] == 'C' && output.data[1] == 'D');
StrClear(&output);
// Test with u32 (containing ASCII values)
- In
Io.Write.c:459:
success = success && (output.length == 4 && output.data[0] == 'E' && output.data[1] == 'f' &&
output.data[2] == 'G' && output.data[3] == 'h');
StrClear(&output);
// Test u32 with :a (lowercase)
- In
Io.Write.c:465:
success = success && (output.length == 4 && output.data[0] == 'e' && output.data[1] == 'f' &&
output.data[2] == 'g' && output.data[3] == 'h');
StrClear(&output);
// Test u32 with :A (uppercase)
- In
Io.Write.c:471:
success = success && (output.length == 4 && output.data[0] == 'E' && output.data[1] == 'F' &&
output.data[2] == 'G' && output.data[3] == 'H');
StrClear(&output);
// Test with i32 (containing ASCII values)
- In
Io.Write.c:480:
success = success && (output.length == 4 && output.data[0] == 'I' && output.data[1] == 'j' &&
output.data[2] == 'K' && output.data[3] == 'l');
StrClear(&output);
// Test i32 with :a (lowercase)
- In
Io.Write.c:486:
success = success && (output.length == 4 && output.data[0] == 'i' && output.data[1] == 'j' &&
output.data[2] == 'k' && output.data[3] == 'l');
StrClear(&output);
// Test i32 with :A (uppercase)
- In
Io.Write.c:492:
success = success && (output.length == 4 && output.data[0] == 'I' && output.data[1] == 'J' &&
output.data[2] == 'K' && output.data[3] == 'L');
StrClear(&output);
// Test with u64 (containing ASCII values)
- In
Io.Write.c:503:
output.data[2] == 'O' && output.data[3] == 'p' && output.data[4] == 'Q' &&
output.data[5] == 'r' && output.data[6] == 'S' && output.data[7] == 't');
StrClear(&output);
// Test u64 with :a (lowercase)
- In
Io.Write.c:510:
output.data[2] == 'o' && output.data[3] == 'p' && output.data[4] == 'q' &&
output.data[5] == 'r' && output.data[6] == 's' && output.data[7] == 't');
StrClear(&output);
// Test u64 with :A (uppercase)
- In
Io.Write.c:517:
output.data[2] == 'O' && output.data[3] == 'P' && output.data[4] == 'Q' &&
output.data[5] == 'R' && output.data[6] == 'S' && output.data[7] == 'T');
StrClear(&output);
// Test with i64 (containing ASCII values)
- In
Io.Write.c:528:
output.data[2] == 'W' && output.data[3] == 'x' && output.data[4] == 'Y' &&
output.data[5] == 'z' && output.data[6] == '1' && output.data[7] == '2');
StrClear(&output);
// Test i64 with :a (lowercase)
- In
Io.Write.c:535:
output.data[2] == 'w' && output.data[3] == 'x' && output.data[4] == 'y' &&
output.data[5] == 'z' && output.data[6] == '1' && output.data[7] == '2');
StrClear(&output);
// Test i64 with :A (uppercase)
- In
Io.Write.c:559:
StrWriteFmt(&output, "{}", bv1);
success = success && (ZstrCompare(output.data, "10110") == 0);
StrClear(&output);
// Test 2: Empty BitVec
- In
Io.Write.c:565:
StrWriteFmt(&output, "{}", bv_empty);
success = success && (output.length == 0);
StrClear(&output);
// Test 3: Hex formatting
- In
Io.Write.c:571:
StrWriteFmt(&output, "{x}", bv2);
success = success && (ZstrCompare(output.data, "0xabcd") == 0);
StrClear(&output);
// Test 4: Uppercase hex formatting
- In
Io.Write.c:576:
StrWriteFmt(&output, "{X}", bv2);
success = success && (ZstrCompare(output.data, "0xABCD") == 0);
StrClear(&output);
// Test 5: Octal formatting
- In
Io.Write.c:582:
StrWriteFmt(&output, "{o}", bv3);
success = success && (ZstrCompare(output.data, "0o755") == 0);
StrClear(&output);
// Test 6: Width and alignment
- In
Io.Write.c:587:
StrWriteFmt(&output, "{>10}", bv1);
success = success && (ZstrCompare(output.data, " 10110") == 0);
StrClear(&output);
StrWriteFmt(&output, "{<10}", bv1);
- In
Io.Write.c:591:
StrWriteFmt(&output, "{<10}", bv1);
success = success && (ZstrCompare(output.data, "10110 ") == 0);
StrClear(&output);
StrWriteFmt(&output, "{^10}", bv1);
- In
Io.Write.c:595:
StrWriteFmt(&output, "{^10}", bv1);
success = success && (ZstrCompare(output.data, " 10110 ") == 0);
StrClear(&output);
// Test 7: Zero value
- In
Io.Write.c:601:
StrWriteFmt(&output, "{x}", bv_zero);
success = success && (ZstrCompare(output.data, "0x0") == 0);
StrClear(&output);
StrWriteFmt(&output, "{o}", bv_zero);
- In
Io.Write.c:605:
StrWriteFmt(&output, "{o}", bv_zero);
success = success && (ZstrCompare(output.data, "0o0") == 0);
StrClear(&output);
// Cleanup
- In
Str.Memory.c:117:
// Test StrClear function
bool test_str_clear(void) {
WriteFmt("Testing StrClear\n");
Str s = StrInitFromZstr("Hello, World!");
- In
Str.Memory.c:125:
// Clear the string
StrClear(&s);
// Length should now be 0, but capacity should remain
- In
MisraEnum.c:104:
});
StrClear(&code);
// Use a temporary variable for enum name
- In
Str.c:144:
// Memory operations
case STR_CLEAR : {
StrClear(str);
break;
}