-
Notifications
You must be signed in to change notification settings - Fork 241
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/: strisdigit(): Add function
Signed-off-by: Alejandro Colomar <[email protected]>
- Loading branch information
1 parent
8821d3f
commit d5fb6c4
Showing
3 changed files
with
45 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/strisdigit.h" | ||
|
||
#include <stdbool.h> | ||
|
||
|
||
extern inline bool strisdigit(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,31 @@ | ||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]> | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_STRISDIGIT_H_ | ||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_STRISDIGIT_H_ | ||
|
||
|
||
#include <config.h> | ||
|
||
#include <stdbool.h> | ||
|
||
#include "string/strchr/stpspn.h" | ||
#include "string/strcmp/streq.h" | ||
|
||
|
||
inline bool strisdigit(const char *s); | ||
|
||
|
||
// Like isdigit(3), but check all characters in the string. | ||
inline bool | ||
strisdigit(const char *s) | ||
{ | ||
if (streq(s, "")) | ||
return false; | ||
|
||
return streq(stpspn(s, "0123456789"), ""); | ||
} | ||
|
||
|
||
#endif // include guard |