aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-05-24 10:49:34 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-05-24 10:49:34 -0400
commite1a47b385cb93c1b0cc759604ad06b7bdd48f15b (patch)
tree029cc1134a06984c97d1f2fe94fd6af0574a9347
parent03e39ae5dcd4002ac9657a550c48b8e9f85c449c (diff)
downloadspmc-e1a47b385cb93c1b0cc759604ad06b7bdd48f15b.tar.gz
Add string functions:
* isdigit_s() * tolower_s()
-rw-r--r--include/str.h2
-rw-r--r--lib/str.c27
2 files changed, 29 insertions, 0 deletions
diff --git a/include/str.h b/include/str.h
index 468f674..ae54997 100644
--- a/include/str.h
+++ b/include/str.h
@@ -34,5 +34,7 @@ int isquoted(char *sptr);
char *normalize_space(char *s);
char **strdup_array(char **array);
int strcmp_array(const char **a, const char **b);
+int isdigit_s(char *s);
+char *tolower_s(char *s);
#endif //SPM_STR_H
diff --git a/lib/str.c b/lib/str.c
index 9b5b201..5fbb8ad 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -817,3 +817,30 @@ int strcmp_array(const char **a, const char **b) {
}
return result;
}
+
+/**
+ * Determine whether a string is comprised of digits
+ * @param s
+ * @return 0=no, 1=yes
+ */
+int isdigit_s(char *s) {
+ for (size_t i = 0; s[i] != '\0'; i++) {
+ if (isdigit(s[i]) == 0) {
+ return 0; // non-digit found, fail
+ }
+ }
+ return 1; // all digits, succeed
+}
+
+/**
+ * Convert input string to lowercase
+ * @param s
+ * @return pointer to input string
+ */
+char *tolower_s(char *s) {
+ for (size_t i = 0; s[i] != '\0'; i++) {
+ s[i] = (char)tolower(s[i]);
+ }
+ return s;
+}
+