mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/fmt: move _is_digit and _is_upper to public API
This commit is contained in:
parent
2b934dea5f
commit
d9229af9d9
@ -48,16 +48,6 @@ static const uint32_t _tenmap[] = {
|
||||
|
||||
#define TENMAP_SIZE ARRAY_SIZE(_tenmap)
|
||||
|
||||
static inline int _is_digit(char c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static inline int _is_upper(char c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static inline char _to_lower(char c)
|
||||
{
|
||||
return 'a' + (c - 'A');
|
||||
@ -437,7 +427,7 @@ size_t fmt_to_lower(char *out, const char *str)
|
||||
size_t len = 0;
|
||||
|
||||
while (str && *str) {
|
||||
if (_is_upper(*str)) {
|
||||
if (fmt_is_upper(*str)) {
|
||||
if (out) {
|
||||
*out++ = _to_lower(*str);
|
||||
}
|
||||
@ -457,7 +447,7 @@ uint32_t scn_u32_dec(const char *str, size_t n)
|
||||
uint32_t res = 0;
|
||||
while(n--) {
|
||||
char c = *str++;
|
||||
if (!_is_digit(c)) {
|
||||
if (!fmt_is_digit(c)) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
@ -474,8 +464,8 @@ uint32_t scn_u32_hex(const char *str, size_t n)
|
||||
|
||||
while (n--) {
|
||||
char c = *str++;
|
||||
if (!_is_digit(c)) {
|
||||
if (_is_upper(c)) {
|
||||
if (!fmt_is_digit(c)) {
|
||||
if (fmt_is_upper(c)) {
|
||||
c = _to_lower(c);
|
||||
}
|
||||
if (c == '\0' || c > 'f') {
|
||||
|
@ -45,6 +45,30 @@ extern "C" {
|
||||
#define FMT_USE_MEMMOVE (1) /**< use memmove() or internal implementation */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Test if the given character is a numerical digit (regex `[0-9]`)
|
||||
*
|
||||
* @param[in] c Character to test
|
||||
*
|
||||
* @return true if @p c is a digit, false otherwise
|
||||
*/
|
||||
static inline int fmt_is_digit(char c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test if the given character is an uppercase letter (regex `[A-Z]`)
|
||||
*
|
||||
* @param[in] c Character to test
|
||||
*
|
||||
* @return true if @p c is an uppercase letter, false otherwise
|
||||
*/
|
||||
static inline int fmt_is_upper(char c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format a byte value as hex
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user