diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/inserter.c | 7 | ||||
-rw-r--r-- | src/read_turtle.c | 29 | ||||
-rw-r--r-- | src/writer.c | 26 |
3 files changed, 50 insertions, 12 deletions
diff --git a/src/inserter.c b/src/inserter.c index f3b8631b..13af697e 100644 --- a/src/inserter.c +++ b/src/inserter.c @@ -45,6 +45,13 @@ can_insert(SerdWorld* const world, const SerdNode* const node) } break; + case SERD_CURIE: + serd_logf(world, + SERD_LOG_LEVEL_ERROR, + "attempt to insert CURIE %s into model", + serd_node_string(node)); + return false; + case SERD_BLANK: case SERD_VARIABLE: break; diff --git a/src/read_turtle.c b/src/read_turtle.c index e8e57dfc..6457d608 100644 --- a/src/read_turtle.c +++ b/src/read_turtle.c @@ -393,18 +393,23 @@ read_PrefixedName(SerdReader* const reader, skip_byte(reader, ':'); - // Search environment for the prefix URI - const ZixStringView prefix = serd_node_string_view(dest); - const ZixStringView prefix_uri = serd_env_find_prefix(reader->env, prefix); - if (!prefix_uri.length) { - return r_err(reader, st, "unknown prefix \"%s\"", prefix.data); - } - - // Pop back to the start of the string - serd_stack_pop_to(&reader->stack, string_start_offset); - dest->length = 0U; - dest->type = SERD_URI; - push_bytes(reader, dest, (const uint8_t*)prefix_uri.data, prefix_uri.length); + if ((reader->flags & SERD_READ_CURIES)) { + dest->type = SERD_CURIE; + } else { + // Search environment for the prefix URI + const ZixStringView name = serd_node_string_view(dest); + const ZixStringView uri = serd_env_find_prefix(reader->env, name); + if (!uri.length) { + return r_err(reader, st, "unknown prefix \"%s\"", name.data); + } + + // Pop back to the start of the string and replace it + serd_stack_pop_to(&reader->stack, string_start_offset); + dest->length = 0U; + dest->type = SERD_URI; + push_bytes(reader, dest, (const uint8_t*)uri.data, uri.length); + } + if ((st = read_PN_LOCAL(reader, dest, ate_dot)) > SERD_FAILURE) { return st; } diff --git a/src/writer.c b/src/writer.c index faf5b7d9..db04c8f9 100644 --- a/src/writer.c +++ b/src/writer.c @@ -955,6 +955,29 @@ write_uri_node(SerdWriter* const writer, } SERD_NODISCARD static SerdStatus +write_curie_node(SerdWriter* const writer, const SerdNode* const node) +{ + writer->last_sep = SEP_NONE; + + const ZixStringView curie = serd_node_string_view(node); + if (supports_abbrev(writer)) { + return write_lname(writer, curie.data, curie.length); + } + + ZixStringView prefix = {NULL, 0}; + ZixStringView suffix = {NULL, 0}; + SerdStatus st = SERD_SUCCESS; + if ((st = serd_env_expand_in_place(writer->env, curie, &prefix, &suffix))) { + return w_err(writer, st, "unknown namespace prefix in '%s'", curie.data); + } + + TRY(st, esink("<", 1, writer)); + TRY(st, ewrite_uri(writer, prefix.data, prefix.length)); + TRY(st, ewrite_uri(writer, suffix.data, suffix.length)); + return esink(">", 1, writer); +} + +SERD_NODISCARD static SerdStatus write_blank(SerdWriter* const writer, const SerdNode* node, const SerdField field, @@ -1012,6 +1035,9 @@ write_node(SerdWriter* const writer, case SERD_URI: st = write_uri_node(writer, node, field); break; + case SERD_CURIE: + st = write_curie_node(writer, node); + break; case SERD_BLANK: st = write_blank(writer, node, field, flags); break; |