IN_RANGE

Table of Contents

IN_RANGE

Description

Checks if the value x is within the inclusive range [lo, hi].

Parameters

NameDirectionDescription
xinThe value to check.
loinThe lower bound of the range.
hiinThe upper bound of the range.

Success

Returns true if x is in range, false otherwise.

Failure

Function cannot fail - always returns boolean result.

Usage example (Cross-references)

    ///
    /// TAGS: Character, Validation, ASCII
    #define IS_CAPS_ALPHA(c) IN_RANGE(c, 'A', 'Z')
    
    ///
    ///
    /// TAGS: Character, ASCII, Printable
    #define IS_PRINTABLE(c) (IN_RANGE(c, 0x20, 0x7e) || IS_SPACE(c))
    
    ///
    ///
    /// TAGS: Character, Validation, ASCII
    #define IS_ALPHA(c) (IN_RANGE(c, 'a', 'z') || IN_RANGE(c, 'A', 'Z'))
    
    ///
    ///
    /// TAGS: Character, Validation, Numeric
    #define IS_DIGIT(c) IN_RANGE(c, '0', '9')
    
    ///
    ///
    /// TAGS: Character, Validation, Hexadecimal
    #define IS_XDIGIT(c) (IS_DIGIT(c) || IN_RANGE(c, 'a', 'f') || IN_RANGE(c, 'A', 'F'))
    
    ///
    ///
    /// TAGS: Character, Conversion, Case
    #define TO_UPPER(c) (IN_RANGE(c, 'a', 'z') ? ((c) - ('a' - 'A')) : (c))
    
    ///
    if (IS_DIGIT(c)) {
    *digit = c - '0';
    } else if (IN_RANGE(c, 'a', 'z')) {
    *digit = c - 'a' + 10;
    } else if (IN_RANGE(c, 'A', 'Z')) {
    } else if (IN_RANGE(c, 'a', 'z')) {
    *digit = c - 'a' + 10;
    } else if (IN_RANGE(c, 'A', 'Z')) {
    *digit = c - 'A' + 10;
    } else {

Share :

Related Posts

MIN2

MIN2 Description Returns the smaller of two values x and y.

Read More

CLAMP

CLAMP Description Clamps the value of x to be within the inclusive range [lo, hi].

Read More

MAX2

MAX2 Description Returns the larger of two values x and y.

Read More