aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-15 19:54:39 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit13f88f7b5da00b74e5a3e1061a29b5db47261486 (patch)
tree0335b9d6ee6c2f600b4aee0684f813b41be7bb24
parent02b3886278d5f6dfcc1f371faff6f6941b80097a (diff)
downloadserd-13f88f7b5da00b74e5a3e1061a29b5db47261486.tar.gz
serd-13f88f7b5da00b74e5a3e1061a29b5db47261486.tar.bz2
serd-13f88f7b5da00b74e5a3e1061a29b5db47261486.zip
Set flags directly when reading literal nodes
-rw-r--r--src/n3.c107
1 files changed, 43 insertions, 64 deletions
diff --git a/src/n3.c b/src/n3.c
index a6d8d801..f0ef162a 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -138,9 +138,7 @@ read_UCHAR(SerdReader* const reader,
// Read ECHAR escape, initial \ is already eaten by caller
static SerdStatus
-read_ECHAR(SerdReader* const reader,
- SerdNode* const dest,
- SerdNodeFlags* const flags)
+read_ECHAR(SerdReader* const reader, SerdNode* const dest)
{
SerdStatus st = SERD_SUCCESS;
const int c = peek_byte(reader);
@@ -150,10 +148,10 @@ read_ECHAR(SerdReader* const reader,
case 'b':
return (st = skip_byte(reader, 'b')) ? st : push_byte(reader, dest, '\b');
case 'n':
- *flags |= SERD_HAS_NEWLINE;
+ dest->flags |= SERD_HAS_NEWLINE;
return (st = skip_byte(reader, 'n')) ? st : push_byte(reader, dest, '\n');
case 'r':
- *flags |= SERD_HAS_NEWLINE;
+ dest->flags |= SERD_HAS_NEWLINE;
return (st = skip_byte(reader, 'r')) ? st : push_byte(reader, dest, '\r');
case 'f':
return (st = skip_byte(reader, 'f')) ? st : push_byte(reader, dest, '\f');
@@ -243,20 +241,17 @@ read_utf8_code(SerdReader* const reader,
// Read one character (possibly multi-byte)
// The first byte, c, has already been eaten by caller
static SerdStatus
-read_character(SerdReader* const reader,
- SerdNode* const dest,
- SerdNodeFlags* const flags,
- const uint8_t c)
+read_character(SerdReader* const reader, SerdNode* const dest, const uint8_t c)
{
if (!(c & 0x80)) {
switch (c) {
case 0xA:
case 0xD:
- *flags |= SERD_HAS_NEWLINE;
+ dest->flags |= SERD_HAS_NEWLINE;
break;
case '"':
case '\'':
- *flags |= SERD_HAS_QUOTE;
+ dest->flags |= SERD_HAS_QUOTE;
break;
default:
break;
@@ -327,14 +322,11 @@ eat_delim(SerdReader* const reader, const uint8_t delim)
}
static SerdStatus
-read_string_escape(SerdReader* const reader,
- SerdNode* const ref,
- SerdNodeFlags* const flags)
+read_string_escape(SerdReader* const reader, SerdNode* const ref)
{
SerdStatus st = SERD_SUCCESS;
uint32_t code = 0;
- if ((st = read_ECHAR(reader, ref, flags)) &&
- (st = read_UCHAR(reader, ref, &code))) {
+ if ((st = read_ECHAR(reader, ref)) && (st = read_UCHAR(reader, ref, &code))) {
return r_err(reader, st, "invalid escape '\\%c'\n", peek_byte(reader));
}
@@ -344,10 +336,9 @@ read_string_escape(SerdReader* const reader,
// STRING_LITERAL_LONG_QUOTE and STRING_LITERAL_LONG_SINGLE_QUOTE
// Initial triple quotes are already eaten by caller
static SerdStatus
-read_STRING_LITERAL_LONG(SerdReader* const reader,
- SerdNode* const ref,
- SerdNodeFlags* const flags,
- const uint8_t q)
+read_STRING_LITERAL_LONG(SerdReader* const reader,
+ SerdNode* const ref,
+ const uint8_t q)
{
SerdStatus st = SERD_SUCCESS;
@@ -355,7 +346,7 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
const int c = peek_byte(reader);
if (c == '\\') {
skip_byte(reader, c);
- st = read_string_escape(reader, ref, flags);
+ st = read_string_escape(reader, ref);
} else if (c == q) {
skip_byte(reader, q);
const int q2 = eat_byte_safe(reader, peek_byte(reader));
@@ -367,17 +358,16 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
if (q2 == '\\') {
push_byte(reader, ref, c);
- st = read_string_escape(reader, ref, flags);
+ st = read_string_escape(reader, ref);
} else {
- *flags |= SERD_HAS_QUOTE;
+ ref->flags |= SERD_HAS_QUOTE;
push_byte(reader, ref, c);
- st = read_character(reader, ref, flags, (uint8_t)q2);
+ st = read_character(reader, ref, (uint8_t)q2);
}
} else if (c == EOF) {
st = r_err(reader, SERD_BAD_SYNTAX, "end of file in long string\n");
} else {
- st =
- read_character(reader, ref, flags, (uint8_t)eat_byte_safe(reader, c));
+ st = read_character(reader, ref, (uint8_t)eat_byte_safe(reader, c));
}
}
@@ -387,10 +377,9 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
// STRING_LITERAL_QUOTE and STRING_LITERAL_SINGLE_QUOTE
// Initial quote is already eaten by caller
static SerdStatus
-read_STRING_LITERAL(SerdReader* const reader,
- SerdNode* const ref,
- SerdNodeFlags* const flags,
- const uint8_t q)
+read_STRING_LITERAL(SerdReader* const reader,
+ SerdNode* const ref,
+ const uint8_t q)
{
SerdStatus st = SERD_SUCCESS;
@@ -404,15 +393,14 @@ read_STRING_LITERAL(SerdReader* const reader,
return r_err(reader, SERD_BAD_SYNTAX, "line end in short string\n");
case '\\':
skip_byte(reader, c);
- TRY(st, read_string_escape(reader, ref, flags));
+ TRY(st, read_string_escape(reader, ref));
break;
default:
if (c == q) {
return skip_byte(reader, c);
}
- st =
- read_character(reader, ref, flags, (uint8_t)eat_byte_safe(reader, c));
+ st = read_character(reader, ref, (uint8_t)eat_byte_safe(reader, c));
}
}
@@ -420,9 +408,7 @@ read_STRING_LITERAL(SerdReader* const reader,
}
static SerdStatus
-read_String(SerdReader* const reader,
- SerdNode* const node,
- SerdNodeFlags* const flags)
+read_String(SerdReader* const reader, SerdNode* const node)
{
const int q1 = eat_byte_safe(reader, peek_byte(reader));
const int q2 = peek_byte(reader);
@@ -431,7 +417,7 @@ read_String(SerdReader* const reader,
}
if (q2 != q1) { // Short string (not triple quoted)
- return read_STRING_LITERAL(reader, node, flags, (uint8_t)q1);
+ return read_STRING_LITERAL(reader, node, (uint8_t)q1);
}
skip_byte(reader, q2);
@@ -450,7 +436,7 @@ read_String(SerdReader* const reader,
}
skip_byte(reader, q3);
- return read_STRING_LITERAL_LONG(reader, node, flags, (uint8_t)q1);
+ return read_STRING_LITERAL_LONG(reader, node, (uint8_t)q1);
}
static bool
@@ -840,10 +826,9 @@ read_0_9(SerdReader* const reader, SerdNode* const str, const bool at_least_one)
}
static SerdStatus
-read_number(SerdReader* const reader,
- SerdNode** const dest,
- SerdNodeFlags* const flags,
- bool* const ate_dot)
+read_number(SerdReader* const reader,
+ SerdNode** const dest,
+ bool* const ate_dot)
{
#define XSD_DECIMAL NS_XSD "decimal"
#define XSD_DOUBLE NS_XSD "double"
@@ -902,14 +887,15 @@ read_number(SerdReader* const reader,
}
TRY(st, read_0_9(reader, *dest, true));
meta = push_node(reader, SERD_URI, XSD_DOUBLE, sizeof(XSD_DOUBLE) - 1);
- *flags |= SERD_HAS_DATATYPE;
+ (*dest)->flags |= SERD_HAS_DATATYPE;
} else if (has_decimal) {
meta = push_node(reader, SERD_URI, XSD_DECIMAL, sizeof(XSD_DECIMAL) - 1);
+ (*dest)->flags |= SERD_HAS_DATATYPE;
} else {
meta = push_node(reader, SERD_URI, XSD_INTEGER, sizeof(XSD_INTEGER) - 1);
}
- *flags |= SERD_HAS_DATATYPE;
+ (*dest)->flags |= SERD_HAS_DATATYPE;
return meta ? SERD_SUCCESS : SERD_BAD_STACK;
}
@@ -928,14 +914,13 @@ read_iri(SerdReader* const reader, SerdNode** const dest, bool* const ate_dot)
}
static SerdStatus
-read_literal(SerdReader* const reader,
- SerdNode** const dest,
- SerdNodeFlags* const flags,
- bool* const ate_dot)
+read_literal(SerdReader* const reader,
+ SerdNode** const dest,
+ bool* const ate_dot)
{
*dest = push_node(reader, SERD_LITERAL, "", 0);
- SerdStatus st = read_String(reader, *dest, flags);
+ SerdStatus st = read_String(reader, *dest);
if (st) {
*dest = NULL;
return st;
@@ -945,7 +930,7 @@ read_literal(SerdReader* const reader,
switch (peek_byte(reader)) {
case '@':
skip_byte(reader, '@');
- *flags |= SERD_HAS_LANGUAGE;
+ (*dest)->flags |= SERD_HAS_LANGUAGE;
if ((st = read_LANGTAG(reader))) {
return r_err(reader, st, "bad literal\n");
}
@@ -956,7 +941,7 @@ read_literal(SerdReader* const reader,
return r_err(reader, SERD_BAD_SYNTAX, "expected '^'\n");
}
- *flags |= SERD_HAS_DATATYPE;
+ (*dest)->flags |= SERD_HAS_DATATYPE;
if ((st = read_iri(reader, &datatype, ate_dot))) {
return r_err(reader, st, "bad datatype\n");
}
@@ -1126,12 +1111,10 @@ read_object(SerdReader* const reader,
const size_t orig_stack_size = reader->stack.size;
- SerdStatus st = SERD_FAILURE;
-
- bool simple = (ctx->subject != 0);
- SerdNode* o = 0;
- uint32_t flags = 0;
- const int c = peek_byte(reader);
+ SerdStatus st = SERD_FAILURE;
+ bool simple = (ctx->subject != 0);
+ SerdNode* o = 0;
+ const int c = peek_byte(reader);
if (!fancy_syntax(reader)) {
switch (c) {
case '"':
@@ -1175,11 +1158,11 @@ read_object(SerdReader* const reader,
case '7':
case '8':
case '9':
- st = read_number(reader, &o, &flags, ate_dot);
+ st = read_number(reader, &o, ate_dot);
break;
case '\"':
case '\'':
- st = read_literal(reader, &o, &flags, ate_dot);
+ st = read_literal(reader, &o, ate_dot);
break;
default:
/* Either a boolean literal, or a qname. Read the prefix first, and if
@@ -1193,7 +1176,7 @@ read_object(SerdReader* const reader,
}
if ((o->length == 4 && !memcmp(serd_node_string(o), "true", 4)) ||
(o->length == 5 && !memcmp(serd_node_string(o), "false", 5))) {
- flags = flags | SERD_HAS_DATATYPE;
+ o->flags |= SERD_HAS_DATATYPE;
o->type = SERD_LITERAL;
push_node(reader, SERD_URI, XSD_BOOLEAN, XSD_BOOLEAN_LEN);
st = SERD_SUCCESS;
@@ -1207,10 +1190,6 @@ read_object(SerdReader* const reader,
}
}
- if (!st && simple && o) {
- o->flags = flags;
- }
-
if (!st && emit && simple && o) {
st = emit_statement(reader, *ctx, o);
} else if (!st && !emit) {