Skip to content
IntTryFromStrRadix

IntTryFromStrRadix

Description

Parse digits in the given radix into an integer. Supports radices from 2 through 36 and ignores underscore separators.

Usage example (Cross-references)

Usage examples (Cross-references)
        Str  temp   = StrInitFromCstr(start, i - start);
        Int  parsed = IntInit();
        bool ok     = IntTryFromStrRadix(&parsed, temp.data, radix);
    
        if (!ok) {
    }
    
    bool IntTryFromStrRadix(Int *out, const char *digits, u8 radix) {
        u64 start = 0;
        Int out = IntInit();
    
        (void)IntTryFromStrRadix(&out, digits, radix);
        return out;
    }
        Int parsed = IntFromStrRadix("102", 2);
        Int value  = IntInit();
        bool result = !IntTryFromStrRadix(&value, "102", 2);
    
        result = result && IntIsZero(&parsed);
        Int parsed = IntFromStrRadix("10", 1);
        Int value  = IntInit();
        bool result = !IntTryFromStrRadix(&value, "10", 1);
    
        result = result && IntIsZero(&parsed);
        Int parsed = IntFromStrRadix(NULL, 10);
        Int value  = IntInit();
        bool result = !IntTryFromStrRadix(&value, NULL, 10);
    
        result = result && IntIsZero(&parsed);
Last updated on