X-Git-Url: http://git.droids-corp.org/?p=protos%2Flibecoli.git;a=blobdiff_plain;f=include%2Fecoli_string.h;fp=include%2Fecoli_string.h;h=d611a13369e1c1fbe7334d46cb80eeacfa601a33;hp=a523b882e0d6dc3feaee81210c92f6d82d52fe5d;hb=a83942778fc85ad92db9082cf0d7c2d958d98aaf;hpb=e900ed6e1cb162855289bc7a9acc9b3d1af9d697 diff --git a/include/ecoli_string.h b/include/ecoli_string.h index a523b88..d611a13 100644 --- a/include/ecoli_string.h +++ b/include/ecoli_string.h @@ -7,6 +7,7 @@ #include #include +#include /* 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); +/** + * 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