str_extra.c

Extra string functions library for C
git clone git://git.finwo.net/lib/str_extra.c
Log | Files | Refs | README

commit fcce88f57c77d39be3a8fc87b6f3d6032179bbe2
parent 9ddfa86916806e26a5fd1662e0720a3bfc13822b
Author: finwo <finwo@pm.me>
Date:   Wed, 16 Aug 2023 23:05:32 +0200

Added str_isHex method

Diffstat:
Mconfig.mk | 1+
Mpackage.ini | 1+
Asrc/str_isHex.c | 20++++++++++++++++++++
Asrc/str_isHex.h | 4++++
4 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/config.mk b/config.mk @@ -1 +1,2 @@ SRC+=__DIRNAME/src/strnstr.c +SRC+=__DIRNAME/src/str_isHex.c diff --git a/package.ini b/package.ini @@ -1,6 +1,7 @@ [export] config.mk=config.mk include/finwo/strnstr.h=src/strnstr.h +include/finwo/str_isHex.h=src/str_isHex.h [package] deps=lib diff --git a/src/str_isHex.c b/src/str_isHex.c @@ -0,0 +1,20 @@ +#include <stdlib.h> +#include <string.h> + +#include "str_isHex.h" + +bool str_isHex(const char *subject) { + int i; + size_t l = strlen(subject); + for(i = 0 ; i < l ; i++) { + if ( + (subject[i] >= 'a' && subject[i] <= 'f') || + (subject[i] >= 'A' && subject[i] <= 'F') || + (subject[i] >= '0' && subject[i] <= '9') + ) { + continue; + } + return false; + } + return true; +} diff --git a/src/str_isHex.h b/src/str_isHex.h @@ -0,0 +1,4 @@ +#include <stdlib.h> +#include <stdbool.h> + +bool str_isHex(const char *subject);