Skip to content

Commit

Permalink
lib/string/ctype/strisascii/: strisdigit(): Add function
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Dec 14, 2024
1 parent 8821d3f commit d5fb6c4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ libshadow_la_SOURCES = \
spawn.c \
sssd.c \
sssd.h \
string/ctype/strisascii/strisdigit.c \
string/ctype/strisascii/strisdigit.h \
string/memset/memzero.c \
string/memset/memzero.h \
string/sprintf/snprintf.c \
Expand Down
12 changes: 12 additions & 0 deletions lib/string/ctype/strisascii/strisdigit.c
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);
31 changes: 31 additions & 0 deletions lib/string/ctype/strisascii/strisdigit.h
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

0 comments on commit d5fb6c4

Please sign in to comment.