aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-07-05 21:01:12 +0200
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commit75af0505f94bb148cd7b4d9004dec824fa13e6c9 (patch)
treeb8b8c8c9c14b23461692dcf7d9a29d6474b63627
parent81f46794f4f1cc2f2da3eab3fa98c399d01715ef (diff)
downloadserd-75af0505f94bb148cd7b4d9004dec824fa13e6c9.tar.gz
serd-75af0505f94bb148cd7b4d9004dec824fa13e6c9.tar.bz2
serd-75af0505f94bb148cd7b4d9004dec824fa13e6c9.zip
Simplify writer style options
-rw-r--r--NEWS1
-rw-r--r--doc/serdi.14
-rw-r--r--serd/serd.h7
-rw-r--r--src/serdi.c25
-rw-r--r--src/writer.c4
-rw-r--r--wscript22
6 files changed, 24 insertions, 39 deletions
diff --git a/NEWS b/NEWS
index 06b66660..6bb2052f 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ serd (1.0.0) unstable;
* Bring read/write interface closer to C standard
* Add SerdWorld for shared library state
* Use a fixed-size reader stack
+ * Simplify writer style options
-- David Robillard <d@drobilla.net> Sat, 19 Jan 2019 13:31:12 +0100
diff --git a/doc/serdi.1 b/doc/serdi.1
index 04696032..166c32de 100644
--- a/doc/serdi.1
+++ b/doc/serdi.1
@@ -29,10 +29,6 @@ page of input has arrived. With this option serdi uses one page less memory,
but will likely be significantly slower.
.TP
-\fB\-f\fR
-Keep full URIs in input (don't qualify).
-
-.TP
\fB\-h\fR
Print the command line options.
diff --git a/serd/serd.h b/serd/serd.h
index 149d3e3e..7b2bd815 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -303,11 +303,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 766120f1..3a1ff3eb 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 a5a2b663..17b11008 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -514,7 +514,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)) {
@@ -525,7 +525,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, abs_uri;
serd_uri_parse(node_str, &uri);
diff --git a/wscript b/wscript
index af81ebe4..38e5e00d 100644
--- a/wscript
+++ b/wscript
@@ -256,19 +256,31 @@ def earl_assertion(test, passed, asserter):
serdi = './serdi_static'
+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, opts=[]):
out_path = path + '.pass'
- out_cmd = [serdi] + opts + [f for sublist in flags for f in sublist] + [
+ opts += 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]
@@ -335,7 +347,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))
@@ -349,7 +361,7 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, options=[]):
action = os.path.join('tests', testdir, os.path.basename(action_node))
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:
@@ -474,7 +486,7 @@ 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')
def posts(ctx):
path = str(ctx.path.abspath())