diff options
author | Simon Glass <sjg@chromium.org> | 2022-04-24 23:30:58 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-04-25 10:00:03 -0400 |
commit | 8565efd509236dc7d4e766de39edae2cefb10057 (patch) | |
tree | 75c6a767cbdac256ad2b4433b5f08a0c97f45ff7 /test | |
parent | d667a0d8f413d7278f912aa4e671bc56d28b25f2 (diff) | |
download | u-boot-8565efd509236dc7d4e766de39edae2cefb10057.zip u-boot-8565efd509236dc7d4e766de39edae2cefb10057.tar.gz u-boot-8565efd509236dc7d4e766de39edae2cefb10057.tar.bz2 |
lib: Add a way to find the postiion of a trailing number
At present it is not possible to find out which part of the string is the
number part and which is before it. Add a new variant which provides this
feature, so we can separate the two in the caller.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/str_ut.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/test/str_ut.c b/test/str_ut.c index 058b359..5a84434 100644 --- a/test/str_ut.c +++ b/test/str_ut.c @@ -244,7 +244,9 @@ STR_TEST(str_xtoa, 0); static int str_trailing(struct unit_test_state *uts) { - char str1[] = "abc123def"; + const char str1[] = "abc123def"; + const char str2[] = "abc123def456"; + const char *end; ut_asserteq(-1, trailing_strtol("")); ut_asserteq(-1, trailing_strtol("123")); @@ -259,6 +261,15 @@ static int str_trailing(struct unit_test_state *uts) ut_asserteq(3, trailing_strtol("a3")); + ut_asserteq(123, trailing_strtoln_end(str1, str1 + 6, &end)); + ut_asserteq(3, end - str1); + + ut_asserteq(-1, trailing_strtoln_end(str1, str1 + 7, &end)); + ut_asserteq(7, end - str1); + + ut_asserteq(456, trailing_strtoln_end(str2, NULL, &end)); + ut_asserteq(9, end - str2); + return 0; } STR_TEST(str_trailing, 0); |