summaryrefslogtreecommitdiff
path: root/src/core/utf8.c
diff options
context:
space:
mode:
authorXavier G <xavier.github@kindwolf.org>2016-05-13 02:10:02 +0200
committerXavier G <xavier.github@kindwolf.org>2016-05-13 02:10:02 +0200
commit2c8648a9c889fc0a7c4b24367a3f81f08dedccb2 (patch)
tree40b589aa69d286cdce41778f05115a64861d0c0b /src/core/utf8.c
parentb0afcc96dbc13cf3a5ed94686bb227ab0d86ceaa (diff)
downloadirssi-2c8648a9c889fc0a7c4b24367a3f81f08dedccb2.zip
Introduce string_policy().
Diffstat (limited to 'src/core/utf8.c')
-rw-r--r--src/core/utf8.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/core/utf8.c b/src/core/utf8.c
index 1daaf03f..d931ba19 100644
--- a/src/core/utf8.c
+++ b/src/core/utf8.c
@@ -25,6 +25,8 @@
#include "utf8.h"
#include "module.h"
#include "wcwidth.c"
+/* Provide is_utf8(): */
+#include "recode.h"
int string_advance(char const **str, gboolean utf8)
{
@@ -41,3 +43,14 @@ int string_advance(char const **str, gboolean utf8)
return 1;
}
}
+
+int string_policy(const char *str)
+{
+ if (is_utf8()) {
+ if (!str || g_utf8_validate(str, -1, NULL)) {
+ /* No string provided or valid UTF-8 string: treat as UTF-8: */
+ return TREAT_STRING_AS_UTF8;
+ }
+ }
+ return TREAT_STRING_AS_BYTES;
+}