chsvlib
chsv helper source code

◆ ucp_isdigit()

int Chusov::String::ucp_isdigit ( ucp_t  ch)
noexcept

Returns a flag that indicates whether a given character is a digit character in the Unicode code space.

Parameters
chis the character to check.
Returns
A nonzero value, if ch is an ASCII decimal digit, i.e. belongs to the range \(\left[\textrm{0x30}; \textrm{0x39}\right]\), or, if ch is not an ASCII character and belongs to any of the three "Number" normative general categories. Otherwise, the function returns a zero value.

The function firstly checks if ch belongs to the ASCII code space. If it does, the function returns the result of a call to ucp_isdigit_ascii. Otherwise, if ch is not an ASCII character the function checks if ch belongs to any of the respective Unicode general categories.

The function does not take Unicode surrogate pairs into account and simply returns 0, if ch appertains the range \(\left[\textrm{0xd800}; \textrm{0xf8ff}\right]\). The function also returns 0, if ch does not belong to the range of valid Unicode code points.

Warning
The function returns a non-zero value for any character that belongs to the "Number" Unicode general category, including those which cannot be converted to actual numeric values by functions like to_ucp_string. On the other hand, the function does not consider Latin symbols to be digits. So not all digits in numerical systems of base greater than 10, such as hexadecimal digits, will be considered digits by the function. Therefore, conversion of Unicode string and characters to actual numerical values cannot be done dogether with this function. Therefore, to the guarantee of convertibility of Unicode characters to actual numbers one should use ucp_isdigit_ascii (for decimal digits) or ucp_isxdigit_ascii (for hexadecimal digits) instead.
See also
ucp_isxdigit_ascii Checks whether ch is either a decimal digit '0'-'9' or a hexadecimal digit ('A'-'F' or 'a'-'f').