From: Alejandro Colomar Date: Sat, 3 Jan 2026 13:37:43 +0000 (+0100) Subject: lib/string/ctype/strisascii.*: Don't special-case "" X-Git-Tag: 4.20.0-rc1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d85bf1617f207b212625942553120249ba3abc07;p=thirdparty%2Fshadow.git lib/string/ctype/strisascii.*: Don't special-case "" It is not intuitive or clear what the right behavior should be for an empty string. If we define these APIs as "return true if all characters in the string belong to the specified character set", then an empty string should return true. On the other hand, if you ask me if an empty string is a numeric string, I might naively say no. It is irrelevant whether we return true or false for an empty string. All of the callers already handle correctly the case of an empty string. This makes the implementation simpler, using the argument only once. This allows implementing these as macros. Signed-off-by: Alejandro Colomar --- diff --git a/lib/string/README b/lib/string/README index 77b8b9316..f3cfceeab 100644 --- a/lib/string/README +++ b/lib/string/README @@ -85,8 +85,8 @@ ctype/ - Character classification and conversion functions The functions defined in this file return true if all of the characters of the string - belong to the category specified in the function name - and the string is not an empty string. + belong to the category specified in the function name. + The behavior is undefined is the string is an empty string. strtoascii.h The functions defined in this file diff --git a/lib/string/ctype/strisascii.c b/lib/string/ctype/strisascii.c index c87c8f1b2..24e8a9cbb 100644 --- a/lib/string/ctype/strisascii.c +++ b/lib/string/ctype/strisascii.c @@ -5,9 +5,3 @@ #include "config.h" #include "string/ctype/strisascii.h" - -#include - - -extern inline bool strisdigit_c(const char *s); -extern inline bool strisprint_c(const char *s); diff --git a/lib/string/ctype/strisascii.h b/lib/string/ctype/strisascii.h index 8e6b59b0b..eb4d831bb 100644 --- a/lib/string/ctype/strisascii.h +++ b/lib/string/ctype/strisascii.h @@ -8,27 +8,14 @@ #include "config.h" -#include - #include "string/ctype/isascii.h" #include "string/strcmp/streq.h" #include "string/strspn/stpspn.h" -inline bool strisdigit_c(const char *s); // strisdigit - string is [:digit:] C-locale -inline bool strisprint_c(const char *s); // strisprint - string is [:print:] C-locale - - -inline bool -strisdigit_c(const char *s) -{ - return !streq(s, "") && streq(stpspn(s, CTYPE_DIGIT_C), ""); -} -inline bool -strisprint_c(const char *s) -{ - return !streq(s, "") && streq(stpspn(s, CTYPE_PRINT_C), ""); -} +// strisascii_c - string is [:ascii:] C-locale +#define strisdigit_c(s) streq(stpspn(s, CTYPE_DIGIT_C), "") +#define strisprint_c(s) streq(stpspn(s, CTYPE_PRINT_C), "") #endif // include guard