diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | doc/serdi.1 | 2 | ||||
-rw-r--r-- | serd/serd.h | 9 | ||||
-rw-r--r-- | src/serdi.c | 23 | ||||
-rw-r--r-- | src/writer.c | 6 | ||||
-rw-r--r-- | wscript | 32 |
6 files changed, 41 insertions, 32 deletions
@@ -8,6 +8,7 @@ serd (1.0.1) unstable; * Remove half-baked serd_uri_to_path() * Remove useless character counting from API * Rename SerdChunk to SerdStringView + * Simplify writer style options * Use a fixed-size reader stack * Use char* for strings in public API diff --git a/doc/serdi.1 b/doc/serdi.1 index a246ff16..9c6900ef 100644 --- a/doc/serdi.1 +++ b/doc/serdi.1 @@ -28,7 +28,7 @@ With this option serdi uses one page less memory, but will likely be significant .TP .BR \-f -Keep full URIs in input (don't qualify). +Keep full URIs in input (don't qualify with namespace prefixes or make URIs relative). .TP .BR \-h diff --git a/serd/serd.h b/serd/serd.h index 6e68e349..4f17babe 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -299,11 +299,10 @@ typedef struct { always ASCII). */ typedef enum { - SERD_STYLE_ABBREVIATED = 1, /**< Abbreviate triples when possible. */ - SERD_STYLE_ASCII = 1 << 1, /**< Escape all non-ASCII characters. */ - SERD_STYLE_RESOLVED = 1 << 2, /**< Resolve URIs against base URI. */ - SERD_STYLE_CURIED = 1 << 3, /**< Shorten URIs into CURIEs. */ - SERD_STYLE_BULK = 1 << 4 /**< Write output in pages. */ + SERD_STYLE_ASCII = 1 << 0, /**< Escape all non-ASCII characters. */ + SERD_STYLE_BULK = 1 << 1, /**< Write output in pages. */ + SERD_STYLE_UNQUALIFIED = 1 << 2, /**< Do not shorten URIs into CURIEs. */ + SERD_STYLE_UNRESOLVED = 1 << 3 /**< Do not make URIs relative. */ } SerdStyle; /** diff --git a/src/serdi.c b/src/serdi.c index 8939ae3b..9bf42ac2 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -205,25 +205,10 @@ main(int argc, char** argv) SerdWorld* world = serd_world_new(); SerdEnv* env = serd_env_new(base); - SerdStyleFlags output_style = 0; - if (output_syntax == SERD_NTRIPLES || ascii) { - output_style |= SERD_STYLE_ASCII; - } else if (output_syntax == SERD_TURTLE) { - output_style |= SERD_STYLE_ABBREVIATED; - if (!full_uris) { - output_style |= SERD_STYLE_CURIED; - } - } - - if ((input_syntax == SERD_TURTLE || input_syntax == SERD_TRIG) || - (output_style & SERD_STYLE_CURIED)) { - // Base URI may change and/or we're abbreviating URIs, so must resolve - output_style |= SERD_STYLE_RESOLVED; - } - - if (bulk_write) { - output_style |= SERD_STYLE_BULK; - } + const SerdStyleFlags output_style = + ((ascii ? SERD_STYLE_ASCII : 0) | // + (bulk_write ? SERD_STYLE_BULK : 0) | // + (full_uris ? (SERD_STYLE_UNQUALIFIED | SERD_STYLE_UNRESOLVED) : 0)); SerdWriter* writer = serd_writer_new(world, output_syntax, diff --git a/src/writer.c b/src/writer.c index fc8f86b4..3e918a0c 100644 --- a/src/writer.c +++ b/src/writer.c @@ -512,7 +512,8 @@ write_uri_node(SerdWriter* const writer, return sink("a", 1, writer) == 1; } else if (supports_abbrev(writer) && !strcmp(node_str, NS_RDF "nil")) { return sink("()", 2, writer) == 2; - } else if (has_scheme && (writer->style & SERD_STYLE_CURIED) && + } else if (has_scheme && supports_abbrev(writer) && + !(writer->style & SERD_STYLE_UNQUALIFIED) && serd_env_qualify_in_place(writer->env, node, &prefix, &suffix) && is_name(serd_node_string(prefix), serd_node_length(prefix)) && is_name(suffix.buf, suffix.len)) { @@ -523,7 +524,8 @@ write_uri_node(SerdWriter* const writer, } write_sep(writer, SEP_URI_BEGIN); - if (writer->style & SERD_STYLE_RESOLVED) { + if (!(writer->style & SERD_STYLE_UNRESOLVED) && + serd_env_base_uri(writer->env)) { const SerdURI* base_uri = serd_env_get_parsed_base_uri(writer->env); SerdURI uri; SerdURI abs_uri; @@ -372,19 +372,41 @@ def earl_assertion(test, passed, asserter): serdi = './serdi_static' -def test_thru(check, base, path, check_path, flags, isyntax, osyntax, opts=[]): +def test_osyntax_options(osyntax): + if osyntax.lower() == 'ntriples' or osyntax.lower() == 'nquads': + return [['-a']] + return [] + + +def flatten_options(opts): + return [o for sublist in opts for o in sublist] + + +def test_thru(check, + base, + path, + check_path, + flags, + isyntax, + osyntax, + options=[]): out_path = path + '.pass' - out_cmd = [serdi] + opts + [f for sublist in flags for f in sublist] + [ + opts = options + flatten_options(test_osyntax_options(osyntax)) + flags = flatten_options(flags) + osyntax_opts = [f for sublist in + test_osyntax_options(osyntax) for f in sublist] + out_cmd = [serdi] + opts + flags + [ '-i', isyntax, '-o', isyntax, '-p', 'foo', check.tst.src_path(path), base] thru_path = path + '.thru' - thru_cmd = [serdi] + opts + [ + thru_cmd = [serdi] + opts + osyntax_opts + [ '-i', isyntax, '-o', osyntax, '-c', 'foo', + '-a', out_path, base] @@ -486,7 +508,7 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, options=[]): action = os.path.join('tests', testdir, basename) rel_action = os.path.join(os.path.relpath(srcdir), action) uri = base_uri + os.path.basename(action) - command = [serdi] + options + ['-f', rel_action, uri] + command = [serdi, '-a'] + options + [rel_action, uri] # Run strict test if expected_return == 0: @@ -643,4 +665,4 @@ def test(tst): test_suite(tst, w3c_base + 'NQuadsTests/', 'NQuadsTests', report, 'NQuads') test_suite(tst, w3c_base + 'TriGTests/', - 'TriGTests', report, 'Trig', ['-a']) + 'TriGTests', report, 'Trig') |