diff options
author | David Robillard <d@drobilla.net> | 2018-05-14 01:03:00 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-05-27 21:10:21 +0200 |
commit | dc9eaf381cb774ce9ddf57613e99fb7e381da041 (patch) | |
tree | 784c630908d43a6e07b8ae7606b487201f1d22a9 /src/reader.h | |
parent | 52d0ac81eee3462c6839c7374ffe57329f7702b7 (diff) | |
download | serd-dc9eaf381cb774ce9ddf57613e99fb7e381da041.tar.gz serd-dc9eaf381cb774ce9ddf57613e99fb7e381da041.tar.bz2 serd-dc9eaf381cb774ce9ddf57613e99fb7e381da041.zip |
Clean up error handling
Diffstat (limited to 'src/reader.h')
-rw-r--r-- | src/reader.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/reader.h b/src/reader.h index 3be55ab7..07313afd 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); @@ -121,20 +121,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 |