aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-07-09 20:09:36 +0200
committerDavid Robillard <d@drobilla.net>2017-07-10 12:06:56 +0200
commit9c29938c172e2423f67925274a18b4f1c1bb42cf (patch)
treef75ce11c9827ef51c570646b4146793b17f70c90 /src/reader.c
parent4d535bbe0390ed4f03c611e433145c9e49cbf3ad (diff)
downloadserd-9c29938c172e2423f67925274a18b4f1c1bb42cf.tar.gz
serd-9c29938c172e2423f67925274a18b4f1c1bb42cf.tar.bz2
serd-9c29938c172e2423f67925274a18b4f1c1bb42cf.zip
Factor out UTF-8 character size counting
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/reader.c b/src/reader.c
index dd7fa8b2..91e0e920 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -409,14 +409,8 @@ bad_char(SerdReader* reader, Ref dest, const char* fmt, uint8_t c)
static SerdStatus
read_utf8_character(SerdReader* reader, Ref dest, uint8_t c)
{
- unsigned size = 1;
- if ((c & 0xE0) == 0xC0) { // Starts with `110'
- size = 2;
- } else if ((c & 0xF0) == 0xE0) { // Starts with `1110'
- size = 3;
- } else if ((c & 0xF8) == 0xF0) { // Starts with `11110'
- size = 4;
- } else {
+ const uint32_t size = utf8_num_bytes(c);
+ if (size <= 1 || size > 4) {
return bad_char(reader, dest, "invalid UTF-8 start 0x%X\n", c);
}