mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/fmt: add fmt_is_number()
This commit is contained in:
parent
d9229af9d9
commit
ab3669294b
@ -53,6 +53,20 @@ static inline char _to_lower(char c)
|
||||
return 'a' + (c - 'A');
|
||||
}
|
||||
|
||||
int fmt_is_number(const char *str)
|
||||
{
|
||||
if (!str || !*str) {
|
||||
return 0;
|
||||
}
|
||||
for (; *str; str++) {
|
||||
if (!fmt_is_digit(*str)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t fmt_byte_hex(char *out, uint8_t byte)
|
||||
{
|
||||
if (out) {
|
||||
|
@ -69,6 +69,15 @@ static inline int fmt_is_upper(char c)
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test if the given string is a number (regex `[0-9]+`)
|
||||
*
|
||||
* @param[in] str String to test, **must be `\0` terminated**
|
||||
*
|
||||
* @return true if @p str solely contains digits, false otherwise
|
||||
*/
|
||||
int fmt_is_number(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Format a byte value as hex
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user