aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-15 14:53:18 +0200
committerDavid Robillard <d@drobilla.net>2020-08-15 22:52:05 +0200
commit64f8675d5a18828494c53579f11ff443b41fda6e (patch)
treefbcaa292f822d4460ff832bb749628985ef779cf /src
parent907891c4f69a97299bef14bc64f417d009792795 (diff)
downloadserd-64f8675d5a18828494c53579f11ff443b41fda6e.tar.gz
serd-64f8675d5a18828494c53579f11ff443b41fda6e.tar.bz2
serd-64f8675d5a18828494c53579f11ff443b41fda6e.zip
Make read_UCHAR() and read_ECHAR() return a status
Diffstat (limited to 'src')
-rw-r--r--src/n3.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/n3.c b/src/n3.c
index ceb0894d..277ef198 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -59,7 +59,7 @@ read_HEX(SerdReader* reader)
}
// Read UCHAR escape, initial \ is already eaten by caller
-static inline bool
+static inline SerdStatus
read_UCHAR(SerdReader* reader, Ref dest, uint32_t* char_code)
{
const int b = peek_byte(reader);
@@ -72,14 +72,14 @@ read_UCHAR(SerdReader* reader, Ref dest, uint32_t* char_code)
length = 4;
break;
default:
- return false;
+ return SERD_ERR_BAD_SYNTAX;
}
eat_byte_safe(reader, b);
uint8_t buf[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (unsigned i = 0; i < length; ++i) {
if (!(buf[i] = read_HEX(reader))) {
- return false;
+ return SERD_ERR_BAD_SYNTAX;
}
}
@@ -101,7 +101,7 @@ read_UCHAR(SerdReader* reader, Ref dest, uint32_t* char_code)
"unicode character 0x%X out of range\n", code);
push_bytes(reader, dest, replacement_char, 3);
*char_code = 0xFFFD;
- return true;
+ return SERD_SUCCESS;
}
// Build output in buf
@@ -132,11 +132,11 @@ read_UCHAR(SerdReader* reader, Ref dest, uint32_t* char_code)
push_bytes(reader, dest, buf, size);
*char_code = code;
- return true;
+ return SERD_SUCCESS;
}
// Read ECHAR escape, initial \ is already eaten by caller
-static inline bool
+static inline SerdStatus
read_ECHAR(SerdReader* reader, Ref dest, SerdNodeFlags* flags)
{
const int c = peek_byte(reader);
@@ -144,30 +144,30 @@ read_ECHAR(SerdReader* reader, Ref dest, SerdNodeFlags* flags)
case 't':
eat_byte_safe(reader, 't');
push_byte(reader, dest, '\t');
- return true;
+ return SERD_SUCCESS;
case 'b':
eat_byte_safe(reader, 'b');
push_byte(reader, dest, '\b');
- return true;
+ return SERD_SUCCESS;
case 'n':
*flags |= SERD_HAS_NEWLINE;
eat_byte_safe(reader, 'n');
push_byte(reader, dest, '\n');
- return true;
+ return SERD_SUCCESS;
case 'r':
*flags |= SERD_HAS_NEWLINE;
eat_byte_safe(reader, 'r');
push_byte(reader, dest, '\r');
- return true;
+ return SERD_SUCCESS;
case 'f':
eat_byte_safe(reader, 'f');
push_byte(reader, dest, '\f');
- return true;
+ return SERD_SUCCESS;
case '\\': case '"': case '\'':
push_byte(reader, dest, eat_byte_safe(reader, c));
- return true;
+ return SERD_SUCCESS;
default:
- return false;
+ return SERD_ERR_BAD_SYNTAX;
}
}
@@ -322,9 +322,9 @@ read_STRING_LITERAL_LONG(SerdReader* reader, SerdNodeFlags* flags, uint8_t q)
if (c == '\\') {
eat_byte_safe(reader, c);
uint32_t code = 0;
- if (!read_ECHAR(reader, ref, flags) &&
- !read_UCHAR(reader, ref, &code)) {
- r_err(reader, SERD_ERR_BAD_SYNTAX,
+ if ((st = read_ECHAR(reader, ref, flags)) &&
+ (st = read_UCHAR(reader, ref, &code))) {
+ r_err(reader, st,
"invalid escape `\\%c'\n", peek_byte(reader));
return pop_node(reader, ref);
}
@@ -369,9 +369,9 @@ read_STRING_LITERAL(SerdReader* reader, SerdNodeFlags* flags, uint8_t q)
return pop_node(reader, ref);
case '\\':
eat_byte_safe(reader, c);
- if (!read_ECHAR(reader, ref, flags) &&
- !read_UCHAR(reader, ref, &code)) {
- r_err(reader, SERD_ERR_BAD_SYNTAX,
+ if ((st = read_ECHAR(reader, ref, flags)) &&
+ (st = read_UCHAR(reader, ref, &code))) {
+ r_err(reader, st,
"invalid escape `\\%c'\n", peek_byte(reader));
return pop_node(reader, ref);
}
@@ -693,8 +693,8 @@ read_IRIREF(SerdReader* reader)
case '>':
return ref;
case '\\':
- if (!read_UCHAR(reader, ref, &code)) {
- r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid IRI escape\n");
+ if ((st = read_UCHAR(reader, ref, &code))) {
+ r_err(reader, st, "invalid IRI escape\n");
return pop_node(reader, ref);
}
switch (code) {