Update UTF-8 base code

UTF-8 encodes characters in one to four bytes (since 2003).

Because 0 is a valid code point, the decode function utf8_ord()
should return -1, not 0, on error. As a consequence utf8_width()
should return 0 for a continuation byte (as it did previously).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen
2017-11-29 22:19:10 +01:00
committed by Lukas Fleischer
parent edc44d613b
commit 95c5d576fa
2 changed files with 11 additions and 23 deletions

View File

@@ -225,13 +225,10 @@
#define TOSTRING(x) STRINGIFY(x)
#define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__)
#define UTF8_MAXLEN 6
#define UTF8_LENGTH(ch) ((unsigned char)ch >= 0xFC ? 6 : \
((unsigned char)ch >= 0xF8 ? 5 : \
((unsigned char)ch >= 0xF0 ? 4 : \
#define UTF8_MAXLEN 4
#define UTF8_LENGTH(ch) ((unsigned char)ch >= 0xF0 ? 4 : \
((unsigned char)ch >= 0xE0 ? 3 : \
((unsigned char)ch >= 0xC0 ? 2 : 1)))))
#define UTF8_ISMULTI(ch) ((unsigned char)ch >= 0x80)
((unsigned char)ch >= 0xC0 ? 2 : 1)))
#define UTF8_ISCONT(ch) ((unsigned char)ch >= 0x80 && \
(unsigned char)ch <= 0xBF)