-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/fmt: add fmt_is_number() #12878
sys/fmt: add fmt_is_number() #12878
Conversation
9d5e45a
to
f97bb41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo.
LGTM, pls squash after fixing!
@@ -20,6 +20,28 @@ | |||
#include "fmt.h" | |||
#include "tests-fmt.h" | |||
|
|||
static void test_fmg_is_x(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here and below: fmg
-> fmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course, fixed.
sys/fmt/fmt.c
Outdated
{ | ||
return (c >= 'A' && c <= 'Z'); | ||
} | ||
if (!str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!str) { | |
if (!str || !*str) { |
otherwise an empty string would be considered a number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense, fixed.
f97bb41
to
cea260b
Compare
addressed comments. |
Sorry, tests were not run, I'll re-trigger. |
ACK. |
Contribution description
The
_is_number()
function is currently duplicated in the RIOT code base at two locations. Furthermore, I need the same function in some other module - and I really don't want to duplicate it even further... So I added that function to thefmt
module.So this PR does the following:
fmt_is_digit()
andfmt_is_upper()
to thefmt
s modules public APIfmt_is_number()
function to thefmt
moduletests/driver_kw2xrf
andshell/commands/sc_gnrc_netif
usefmt_is_number()
instead of their local implementationsNote: while moving the
is_number()
function, I altered it slightly: (i) useint
instead ofbool
, to keep thefmt
s modules dependencies to the stdlib low, and (ii) also check the input string for beingNULL
so the function does not returntrue
on empty strings.Testing procedure
Run unittests and check the build output for
tests/driver_kw2xrf
andexamples/gnrc_networking
.Issues/PRs references
none