]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/ctype/strisascii.*: Don't special-case ""
authorAlejandro Colomar <alx@kernel.org>
Sat, 3 Jan 2026 13:37:43 +0000 (14:37 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Thu, 11 Jun 2026 07:33:53 +0000 (09:33 +0200)
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 <alx@kernel.org>
lib/string/README
lib/string/ctype/strisascii.c
lib/string/ctype/strisascii.h

index 77b8b93162701ed44b35ffa07a2337f342fd1e89..f3cfceeab46144d3509db3f06f704db40e9e8dd6 100644 (file)
@@ -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
index c87c8f1b28bf6bb521248cdbbbd9f34d50e10c75..24e8a9cbb4afa52d0558c81ff0726957194a3294 100644 (file)
@@ -5,9 +5,3 @@
 #include "config.h"
 
 #include "string/ctype/strisascii.h"
-
-#include <stdbool.h>
-
-
-extern inline bool strisdigit_c(const char *s);
-extern inline bool strisprint_c(const char *s);
index 8e6b59b0bd23569f7cdfc7942a57ed1a414ea48d..eb4d831bbd89aa07552cf7ed21e9523ebc91eaf5 100644 (file)
@@ -8,27 +8,14 @@
 
 #include "config.h"
 
-#include <stdbool.h>
-
 #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