IntFromStrRadix
IntFromStrRadix
Description
Parse digits in the given radix into an integer. Supports radices from 2 through 36 and ignores underscore separators.
Aborts on invalid digits or unsupported radix.
Parameters
| Name | Direction | Description |
|---|---|---|
digits |
in | Input digit string |
radix |
in | Radix to use |
Usage example (from documentation)
Int value = IntFromStrRadix("ff", 16);Returns
Parsed integer value.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:2834:
Str temp = StrInitFromCstr(start, i - start);
Int parsed = IntFromStrRadix(temp.data, radix);
IntDeinit(value);- In
Int.c:499:
}
Int IntFromStrRadix(const char *digits, u8 radix) {
u64 start = 0; WriteFmt("Testing Int radix conversion round trip\n");
Int value = IntFromStrRadix("zz", 36);
Str text = IntToStrRadix(&value, 36, false);
bool test_int_from_radix_invalid_digit(void) {
WriteFmt("Testing IntFromStrRadix invalid digit handling\n");
IntFromStrRadix("102", 2); WriteFmt("Testing IntFromStrRadix invalid digit handling\n");
IntFromStrRadix("102", 2);
return false;
}
bool test_int_from_radix_invalid_radix(void) {
WriteFmt("Testing IntFromStrRadix invalid radix handling\n");
IntFromStrRadix("10", 1); WriteFmt("Testing IntFromStrRadix invalid radix handling\n");
IntFromStrRadix("10", 1);
return false;
}
bool test_int_from_radix_null(void) {
WriteFmt("Testing IntFromStrRadix NULL handling\n");
IntFromStrRadix(NULL, 10); WriteFmt("Testing IntFromStrRadix NULL handling\n");
IntFromStrRadix(NULL, 10);
return false;
}
Last updated on