-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/string/ctype/strisascii_c/: strisdigit_c(): Add function
The "_c" means that it considers the digits from the C locale. Signed-off-by: Alejandro Colomar <[email protected]>
- Loading branch information
1 parent
8821d3f
commit d160bac
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]> | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
#include <config.h> | ||
|
||
#include "string/ctype/strisascii_c/strisdigit_c.h" | ||
|
||
#include <stdbool.h> | ||
|
||
|
||
extern inline bool strisdigit_c(const char *s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]> | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_C_STRISDIGIT_C_H_ | ||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_C_STRISDIGIT_C_H_ | ||
|
||
|
||
#include <config.h> | ||
|
||
#include <stdbool.h> | ||
|
||
#include "string/strchr/stpspn.h" | ||
#include "string/strcmp/streq.h" | ||
|
||
|
||
inline bool strisdigit_c(const char *s); | ||
|
||
|
||
// Like isdigit(3), | ||
// but check all characters in the string, and use the C locale. | ||
inline bool | ||
strisdigit_c(const char *s) | ||
{ | ||
if (streq(s, "")) | ||
return false; | ||
|
||
return streq(stpspn(s, "0123456789"), ""); | ||
} | ||
|
||
|
||
#endif // include guard |