Skip to content

Commit

Permalink
lib/string/ctype/strisascii_c/: strisdigit_c(): Add function
Browse files Browse the repository at this point in the history
The "_c" means that it considers the digits from the C locale.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Dec 13, 2024
1 parent 8821d3f commit d160bac
Show file tree
Hide file tree
Showing 3 changed files with 46 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_c/strisdigit_c.c \
string/ctype/strisascii_c/strisdigit_c.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_c/strisdigit_c.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_c/strisdigit_c.h"

#include <stdbool.h>


extern inline bool strisdigit_c(const char *s);
32 changes: 32 additions & 0 deletions lib/string/ctype/strisascii_c/strisdigit_c.h
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

0 comments on commit d160bac

Please sign in to comment.