IS_DIGIT

Table of Contents

IS_DIGIT

Description

Checks if the given character c is an ASCII digit.

Parameters

NameDirectionDescription
cinThe character to check.

Success

Returns true for 0-9, false otherwise.

Failure

Function cannot fail - always returns boolean result.

Usage example (Cross-references)

    ///
    /// TAGS: Character, Validation, Hexadecimal
    #define IS_XDIGIT(c) (IS_DIGIT(c) || IN_RANGE(c, 'a', 'f') || IN_RANGE(c, 'A', 'F'))
    
    ///
    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;

Share :

Related Posts

IS_PRINTABLE

IS_PRINTABLE Description Checks whether a given character ‘c’ is printable ascii or not.

Read More

IS_CAPS_ALPHA

IS_CAPS_ALPHA Description Checks if the given character c is an uppercase ASCII alphabet.

Read More

IS_ALPHA

IS_ALPHA Description Checks if the given character c is an ASCII alphabet.

Read More