summaryrefslogtreecommitdiff
path: root/src/basic/utf8.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/utf8.c')
-rw-r--r--src/basic/utf8.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/basic/utf8.c b/src/basic/utf8.c
index cc041d5b34..7600d99903 100644
--- a/src/basic/utf8.c
+++ b/src/basic/utf8.c
@@ -54,7 +54,7 @@
#include "utf8.h"
#include "util.h"
-bool unichar_is_valid(char32_t ch) {
+bool unichar_is_valid(uint32_t ch) {
if (ch >= 0x110000) /* End of unicode space */
return false;
@@ -68,7 +68,7 @@ bool unichar_is_valid(char32_t ch) {
return true;
}
-static bool unichar_is_control(char32_t ch) {
+static bool unichar_is_control(uint32_t ch) {
/*
0 to ' '-1 is the C0 range.
@@ -104,9 +104,8 @@ static int utf8_encoded_expected_len(const char *str) {
}
/* decode one unicode char */
-char32_t utf8_encoded_to_unichar(const char *str) {
- char32_t unichar;
- int len, i;
+int utf8_encoded_to_unichar(const char *str) {
+ int unichar, len, i;
assert(str);
@@ -114,31 +113,31 @@ char32_t utf8_encoded_to_unichar(const char *str) {
switch (len) {
case 1:
- return (char32_t)str[0];
+ return (int)str[0];
case 2:
unichar = str[0] & 0x1f;
break;
case 3:
- unichar = (char32_t)str[0] & 0x0f;
+ unichar = (int)str[0] & 0x0f;
break;
case 4:
- unichar = (char32_t)str[0] & 0x07;
+ unichar = (int)str[0] & 0x07;
break;
case 5:
- unichar = (char32_t)str[0] & 0x03;
+ unichar = (int)str[0] & 0x03;
break;
case 6:
- unichar = (char32_t)str[0] & 0x01;
+ unichar = (int)str[0] & 0x01;
break;
default:
return -EINVAL;
}
for (i = 1; i < len; i++) {
- if (((char32_t)str[i] & 0xc0) != 0x80)
+ if (((int)str[i] & 0xc0) != 0x80)
return -EINVAL;
unichar <<= 6;
- unichar |= (char32_t)str[i] & 0x3f;
+ unichar |= (int)str[i] & 0x3f;
}
return unichar;
@@ -150,8 +149,7 @@ bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
assert(str);
for (p = str; length;) {
- int encoded_len;
- char32_t val;
+ int encoded_len, val;
encoded_len = utf8_encoded_valid_unichar(p);
if (encoded_len < 0 ||
@@ -279,7 +277,7 @@ char *ascii_is_valid(const char *str) {
* Returns: The length in bytes that the UTF-8 representation does or would
* occupy.
*/
-size_t utf8_encode_unichar(char *out_utf8, char32_t g) {
+size_t utf8_encode_unichar(char *out_utf8, uint32_t g) {
if (g < (1 << 7)) {
if (out_utf8)
@@ -323,7 +321,7 @@ char *utf16_to_utf8(const void *s, size_t length) {
t = r;
while (f < (const uint8_t*) s + length) {
- char16_t w1, w2;
+ uint16_t w1, w2;
/* see RFC 2781 section 2.2 */
@@ -331,7 +329,7 @@ char *utf16_to_utf8(const void *s, size_t length) {
f += 2;
if (!utf16_is_surrogate(w1)) {
- t += utf8_encode_unichar(t, (char32_t) w1);
+ t += utf8_encode_unichar(t, w1);
continue;
}
@@ -375,8 +373,7 @@ static int utf8_unichar_to_encoded_len(int unichar) {
/* validate one encoded unicode char and return its length */
int utf8_encoded_valid_unichar(const char *str) {
- int len, i;
- char32_t unichar;
+ int len, unichar, i;
assert(str);