5#ifndef SPA_UTILS_STRING_H
6#define SPA_UTILS_STRING_H
23 #define SPA_API_STRING SPA_API_IMPL
25 #define SPA_API_STRING static inline
47 return SPA_LIKELY(s1 && s2) ? strcmp(s1, s2) == 0 : s1 == s2;
57 return SPA_LIKELY(s1 && s2) ? strncmp(s1, s2, len) == 0 : s1 == s2;
73 return strncmp(s, prefix, strlen(prefix)) == 0;
93 return l1 >= l2 &&
spa_streq(s + l1 - l2, suffix);
109 if (!str || *str ==
'\0')
113 v = strtol(str, &endptr, base);
114 if (errno != 0 || *endptr !=
'\0')
135 unsigned long long v;
137 if (!str || *str ==
'\0')
141 v = strtoull(str, &endptr, base);
142 if (errno != 0 || *endptr !=
'\0')
145 if (v != (uint32_t)v)
165 if (!str || *str ==
'\0')
169 v = strtoll(str, &endptr, base);
170 if (errno != 0 || *endptr !=
'\0')
188 unsigned long long v;
190 if (!str || *str ==
'\0')
194 v = strtoull(str, &endptr, base);
195 if (errno != 0 || *endptr !=
'\0')
267#ifndef __LOCALE_C_ONLY
268 static locale_t locale = NULL;
272#ifndef __LOCALE_C_ONLY
274 locale = newlocale(LC_ALL_MASK,
"C", NULL);
275 prev = uselocale(locale);
277 v = strtof(str, endptr);
278#ifndef __LOCALE_C_ONLY
296 if (!str || *str ==
'\0')
300 if (errno != 0 || *endptr !=
'\0')
317#ifndef __LOCALE_C_ONLY
318 static locale_t locale = NULL;
322#ifndef __LOCALE_C_ONLY
324 locale = newlocale(LC_ALL_MASK,
"C", NULL);
325 prev = uselocale(locale);
327 v = strtod(str, endptr);
328#ifndef __LOCALE_C_ONLY
346 if (!str || *str ==
'\0')
351 if (errno != 0 || *endptr !=
'\0')
362 for (i = 0; i < l; i++)
386 size_t remain = buf->maxsize - buf->pos;
390 written =
vsnprintf(&buf->buffer[buf->pos], remain, fmt,
args);
393 buf->pos +=
SPA_MIN(remain, (
size_t)written);
uint32_t int int const char va_list args
Definition core.h:434
vsnprintf(buffer, sizeof(buffer), message, args)
uint32_t int int const char int r
Definition core.h:447
SPA_API_STRING char * spa_dtoa(char *str, size_t size, double val)
Definition string.h:365
SPA_API_STRING int spa_strbuf_append(struct spa_strbuf *buf, const char *fmt,...)
Definition string.h:391
SPA_API_STRING 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:192
SPA_API_STRING bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition string.h:298
SPA_API_STRING void spa_strbuf_init(struct spa_strbuf *buf, char *buffer, size_t maxsize)
Definition string.h:381
SPA_API_STRING bool spa_strendswith(const char *s, const char *suffix)
Definition string.h:89
SPA_API_STRING bool spa_strstartswith(const char *s, const char *prefix)
Definition string.h:73
SPA_API_STRING bool spa_strneq(const char *s1, const char *s2, size_t len)
Definition string.h:62
SPA_API_STRING bool spa_atob(const char *str)
Convert str to a boolean.
Definition string.h:215
SPA_API_STRING 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:167
SPA_API_STRING 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:111
SPA_API_STRING int spa_vscnprintf(char *buffer, size_t size, const char *format, va_list args)
Definition string.h:229
SPA_API_STRING double spa_strtod(const char *str, char **endptr)
Convert str to a double in the C locale.
Definition string.h:322
SPA_API_STRING float spa_strtof(const char *str, char **endptr)
Convert str to a float in the C locale.
Definition string.h:272
SPA_API_STRING int spa_scnprintf(char *buffer, size_t size, const char *format,...)
Definition string.h:252
SPA_API_STRING bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition string.h:348
SPA_API_STRING 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:139
SPA_API_STRING bool spa_streq(const char *s1, const char *s2)
Definition string.h:52
#define SPA_MIN(a, b)
Definition defs.h:165
#define spa_assert_se(expr)
Definition defs.h:472
#define SPA_LIKELY(x)
Definition defs.h:396
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:297
#define SPA_UNLIKELY(x)
Definition defs.h:398
#define SPA_API_STRING
Definition string.h:32
size_t pos
Definition string.h:378
size_t maxsize
Definition string.h:377
char * buffer
Definition string.h:376