utf8.[ch] et al: use char32_t and char16_t instead of int, int32_t, int16_t

rework C11 utf8.[ch] to use char32_t instead of uint32_t when referring
to unicode chars, to make things more expressive.

[
 @zonque:
  * rebased to current master
  * use AC_CHECK_DECLS to detect availibility of char{16,32}_t
  * make utf8_encoded_to_unichar() return int
]
This commit is contained in:
Shawn Landden
2015-12-13 14:26:43 -08:00
committed by Daniel Mack
parent 9766c16bd0
commit c932fb71cc
9 changed files with 66 additions and 42 deletions

View File

@@ -450,6 +450,7 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
char *e;
const char *i, *j;
unsigned k, len, len2;
int r;
assert(s);
assert(percent <= 100);
@@ -469,10 +470,10 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
k = 0;
for (i = s; k < x && i < s + old_length; i = utf8_next_char(i)) {
int c;
char32_t c;
c = utf8_encoded_to_unichar(i);
if (c < 0)
r = utf8_encoded_to_unichar(i, &c);
if (r < 0)
return NULL;
k += unichar_iswide(c) ? 2 : 1;
}
@@ -481,11 +482,11 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
x ++;
for (j = s + old_length; k < new_length && j > i; ) {
int c;
char32_t c;
j = utf8_prev_char(j);
c = utf8_encoded_to_unichar(j);
if (c < 0)
r = utf8_encoded_to_unichar(j, &c);
if (r < 0)
return NULL;
k += unichar_iswide(c) ? 2 : 1;
}