aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-31 10:50:12 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commitd22653dfe356e3da1354cdb0f7915e29c4a33e3b (patch)
tree496e678ba61a436e2bf0b11b079bf6115ba630fa /src/reader.c
parent469034ec4ae5c0b5230ca30c40aaa9b1432c13a2 (diff)
downloadserd-d22653dfe356e3da1354cdb0f7915e29c4a33e3b.tar.gz
serd-d22653dfe356e3da1354cdb0f7915e29c4a33e3b.tar.bz2
serd-d22653dfe356e3da1354cdb0f7915e29c4a33e3b.zip
Factor out NTriples reader
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/reader.c b/src/reader.c
index 7eb2323e..057f1d7f 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -6,6 +6,7 @@
#include "byte_source.h"
#include "namespaces.h"
#include "node.h"
+#include "read_ntriples.h"
#include "stack.h"
#include "statement.h"
#include "system.h"
@@ -36,6 +37,29 @@ r_err(SerdReader* const reader, const SerdStatus st, const char* const fmt, ...)
return st;
}
+SerdStatus
+skip_horizontal_whitespace(SerdReader* const reader)
+{
+ while (peek_byte(reader) == '\t' || peek_byte(reader) == ' ') {
+ eat_byte(reader);
+ }
+
+ return SERD_SUCCESS;
+}
+
+SerdStatus
+serd_reader_skip_until_byte(SerdReader* const reader, const uint8_t byte)
+{
+ int c = peek_byte(reader);
+
+ while (c != byte && c != EOF) {
+ skip_byte(reader, c);
+ c = peek_byte(reader);
+ }
+
+ return c == EOF ? SERD_FAILURE : SERD_SUCCESS;
+}
+
void
set_blank_id(SerdReader* const reader,
SerdNode* const node,
@@ -152,15 +176,27 @@ serd_reader_read_document(SerdReader* const reader)
{
assert(reader);
- if (!reader->source.prepared) {
+ if (reader->syntax != SERD_SYNTAX_EMPTY && !reader->source.prepared) {
SerdStatus st = serd_reader_prepare(reader);
if (st) {
return st;
}
}
- return ((reader->syntax == SERD_NQUADS) ? read_nquadsDoc(reader)
- : read_turtleTrigDoc(reader));
+ switch (reader->syntax) {
+ case SERD_SYNTAX_EMPTY:
+ break;
+ case SERD_TURTLE:
+ return read_turtleTrigDoc(reader);
+ case SERD_NTRIPLES:
+ return read_ntriplesDoc(reader);
+ case SERD_NQUADS:
+ return read_nquadsDoc(reader);
+ case SERD_TRIG:
+ return read_turtleTrigDoc(reader);
+ }
+
+ return SERD_SUCCESS;
}
SerdReader*