aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-15 18:22:12 +0200
committerDavid Robillard <d@drobilla.net>2020-08-15 22:53:00 +0200
commit7221394ae12f87533261ecaae725821fab6db40d (patch)
treeb19440b7ce7552c1ecc94c9f02bc99ec128dc65e /src/reader.h
parent8cfbb485d367c861f20aa51261f4b41e78b144b6 (diff)
downloadserd-7221394ae12f87533261ecaae725821fab6db40d.tar.gz
serd-7221394ae12f87533261ecaae725821fab6db40d.tar.bz2
serd-7221394ae12f87533261ecaae725821fab6db40d.zip
Clean up reader error handling
Diffstat (limited to 'src/reader.h')
-rw-r--r--src/reader.h25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/reader.h b/src/reader.h
index dfc0f680..69e632e8 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -72,7 +72,6 @@ struct SerdReaderImpl {
SerdStack stack;
SerdSyntax syntax;
unsigned next_id;
- SerdStatus status;
uint8_t* buf;
uint8_t* bprefix;
size_t bprefix_len;
@@ -107,11 +106,12 @@ SerdNode* deref(SerdReader* reader, Ref ref);
Ref pop_node(SerdReader* reader, Ref ref);
-bool emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l);
+SerdStatus
+emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l);
-bool read_n3_statement(SerdReader* reader);
-bool read_nquadsDoc(SerdReader* reader);
-bool read_turtleTrigDoc(SerdReader* reader);
+SerdStatus read_n3_statement(SerdReader* reader);
+SerdStatus read_nquadsDoc(SerdReader* reader);
+SerdStatus read_turtleTrigDoc(SerdReader* reader);
static inline int
peek_byte(SerdReader* reader)
@@ -126,10 +126,8 @@ eat_byte(SerdReader* reader)
{
const int c = peek_byte(reader);
const SerdStatus st = serd_byte_source_advance(&reader->source);
- if (st) {
- reader->status = st;
- }
- return c;
+
+ return st > SERD_FAILURE ? EOF : c;
}
static inline int
@@ -154,14 +152,15 @@ eat_byte_check(SerdReader* reader, const int byte)
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