X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=include%2Fecoli_string.h;h=3ef022cb9e5864d59403b87c7a05e54ccfcb67dc;hb=70ebe6bd8740d8cb32cd0b0a21ca28a4fa74a2a5;hp=a523b882e0d6dc3feaee81210c92f6d82d52fe5d;hpb=18d03456d96f7a086a2ccc82ce97fcf056848d90;p=protos%2Flibecoli.git diff --git a/include/ecoli_string.h b/include/ecoli_string.h index a523b88..3ef022c 100644 --- a/include/ecoli_string.h +++ b/include/ecoli_string.h @@ -2,11 +2,19 @@ * Copyright 2016, Olivier MATZ */ +/** + * @defgroup string String + * @{ + * + * @brief Helpers for strings manipulation. + */ + #ifndef ECOLI_STRING_ #define ECOLI_STRING_ #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 +31,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