25 #ifndef SPA_UTILS_STRING_H
26 #define SPA_UTILS_STRING_H
54 static inline bool spa_streq(
const char *s1,
const char *s2)
56 return SPA_LIKELY(s1 && s2) ? strcmp(s1, s2) == 0 : s1 == s2;
64 static inline bool spa_strneq(
const char *s1,
const char *s2,
size_t len)
66 return SPA_LIKELY(s1 && s2) ? strncmp(s1, s2, len) == 0 : s1 == s2;
82 return strncmp(s, prefix, strlen(prefix)) == 0;
102 return l1 >= l2 &&
spa_streq(s + l1 - l2, suffix);
113 static inline bool spa_atoi32(
const char *str, int32_t *val,
int base)
118 if (!str || *str ==
'\0')
122 v = strtol(str, &endptr, base);
123 if (errno != 0 || *endptr !=
'\0')
141 static inline bool spa_atou32(
const char *str, uint32_t *val,
int base)
144 unsigned long long v;
146 if (!str || *str ==
'\0')
150 v = strtoull(str, &endptr, base);
151 if (errno != 0 || *endptr !=
'\0')
154 if (v != (uint32_t)v)
169 static inline bool spa_atoi64(
const char *str, int64_t *val,
int base)
174 if (!str || *str ==
'\0')
178 v = strtoll(str, &endptr, base);
179 if (errno != 0 || *endptr !=
'\0')
194 static inline bool spa_atou64(
const char *str, uint64_t *val,
int base)
197 unsigned long long v;
199 if (!str || *str ==
'\0')
203 v = strtoull(str, &endptr, base);
204 if (errno != 0 || *endptr !=
'\0')
217 static inline bool spa_atob(
const char *str)
231 static inline
int spa_vscnprintf(
char *buffer,
size_t size, const
char *format, va_list args)
237 r = vsnprintf(buffer, size, format, args);
254 static inline
int spa_scnprintf(
char *buffer,
size_t size, const
char *format, ...)
259 va_start(args, format);
273 static inline bool spa_atof(
const char *str,
float *val)
278 if (!str || *str ==
'\0')
282 v = strtof(str, &endptr);
283 if (errno != 0 || *endptr !=
'\0')
297 static inline bool spa_atod(
const char *str,
double *val)
302 if (!str || *str ==
'\0')
306 v = strtod(str, &endptr);
307 if (errno != 0 || *endptr !=
'\0')
static bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:302
static 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:199
static bool spa_strstartswith(const char *s, const char *prefix)
Definition: string.h:80
static bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:222
static 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:174
static 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:146
static 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:118
static bool spa_strendswith(const char *s, const char *suffix)
Definition: string.h:96
static bool spa_strneq(const char *s1, const char *s2, size_t len)
Definition: string.h:69
static int spa_vscnprintf(char *buffer, size_t size, const char *format, va_list args)
Definition: string.h:236
static bool spa_streq(const char *s1, const char *s2)
Definition: string.h:59
static bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:278
static int spa_scnprintf(char *buffer, size_t size, const char *format,...)
Definition: string.h:259
#define spa_assert_se(expr)
Definition: defs.h:345
#define SPA_LIKELY(x)
Definition: defs.h:313
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
#define SPA_UNLIKELY(x)
Definition: defs.h:315