StrParseConfig
StrParseConfig
Description
Configuration for parsing
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:2700:
Str hex_str = StrInitFromCstr(hex_start, i - hex_start);
u64 value;
StrParseConfig config = {.base = 16};
if (!StrToU64(&hex_str, &value, &config)) {
LOG_ERROR("Failed to parse hex value");- In
Io.c:2736:
Str oct_str = StrInitFromCstr(oct_start, i - oct_start);
u64 value;
StrParseConfig config = {.base = 8};
if (!StrToU64(&oct_str, &value, &config)) {
LOG_ERROR("Failed to parse octal value");- In
Str.c:568:
}
bool StrToU64(const Str *str, u64 *value, const StrParseConfig *config) {
ValidateStr(str);- In
Str.c:658:
}
bool StrToI64(const Str *str, i64 *value, const StrParseConfig *config) {
ValidateStr(str);- In
Str.c:718:
}
bool StrToF64(const Str *str, f64 *value, const StrParseConfig *config) {
ValidateStr(str);- In
Str.c:880:
{.precision = 6, .force_sci = false, .uppercase = false, .trim_zeros = false, .always_sign = false};
const StrParseConfig STR_PARSE_DEFAULT = {.strict = false, .trim_space = true, .base = 0}; StrDeinit(&s);
s = StrInitFromZstr("ABCD"); // No 0x prefix when base is explicitly 16
StrParseConfig config = {.base = 16};
success = StrToU64(&s, &value, &config);
result = result && (success && value == 0xABCD);
// For bases with prefixes, use auto-detect. For others, use explicit base parsing
StrParseConfig parse_config = {.base = base};
bool success = StrToU64(&s, &recovered, config.use_prefix ? NULL : &parse_config);
result = result && success && (recovered == base); Str test_str = StrInitFromZstr(prefix_tests[i].input);
u64 value = 0;
StrParseConfig config = {.base = prefix_tests[i].base};
bool success = StrToU64(&test_str, &value, prefix_tests[i].base == 0 ? NULL : &config);
result = result && success && (value == prefix_tests[i].expected); StrFromU64(&s, large_value, &config);
u64 recovered = 0;
StrParseConfig pconfig = {.base = base};
bool success = StrToU64(&s, &recovered, &pconfig); // Can now use explicit base with prefixes
result = result && success && (recovered == large_value); // Test StrToU64 round-trip
u64 recovered = 0;
StrParseConfig parse_config = {.base = base};
bool success = StrToU64(&s, &recovered, &parse_config);
u64 recovered = 0;
StrParseConfig parse_config = {.base = base};
bool success = StrToU64(&s, &recovered, &parse_config);
u64 recovered = 0;
StrParseConfig parse_config = {.base = base};
bool success = StrToU64(&s, &recovered, &parse_config);- In
Convert.h:39:
bool trim_space; ///< Trim leading/trailing whitespace
u8 base; ///< Base for integers (0 = auto-detect)
} StrParseConfig;
/// Default configurations
- In
Convert.h:44:
extern const StrIntFormat STR_INT_DEFAULT;
extern const StrFloatFormat STR_FLOAT_DEFAULT;
extern const StrParseConfig STR_PARSE_DEFAULT;
///
- In
Convert.h:92:
/// FAILURE : Returns false if conversion fails
///
bool StrToU64(const Str *str, u64 *value, const StrParseConfig *config);
///
- In
Convert.h:104:
/// FAILURE : Returns false if conversion fails
///
bool StrToI64(const Str *str, i64 *value, const StrParseConfig *config);
///
- In
Convert.h:116:
/// FAILURE : Returns false if conversion fails
///
bool StrToF64(const Str *str, f64 *value, const StrParseConfig *config);
Last updated on