Skip to content

IS_DIGIT

IS_DIGIT

Description

Checks if the given character c is an ASCII digit.

Parameters

Name Direction Description
c in The character to check.

Success

Returns true for 0-9, false otherwise.

Failure

Function cannot fail - always returns boolean result.

Usage example (Cross-references)

Usage examples (Cross-references)
            char ch = input[pos];
    
            if (IS_DIGIT(ch)) {
                saw_digit      = true;
                need_exp_digit = false;
    static bool IsValidNumberChar(char c, bool is_first_char, bool allow_decimal) {
        // Allow digits
        if (IS_DIGIT(c))
            return true;
    
                // Must have at least one digit in exponent
                if (!IS_DIGIT(i[pos])) {
                    // Invalid exponent - back up to before the 'e'
                    pos--;
    
                // Continue with exponent digits
                while (IS_DIGIT(i[pos]))
                    pos++;
                break; // Stop after exponent
    
                // Must have at least one digit in exponent
                if (!IS_DIGIT(i[pos])) {
                    // Invalid exponent - back up to before the 'e'
                    pos--;
    
                // Continue with exponent digits
                while (IS_DIGIT(i[pos]))
                    pos++;
                break; // Stop after exponent
    // Helper function to convert character to digit
    static inline bool char_to_digit(char c, u8 *digit, u8 base) {
        if (IS_DIGIT(c)) {
            *digit = c - '0';
        } else if (IN_RANGE(c, 'a', 'z')) {
    
        // Parse integer part
        while (pos < str->length && IS_DIGIT(str->data[pos])) {
            result      = result * 10.0 + (str->data[pos] - '0');
            have_digits = true;
            f64 scale = 0.1;
    
            while (pos < str->length && IS_DIGIT(str->data[pos])) {
                result      += (str->data[pos] - '0') * scale;
                scale       *= 0.1;
            bool have_exp_digits = false;
    
            while (pos < str->length && IS_DIGIT(str->data[pos])) {
                exponent        = exponent * 10 + (str->data[pos] - '0');
                have_exp_digits = true;
    ///
    /// TAGS: Character, Validation, Hexadecimal
    #define IS_XDIGIT(c) (IS_DIGIT(c) || IN_RANGE(c, 'a', 'f') || IN_RANGE(c, 'A', 'F'))
    
    ///
Last updated on