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)
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStrRadix("zz", 36, ALLOCATOR_OF(&alloc));
Str text = IntToStrRadix(&value, 36, false);
bool test_int_from_radix_invalid_digit(void) {
WriteFmt("Testing IntFromStrRadix invalid digit handling\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromStrRadix("102", 2, ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromStrRadix(&value, "102", 2);
bool test_int_from_radix_invalid_radix(void) {
WriteFmt("Testing IntFromStrRadix invalid radix handling\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromStrRadix("10", 1, ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromStrRadix(&value, "10", 1);
bool test_int_from_radix_null(void) {
WriteFmt("Testing IntFromStrRadix NULL handling\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromStrRadix((Zstr)NULL, 10, ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromStrRadix(&value, (Zstr)NULL, 10);
Last updated on