factorize integer parsing
[protos/libecoli.git] / include / ecoli_string.h
index a523b88..d611a13 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <stddef.h>
 #include <stdbool.h>
 
 #include <stddef.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 /* count the number of identical chars at the beginning of 2 strings */
 size_t ec_strcmp_count(const char *s1, const char *s2);
 
 /* count the number of identical chars at the beginning of 2 strings */
 size_t ec_strcmp_count(const char *s1, const char *s2);
@@ -23,4 +24,41 @@ int ec_vasprintf(char **buf, const char *fmt, va_list ap);
 /* return true if string is only composed of spaces (' ', '\n', ...) */
 bool ec_str_is_space(const char *s);
 
 /* return true if string is only composed of spaces (' ', '\n', ...) */
 bool ec_str_is_space(const char *s);
 
+/**
+ * Parse a string for a signed integer.
+ *
+ * @param str
+ *   The string to parse.
+ * @param base
+ *   The base (0 means "guess").
+ * @param min
+ *   The minimum allowed value.
+ * @param max
+ *   The maximum allowed value.
+ * @param val
+ *   The pointer to the value to be set on success.
+ * @return
+ *   On success, return 0. Else, return -1 and set errno.
+ */
+int ec_str_parse_llint(const char *str, unsigned int base, int64_t min,
+               int64_t max, int64_t *val);
+
+/**
+ * Parse a string for an unsigned integer.
+ *
+ * @param str
+ *   The string to parse.
+ * @param base
+ *   The base (0 means "guess").
+ * @param min
+ *   The minimum allowed value.
+ * @param max
+ *   The maximum allowed value.
+ * @param val
+ *   The pointer to the value to be set on success.
+ * @return
+ *   On success, return 0. Else, return -1 and set errno.
+ */
+int ec_str_parse_ullint(const char *str, unsigned int base, uint64_t min,
+                       uint64_t max, uint64_t *val);
 #endif
 #endif