25 #ifndef SPA_UTILS_STRING_H 26 #define SPA_UTILS_STRING_H 49 inline bool spa_streq(
const char *s1,
const char *s2)
51 return SPA_LIKELY(s1 && s2) ? strcmp(s1, s2) == 0 : s1 == s2;
59 inline bool spa_strneq(
const char *s1,
const char *s2,
size_t len)
61 return SPA_LIKELY(s1 && s2) ? strncmp(s1, s2, len) == 0 : s1 == s2;
72 inline bool spa_atoi32(
const char *str, int32_t *val,
int base)
77 if (!str || *str ==
'\0')
81 v = strtol(str, &endptr, base);
82 if (errno != 0 || *endptr !=
'\0')
100 inline bool spa_atou32(
const char *str, uint32_t *val,
int base)
103 unsigned long long v;
105 if (!str || *str ==
'\0')
109 v = strtoull(str, &endptr, base);
110 if (errno != 0 || *endptr !=
'\0')
113 if (v != (uint32_t)v)
128 inline bool spa_atoi64(
const char *str, int64_t *val,
int base)
133 if (!str || *str ==
'\0')
137 v = strtoll(str, &endptr, base);
138 if (errno != 0 || *endptr !=
'\0')
153 inline bool spa_atou64(
const char *str, uint64_t *val,
int base)
156 unsigned long long v;
158 if (!str || *str ==
'\0')
162 v = strtoull(str, &endptr, base);
163 if (errno != 0 || *endptr !=
'\0')
193 if (!str || *str ==
'\0')
197 v = strtof(str, &endptr);
198 if (errno != 0 || *endptr !=
'\0')
217 if (!str || *str ==
'\0')
221 v = strtod(str, &endptr);
222 if (errno != 0 || *endptr !=
'\0')
bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:188
#define SPA_LIKELY(x)
Definition: defs.h:231
bool spa_atou32(const char *str, uint32_t *val, int base)
Convert str to an uint32_t with the given base and store the result in val.
Definition: string.h:100
bool spa_strneq(const char *s1, const char *s2, size_t len)
Definition: string.h:59
bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:176
bool spa_streq(const char *s1, const char *s2)
Definition: string.h:49
bool spa_atoi32(const char *str, int32_t *val, int base)
Convert str to an int32_t with the given base and store the result in val.
Definition: string.h:72
bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:212
bool spa_atoi64(const char *str, int64_t *val, int base)
Convert str to an int64_t with the given base and store the result in val.
Definition: string.h:128
bool spa_atou64(const char *str, uint64_t *val, int base)
Convert str to an uint64_t with the given base and store the result in val.
Definition: string.h:153