summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-14 17:31:34 -0400
committerAnthony G. Basile <blueness@gentoo.org>2015-04-14 17:31:34 -0400
commit4b725bd2d38cbad1c490d22823f73c73ef3fc9df (patch)
treee9dbfa93b5ef064af87e03005a8f27ada56e23e9
parent119711f4e8f7dd47cb9abcdbde0023a4607e2dbf (diff)
util: when unescaping C escape sequences support C++11 \u and
\U unicode literals We simply recode them in utf8. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r--src/shared/utf8.c13
-rw-r--r--src/shared/utf8.h2
2 files changed, 9 insertions, 6 deletions
diff --git a/src/shared/utf8.c b/src/shared/utf8.c
index fec2f4df34..d59e07f3ee 100644
--- a/src/shared/utf8.c
+++ b/src/shared/utf8.c
@@ -50,7 +50,7 @@
#include "utf8.h"
#include "util.h"
-static inline bool is_unicode_valid(uint32_t ch) {
+bool unichar_is_valid(uint32_t ch) {
if (ch >= 0x110000) /* End of unicode space */
return false;
@@ -64,7 +64,7 @@ static inline bool is_unicode_valid(uint32_t ch) {
return true;
}
-static bool is_unicode_control(uint32_t ch) {
+static bool unichar_is_control(uint32_t ch) {
/*
0 to ' '-1 is the C0 range.
@@ -154,7 +154,7 @@ bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
val = utf8_encoded_to_unichar((const char*) p);
if (val < 0 ||
- is_unicode_control(val) ||
+ unichar_is_control(val) ||
(!newline && val == '\n'))
return false;
@@ -190,6 +190,7 @@ char *ascii_is_valid(const char *str) {
* occupy.
*/
size_t utf8_encode_unichar(char *out_utf8, uint32_t g) {
+
if (g < (1 << 7)) {
if (out_utf8)
out_utf8[0] = g & 0x7f;
@@ -215,9 +216,9 @@ size_t utf8_encode_unichar(char *out_utf8, uint32_t g) {
out_utf8[3] = 0x80 | (g & 0x3f);
}
return 4;
- } else {
- return 0;
}
+
+ return 0;
}
char *utf16_to_utf8(const void *s, size_t length) {
@@ -308,7 +309,7 @@ int utf8_encoded_valid_unichar(const char *str) {
return -EINVAL;
/* check if value has valid range */
- if (!is_unicode_valid(unichar))
+ if (!unichar_is_valid(unichar))
return -EINVAL;
return len;
diff --git a/src/shared/utf8.h b/src/shared/utf8.h
index 143b0ba08c..99a6304cf4 100644
--- a/src/shared/utf8.h
+++ b/src/shared/utf8.h
@@ -22,6 +22,8 @@
#include <stdbool.h>
#include "macro.h"
+
+bool unichar_is_valid(uint32_t c);
char *ascii_is_valid(const char *s) _pure_;