From aa65756284ba705a6d2e33a6fd1dca76a1602a88 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 5 Jul 2018 21:01:12 +0200 Subject: Simplify writer style options --- NEWS | 1 + doc/serdi.1 | 4 ---- serd/serd.h | 7 ++----- src/serdi.c | 25 ++----------------------- src/writer.c | 4 ++-- wscript | 34 ++++++++++++++++++++++++++++------ 6 files changed, 35 insertions(+), 40 deletions(-) diff --git a/NEWS b/NEWS index bc53b443..dbf3e4d5 100644 --- a/NEWS +++ b/NEWS @@ -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 a5f0acee..f4c6d13c 100644 --- a/doc/serdi.1 +++ b/doc/serdi.1 @@ -28,10 +28,6 @@ generated immediately as input arrives, rather than waiting until an entire page of input has arrived. With this option serdi uses one page less memory, but will likely be significantly slower. -.TP -.BR \-f -Keep full URIs in input (don't qualify). - .TP .BR \-h Print the command line options. diff --git a/serd/serd.h b/serd/serd.h index 6a5bd1a1..56534571 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -295,11 +295,8 @@ 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. */ } SerdStyle; /** diff --git a/src/serdi.c b/src/serdi.c index 1c47aed3..86a315df 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -55,7 +55,6 @@ print_usage(const char* name, bool error) fprintf(os, " -b Fast bulk output for large serialisations.\n"); fprintf(os, " -c PREFIX Chop PREFIX from matching blank node IDs.\n"); fprintf(os, " -e Eat input one character at a time.\n"); - fprintf(os, " -f Keep full URIs in input (don't qualify).\n"); fprintf(os, " -h Display this help and exit.\n"); fprintf(os, " -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n"); fprintf(os, " -k BYTES Parser stack size.\n"); @@ -98,7 +97,6 @@ main(int argc, char** argv) bool ascii = false; bool bulk_read = true; bool bulk_write = false; - bool full_uris = false; bool lax = false; bool quiet = false; size_t stack_size = 4194304; @@ -116,8 +114,6 @@ main(int argc, char** argv) bulk_write = true; } else if (argv[a][1] == 'e') { bulk_read = false; - } else if (argv[a][1] == 'f') { - full_uris = true; } else if (argv[a][1] == 'h') { return print_usage(argv[0], false); } else if (argv[a][1] == 'l') { @@ -206,25 +202,8 @@ 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)); SerdWriter* writer = serd_writer_new(world, output_syntax, diff --git a/src/writer.c b/src/writer.c index fad22ee2..bade5bf1 100644 --- a/src/writer.c +++ b/src/writer.c @@ -513,7 +513,7 @@ 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) && serd_env_qualify_in_place(writer->env, node, &prefix, &suffix) && is_name(serd_node_get_string(prefix), serd_node_get_length(prefix)) && is_name(suffix.buf, suffix.len)) { @@ -524,7 +524,7 @@ write_uri_node(SerdWriter* const writer, } write_sep(writer, SEP_URI_BEGIN); - if (writer->style & SERD_STYLE_RESOLVED) { + if (serd_env_get_base_uri(writer->env)) { const SerdURI* base_uri = serd_env_get_parsed_base_uri(writer->env); SerdURI uri; SerdURI abs_uri; diff --git a/wscript b/wscript index 98ac1175..dbeb420b 100644 --- a/wscript +++ b/wscript @@ -320,19 +320,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] @@ -410,7 +432,7 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, options=[]): asserter = 'http://drobilla.net/drobilla#me' def run_tests(test_class, tests, expected_return): - thru_flags = [['-e'], ['-f'], ['-b'], ['-r', 'http://example.org/']] + thru_flags = [['-e'], ['-b'], ['-r', 'http://example.org/']] thru_options = [] for n in range(len(thru_flags) + 1): thru_options += list(itertools.combinations(thru_flags, n)) @@ -425,7 +447,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: @@ -579,4 +601,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') -- cgit v1.2.1