aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Kellermann2018-07-19 18:05:46 -0400
committerAntony Kellermann2018-07-19 18:05:46 -0400
commit8e59ff5ff8c7f412b8d9ae360f5671f24e10e1a5 (patch)
treea8d8f7091889c8e38122566efd47a24dc582292f
parentd2d72dd287eb97293c952fef041aff5310c96c43 (diff)
downloadaur-8e59ff5ff8c7f412b8d9ae360f5671f24e10e1a5.tar.gz
Added is_str_number function
-rw-r--r--string-tick.c12
-rw-r--r--string-tick.h7
2 files changed, 19 insertions, 0 deletions
diff --git a/string-tick.c b/string-tick.c
index b916657c2ef6..5ddf41373cd6 100644
--- a/string-tick.c
+++ b/string-tick.c
@@ -100,4 +100,16 @@ int is_string_json_array(const String* pString) {
int formatted = jobj != NULL && json_object_is_type(jobj, json_type_array);
json_object_put(jobj);
return formatted;
+}
+
+int is_str_number(const char* string) {
+ size_t len = strlen(string);
+ if (len == 0)
+ return 0;
+
+ for (size_t i = 0; i < len; i++)
+ if (!isdigit(string[i]))
+ return 0;
+
+ return 1;
} \ No newline at end of file
diff --git a/string-tick.h b/string-tick.h
index c360eba124a1..9825fd055ad4 100644
--- a/string-tick.h
+++ b/string-tick.h
@@ -111,4 +111,11 @@ void pointer_alloc_check(void* alloced);
*/
int is_string_json_array(const String* pString);
+/**
+ * Returns 1 if the string contains only digits or 0 otherwise
+ * @param string char*
+ * @return 1 is number, 0 if not
+ */
+int is_str_number(const char* string);
+
#endif \ No newline at end of file