Skip to content
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

Merged
merged 5 commits into from
Dec 5, 2019
Merged

Conversation

haukepetersen
Copy link
Contributor

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 the fmt module.

So this PR does the following:

  • move fmt_is_digit() and fmt_is_upper() to the fmts modules public API
  • add fmt_is_number() function to the fmt module
  • add fitting unit tests for these 3 functions
  • make tests/driver_kw2xrf and shell/commands/sc_gnrc_netif use fmt_is_number() instead of their local implementations

Note: while moving the is_number() function, I altered it slightly: (i) use int instead of bool, to keep the fmts modules dependencies to the stdlib low, and (ii) also check the input string for being NULL so the function does not return true on empty strings.

Testing procedure

Run unittests and check the build output for tests/driver_kw2xrf and examples/gnrc_networking.

Issues/PRs references

none

@haukepetersen haukepetersen added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: sys Area: System labels Dec 5, 2019
Copy link
Contributor

@kaspar030 kaspar030 left a 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)
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

@kaspar030 kaspar030 Dec 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!str) {
if (!str || !*str) {

otherwise an empty string would be considered a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, fixed.

@haukepetersen
Copy link
Contributor Author

addressed comments.

@kaspar030 kaspar030 added the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Dec 5, 2019
@kaspar030
Copy link
Contributor

Sorry, tests were not run, I'll re-trigger.

@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 5, 2019
@kaspar030
Copy link
Contributor

ACK.

@kaspar030 kaspar030 merged commit c7a534e into RIOT-OS:master Dec 5, 2019
@haukepetersen haukepetersen deleted the add_fmt_isnumber branch December 6, 2019 08:22
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants