Skip to content
IntTryFromOctStr

IntTryFromOctStr

Description

Parse an octal string into an integer. Accepts an optional 0o or 0O prefix; underscore separators between digits are silently skipped.

Parameters

Name Direction Description
out in,out Int to overwrite with the parsed value. Must already be a valid initialised Int; its allocator is reused for the parsed result.
octal in Null-terminated octal string, optionally prefixed with 0o / 0O.

Success

Returns true. *out is deinitialised and replaced with the normalised parsed value.

Failure

Returns false on a non-octal character, an empty digit run, or an allocation failure during accumulation. *out retains its pre-call value.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    bool test_int_try_from_octal_null(void) {
        WriteFmt("Testing IntTryFromOctStr NULL handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromOctStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
    
        Int  out = IntInit(&alloc.base);
        bool ok  = IntTryFromOctStr(&out, "17");
    
        bool result = ok && (IntToU64(&out) == 15);
    
        Int  out = IntInit(&alloc.base);
        bool ok  = IntTryFromOctStr(&out, "017");
    
        bool result = ok && (IntToU64(&out) == 15);
Last updated on