IntFromStrRadix
Description
Compatibility wrapper for IntTryFromStrRadix(...).
Success
Returns Parsed integer value, or zero on failure.
Failure
Returns a zero-initialised Int on an invalid radix, an invalid digit, an empty digit run, or an allocation failure. Use IntTryFromStrRadix(...) when explicit failure propagation is required.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Convert.c:192:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStrRadix("zz", 36, ALLOCATOR_OF(&alloc));
Str text = IntToStrRadix(&value, 36, false);- In
Convert.c:389:
bool test_int_from_radix_invalid_digit(void) {
WriteFmt("Testing IntFromStrRadix invalid digit handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:393:
DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromStrRadix("102", 2, ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromStrRadix(&value, "102", 2);- In
Convert.c:407:
bool test_int_from_radix_invalid_radix(void) {
WriteFmt("Testing IntFromStrRadix invalid radix handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:411:
DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromStrRadix("10", 1, ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromStrRadix(&value, "10", 1);- In
Convert.c:506:
bool test_int_from_radix_null(void) {
WriteFmt("Testing IntFromStrRadix NULL handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:510:
DefaultAllocator alloc = DefaultAllocatorInit();
IntFromStrRadix((Zstr)NULL, 10, ALLOCATOR_OF(&alloc));
DefaultAllocatorDeinit(&alloc);
return false;- In
Convert.c:924:
DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed_dec = IntFromStrRadix("987654321987654321", 10, &alloc.base);
Int parsed_hex = IntFromStrRadix("deadbeef", 16, &alloc.base);- In
Convert.c:925:
Int parsed_dec = IntFromStrRadix("987654321987654321", 10, &alloc.base);
Int parsed_hex = IntFromStrRadix("deadbeef", 16, &alloc.base);
Str back_dec = IntToStrRadix(&parsed_dec, 10, false, &alloc.base);- In
Convert.c:1479:
Str digits = StrInitFromZstr("ff", &alloc.base);
Int value = IntFromStrRadix(&digits, (u8)16u, &alloc.base);
bool result = (IntToU64(&value) == (u64)255u);- In
Convert.c:1626:
Int value = IntFromStr("123456789012345678901234567890", alloc);
Str hex = IntToStrRadix(&value, 16, false, alloc);
Int parsed = IntFromStrRadix(&hex, 16, alloc);
bool ok = IntCompare(&value, &parsed) == 0;
Last updated on