25 #ifndef SPA_UTILS_STRING_H
26 #define SPA_UTILS_STRING_H
50 inline bool spa_streq(
const char *s1,
const char *s2)
52 return SPA_LIKELY(s1 && s2) ? strcmp(s1, s2) == 0 : s1 == s2;
60 inline bool spa_strneq(
const char *s1,
const char *s2,
size_t len)
62 return SPA_LIKELY(s1 && s2) ? strncmp(s1, s2, len) == 0 : s1 == s2;
82 return l1 >= l2 &&
spa_streq(s + l1 - l2, suffix);
93 inline bool spa_atoi32(
const char *str, int32_t *val,
int base)
98 if (!str || *str ==
'\0')
102 v = strtol(str, &endptr, base);
103 if (errno != 0 || *endptr !=
'\0')
121 inline bool spa_atou32(
const char *str, uint32_t *val,
int base)
124 unsigned long long v;
126 if (!str || *str ==
'\0')
130 v = strtoull(str, &endptr, base);
131 if (errno != 0 || *endptr !=
'\0')
134 if (v != (uint32_t)v)
149 inline bool spa_atoi64(
const char *str, int64_t *val,
int base)
154 if (!str || *str ==
'\0')
158 v = strtoll(str, &endptr, base);
159 if (errno != 0 || *endptr !=
'\0')
174 inline bool spa_atou64(
const char *str, uint64_t *val,
int base)
177 unsigned long long v;
179 if (!str || *str ==
'\0')
183 v = strtoull(str, &endptr, base);
184 if (errno != 0 || *endptr !=
'\0')
258 if (!str || *str ==
'\0')
262 v = strtof(str, &endptr);
263 if (errno != 0 || *endptr !=
'\0')
282 if (!str || *str ==
'\0')
286 v = strtod(str, &endptr);
287 if (errno != 0 || *endptr !=
'\0')
static uint32_t int int const char va_list args
Definition: core.h:330
vsnprintf(buffer, sizeof(buffer), message, args)
static uint32_t int int const char int r
Definition: core.h:341
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:93
int spa_scnprintf(char *buffer, size_t size, const char *format,...)
"Safe" version of snprintf.
Definition: string.h:234
bool spa_strneq(const char *s1, const char *s2, size_t len)
Definition: string.h:60
bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:277
bool spa_streq(const char *s1, const char *s2)
Definition: string.h:50
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:121
int spa_vscnprintf(char *buffer, size_t size, const char *format, va_list args)
"Safe" version of vsnprintf.
Definition: string.h:211
bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:253
bool spa_strendswith(const char *s, const char *suffix)
Definition: string.h:71
#define SPA_LIKELY(x)
Definition: defs.h:234
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:205
bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:197
#define SPA_UNLIKELY(x)
Definition: defs.h:235
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:174
#define spa_assert(expr)
Definition: defs.h:288
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:149