summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/core-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-08-09 03:46:23 +0200
committerLennart Poettering <lennart@poettering.net>2008-08-09 03:46:23 +0200
commit9cf1a4e5c4e319c34c1eef722162c0d67997e312 (patch)
tree7d9324942d7dd9f60b3d35fd16b6d743d1e286ea /src/pulsecore/core-util.c
parentc4d32ec8048075c7ccd979594b041335ebbcd51d (diff)
add locale support to pa_parse_boolean()
Diffstat (limited to 'src/pulsecore/core-util.c')
-rw-r--r--src/pulsecore/core-util.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index b2c91e45..dcceec90 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -40,6 +40,8 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <dirent.h>
+#include <regex.h>
+#include <langinfo.h>
#ifdef HAVE_STRTOF_L
#include <locale.h>
@@ -679,15 +681,48 @@ void pa_reset_priority(void) {
#endif
}
+static int match(const char *expr, const char *v) {
+ int k;
+ regex_t re;
+
+ if (regcomp(&re, expr, REG_NOSUB|REG_EXTENDED) != 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if ((k = regexec(&re, v, 0, NULL, 0)) == 0)
+ return 1;
+ else if (k == REG_NOMATCH)
+ return 0;
+
+ errno = EINVAL;
+ return -1;
+}
+
/* Try to parse a boolean string value.*/
int pa_parse_boolean(const char *v) {
+ const char *expr;
+ int r;
pa_assert(v);
+ /* First we check language independant */
if (!strcmp(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
return 1;
else if (!strcmp(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
return 0;
+ /* And then we check language dependant */
+ if ((expr = nl_langinfo(YESEXPR)))
+ if (expr[0])
+ if ((r = match(expr, v)) > 0)
+ return 1;
+
+ if ((expr = nl_langinfo(NOEXPR)))
+ if (expr[0])
+ if ((r = match(expr, v)) > 0)
+ return 0;
+
+ errno = EINVAL;
return -1;
}