Skip to content

IntFromStr

Description

Compatibility wrapper for IntTryFromStr(...).

Success

Returns Parsed integer value, or zero on failure.

Failure

Returns a zero-initialised Int on a non-decimal character, an empty digit run, or an allocation failure. Use IntTryFromStr(...) when explicit failure propagation is required.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        Zstr digits = "123456789012345678901234567890";
        Int  value  = IntFromStr(digits, ALLOCATOR_OF(&alloc));
        Str  text   = IntToStr(&value);
    
    bool test_int_from_decimal_invalid_digit(void) {
        WriteFmt("Testing IntFromStr invalid digit handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  parsed = IntFromStr("12x3", ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromStr(&value, "12x3");
    
    bool test_int_from_decimal_null(void) {
        WriteFmt("Testing IntFromStr NULL handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  parsed = IntFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromStr(&value, (Zstr)NULL);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int   integer = IntFromStr("12345678901234567890", ALLOCATOR_OF(&alloc));
        Float value   = float_from_int(&integer, ALLOCATOR_OF(&alloc));
        Str   text    = FloatToStr(&value);
        bool success = true;
    
        Int big_dec = IntFromStr("123456789012345678901234567890", alloc_base);
        Int hex_val = IntFromHexStr("deadbeefcafebabe1234", alloc_base);
        Int bin_val = IntFromBinary("10100011", alloc_base);
        Int large = IntFrom(1u, &alloc.base);
        IntShiftLeft(&large, 80);
        Int decimal = IntFromStr("12345678901234567890", &alloc.base);
    
        u64 h_zero    = int_hash(&zero, 0);
        Int rhs          = IntFrom(2, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int huge         = IntFromStr("123456789012345678901234567890", &alloc.base);
        Str text         = StrInit(&alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int preserved    = IntFrom(99, &alloc.base);
        Int huge         = IntFromStr("12345678901234567890", &alloc.base);
        Str text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value        = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int dividend     = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value     = IntFromStr("12345678901234567890", &alloc.base);
        Int remainder = IntInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int prime     = IntFromStr("1000000007", &alloc.base);
        Int composite = IntFrom(561, &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntFromStr("1000000000", &alloc.base);
        Int next  = IntInit(&alloc.base);
        Str text  = StrInit(&alloc.base);
Last updated on