chsvlib
chsv helper source code

◆ ucpstoul()

unsigned long Chusov::String::ucpstoul ( const ucp_t *restrict  str,
ucp_t **restrict  str_end,
int  base 
)
noexcept

Converts a number withing a string to the type "unsigned long".

Parameters
strA string with the number to convert.
str_endAn output pointer receiving an address of a first character that does not match any digit according to the value of base.
baseA radix used for conversion. Valid values are from the range 2 to 36 inclusively and 0 for automatic detection of the base. For base greater than 10 digits are expected to be encoded with latin characters. The conversion is case-insensitive.
Returns
The result of the conversion. If the converted number is not representable by the type
unsigned long
, the return value is ULONG_MAX. If the conversion fails, the functions returns 0.

The function skips leading whitespace characters, if any, before the actual conversion takes place.

If the value of base is 0, the function determines the base from the prefix of the number in str. If the prefix is "0x" or "0X", the base is determined to be 16. Otherwise, if the prefix is 0, the base is considered to be 8. Otherwise, it is 10.

If the number falls out of the range of values representable with the type

unsigned long

, the function sets errno to ERANGE and returns ULONG_MAX.

In any case, on output *str_end points to the first character in str which (after skipping all leading whitespace characters) does not correspond to a digit in base.

Remarks
The function repeats the functionality of the standard strtoul function but works with ucp_t characters.
See also
Chusov::String::ucpstoull ucpstoull
Chusov::String::ucpstol ucpstol
Chusov::String::ucpstoll ucpstoll
Chusov::String::ucpstof ucpstof
Chusov::String::ucpstod ucpstod
Chusov::String::ucpstold ucpstold.