aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-14 01:03:00 +0200
committerDavid Robillard <d@drobilla.net>2018-12-31 11:37:47 -0500
commit12ef27529d86c581e7b38171fdcafd00cc691ef8 (patch)
tree23dc22d385e77527a9cb5c6b3a6d3fc195952a9c /src/reader.h
parent59f20cd25fe9adddc2072e98edf2e8981e1aae42 (diff)
downloadserd-12ef27529d86c581e7b38171fdcafd00cc691ef8.tar.gz
serd-12ef27529d86c581e7b38171fdcafd00cc691ef8.tar.bz2
serd-12ef27529d86c581e7b38171fdcafd00cc691ef8.zip
Clean up reader error handling
Diffstat (limited to 'src/reader.h')
-rw-r--r--src/reader.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/reader.h b/src/reader.h
index 259ef6bd..17aac125 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -68,7 +68,7 @@ struct SerdReaderImpl {
#endif
};
-int r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...);
+SerdStatus r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...);
SerdNode* push_node_padded(SerdReader* reader,
size_t maxlen,
@@ -85,9 +85,9 @@ size_t genid_size(SerdReader* reader);
SerdNode* blank_id(SerdReader* reader);
void set_blank_id(SerdReader* reader, SerdNode* node, size_t buf_size);
-bool emit_statement(SerdReader* reader, ReadContext ctx, SerdNode* o);
+SerdStatus emit_statement(SerdReader* reader, ReadContext ctx, SerdNode* o);
-bool read_n3_statement(SerdReader* reader);
+SerdStatus read_n3_statement(SerdReader* reader);
SerdStatus read_nquadsDoc(SerdReader* reader);
SerdStatus read_turtleTrigDoc(SerdReader* reader);
@@ -123,20 +123,22 @@ eat_byte_check(SerdReader* reader, const uint8_t byte)
{
const uint8_t c = peek_byte(reader);
if (c != byte) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX,
- "expected `%c', not `%c'\n", byte, c);
+ r_err(reader, SERD_ERR_BAD_SYNTAX,
+ "expected `%c', not `%c'\n", byte, c);
+ return 0;
}
return eat_byte_safe(reader, byte);
}
-static inline bool
+static inline SerdStatus
eat_string(SerdReader* reader, const char* str, unsigned n)
{
- bool bad = false;
for (unsigned i = 0; i < n; ++i) {
- bad |= (bool)eat_byte_check(reader, ((const uint8_t*)str)[i]);
+ if (!eat_byte_check(reader, ((const uint8_t*)str)[i])) {
+ return SERD_ERR_BAD_SYNTAX;
+ }
}
- return bad;
+ return SERD_SUCCESS;
}
static inline SerdStatus