aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-29 20:05:00 -0500
committerDavid Robillard <d@drobilla.net>2022-01-13 15:33:54 -0500
commit6cdd2b1e6f4ac37682ee20dca32441f88c92bcfa (patch)
tree350d096f47e2c9b3a3432de4c113ecdbfc29e964
parent9fa93ba7da0983e3a4e810138ae6f7c14751e180 (diff)
downloadserd-6cdd2b1e6f4ac37682ee20dca32441f88c92bcfa.tar.gz
serd-6cdd2b1e6f4ac37682ee20dca32441f88c92bcfa.tar.bz2
serd-6cdd2b1e6f4ac37682ee20dca32441f88c92bcfa.zip
Rename SerdStyle to SerdWriterFlags
-rw-r--r--include/serd/serd.h19
-rw-r--r--src/serdi.c22
-rw-r--r--src/writer.c48
-rw-r--r--test/test_reader_writer.c9
-rw-r--r--test/test_writer.c4
5 files changed, 52 insertions, 50 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 7aea35c8..74d3104a 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -861,25 +861,28 @@ serd_reader_free(SerdReader* SERD_NULLABLE reader);
typedef struct SerdWriterImpl SerdWriter;
/**
- Syntax style options.
+ Writer style options.
These flags allow more precise control of writer output style. Note that
some options are only supported for some syntaxes, for example, NTriples
does not support abbreviation and is always ASCII.
*/
typedef enum {
- SERD_STYLE_ABBREVIATED = 1u << 0u, ///< Abbreviate triples when possible.
- SERD_STYLE_ASCII = 1u << 1u, ///< Escape all non-ASCII characters.
- SERD_STYLE_RESOLVED = 1u << 2u, ///< Resolve URIs against base URI.
- SERD_STYLE_CURIED = 1u << 3u, ///< Shorten URIs into CURIEs.
- SERD_STYLE_BULK = 1u << 4u, ///< Write output in pages.
-} SerdStyle;
+ SERD_WRITE_ABBREVIATED = 1u << 0u, ///< Abbreviate triples when possible
+ SERD_WRITE_ASCII = 1u << 1u, ///< Escape all non-ASCII characters
+ SERD_WRITE_RESOLVED = 1u << 2u, ///< Resolve URIs against base URI
+ SERD_WRITE_CURIED = 1u << 3u, ///< Shorten URIs into CURIEs
+ SERD_WRITE_BULK = 1u << 4u, ///< Write output in pages
+} SerdWriterFlag;
+
+/// Bitwise OR of SerdWriterFlag values
+typedef uint32_t SerdWriterFlags;
/// Create a new RDF writer
SERD_API
SerdWriter* SERD_ALLOCATED
serd_writer_new(SerdSyntax syntax,
- SerdStyle style,
+ SerdWriterFlags flags,
SerdEnv* SERD_NONNULL env,
const SerdURIView* SERD_NULLABLE base_uri,
SerdSink SERD_NONNULL ssink,
diff --git a/src/serdi.c b/src/serdi.c
index 1ebd5e85..cda8aa21 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -147,34 +147,34 @@ serd_fopen(const char* const path, const char* const mode)
return fd;
}
-static SerdStyle
+static SerdWriterFlags
choose_style(const SerdSyntax input_syntax,
const SerdSyntax output_syntax,
const bool ascii,
const bool bulk_write,
const bool full_uris)
{
- unsigned output_style = 0u;
+ SerdWriterFlags writer_flags = 0u;
if (output_syntax == SERD_NTRIPLES || ascii) {
- output_style |= SERD_STYLE_ASCII;
+ writer_flags |= SERD_WRITE_ASCII;
} else if (output_syntax == SERD_TURTLE) {
- output_style |= SERD_STYLE_ABBREVIATED;
+ writer_flags |= SERD_WRITE_ABBREVIATED;
if (!full_uris) {
- output_style |= SERD_STYLE_CURIED;
+ writer_flags |= SERD_WRITE_CURIED;
}
}
if ((input_syntax == SERD_TURTLE || input_syntax == SERD_TRIG) ||
- (output_style & SERD_STYLE_CURIED)) {
+ (writer_flags & SERD_WRITE_CURIED)) {
// Base URI may change and/or we're abbreviating URIs, so must resolve
- output_style |= SERD_STYLE_RESOLVED;
+ writer_flags |= SERD_WRITE_RESOLVED;
}
if (bulk_write) {
- output_style |= SERD_STYLE_BULK;
+ writer_flags |= SERD_WRITE_BULK;
}
- return (SerdStyle)output_style;
+ return writer_flags;
}
int
@@ -312,7 +312,7 @@ main(int argc, char** argv)
: SERD_NQUADS);
}
- const SerdStyle output_style =
+ const SerdWriterFlags writer_flags =
choose_style(input_syntax, output_syntax, ascii, bulk_write, full_uris);
SerdURIView base_uri = SERD_URI_NULL;
@@ -327,7 +327,7 @@ main(int argc, char** argv)
SerdEnv* const env = serd_env_new(&base);
SerdWriter* const writer = serd_writer_new(
- output_syntax, output_style, env, &base_uri, serd_file_sink, out_fd);
+ output_syntax, writer_flags, env, &base_uri, serd_file_sink, out_fd);
SerdReader* const reader =
serd_reader_new(input_syntax,
diff --git a/src/writer.c b/src/writer.c
index 0d5c16f2..82447826 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -92,24 +92,24 @@ static const SepRule rules[] = {{NULL, 0, 0, 0, 0},
{"\n", 1, 0, 1, 0}};
struct SerdWriterImpl {
- SerdSyntax syntax;
- SerdStyle style;
- SerdEnv* env;
- SerdNode root_node;
- SerdURIView root_uri;
- SerdURIView base_uri;
- SerdStack anon_stack;
- SerdByteSink byte_sink;
- SerdErrorSink error_sink;
- void* error_handle;
- WriteContext context;
- SerdNode list_subj;
- unsigned list_depth;
- unsigned indent;
- char* bprefix;
- size_t bprefix_len;
- Sep last_sep;
- bool empty;
+ SerdSyntax syntax;
+ SerdWriterFlags flags;
+ SerdEnv* env;
+ SerdNode root_node;
+ SerdURIView root_uri;
+ SerdURIView base_uri;
+ SerdStack anon_stack;
+ SerdByteSink byte_sink;
+ SerdErrorSink error_sink;
+ void* error_handle;
+ WriteContext context;
+ SerdNode list_subj;
+ unsigned list_depth;
+ unsigned indent;
+ char* bprefix;
+ size_t bprefix_len;
+ Sep last_sep;
+ bool empty;
};
typedef enum { WRITE_STRING, WRITE_LONG_STRING } TextContext;
@@ -196,7 +196,7 @@ write_character(SerdWriter* writer, const uint8_t* utf8, size_t* size)
break;
}
- if (!(writer->style & SERD_STYLE_ASCII)) {
+ if (!(writer->flags & SERD_WRITE_ASCII)) {
// Write UTF-8 character directly to UTF-8 output
return sink(utf8, *size, writer);
}
@@ -576,7 +576,7 @@ write_uri_node(SerdWriter* const writer,
return sink("a", 1, writer) == 1;
}
- if (has_scheme && (writer->style & SERD_STYLE_CURIED) &&
+ if (has_scheme && (writer->flags & SERD_WRITE_CURIED) &&
serd_env_qualify(writer->env, node, &prefix, &suffix) &&
is_name(prefix.buf, prefix.n_bytes) &&
is_name(suffix.buf, suffix.len)) {
@@ -597,7 +597,7 @@ write_uri_node(SerdWriter* const writer,
}
write_sep(writer, SEP_URI_BEGIN);
- if (writer->style & SERD_STYLE_RESOLVED) {
+ if (writer->flags & SERD_WRITE_RESOLVED) {
SerdURIView in_base_uri;
SerdURIView uri;
SerdURIView abs_uri;
@@ -936,7 +936,7 @@ serd_writer_finish(SerdWriter* writer)
SerdWriter*
serd_writer_new(SerdSyntax syntax,
- SerdStyle style,
+ SerdWriterFlags flags,
SerdEnv* env,
const SerdURIView* base_uri,
SerdSink ssink,
@@ -946,7 +946,7 @@ serd_writer_new(SerdSyntax syntax,
SerdWriter* writer = (SerdWriter*)calloc(1, sizeof(SerdWriter));
writer->syntax = syntax;
- writer->style = style;
+ writer->flags = flags;
writer->env = env;
writer->root_node = SERD_NODE_NULL;
writer->root_uri = SERD_URI_NULL;
@@ -956,7 +956,7 @@ serd_writer_new(SerdSyntax syntax,
writer->list_subj = SERD_NODE_NULL;
writer->empty = true;
writer->byte_sink = serd_byte_sink_new(
- ssink, stream, (style & SERD_STYLE_BULK) ? SERD_PAGE_SIZE : 1);
+ ssink, stream, (flags & SERD_WRITE_BULK) ? SERD_PAGE_SIZE : 1);
return writer;
}
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 1c332bbe..287a2bfc 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -185,7 +185,7 @@ test_writer(const char* const path)
assert(fd);
SerdWriter* writer =
- serd_writer_new(SERD_TURTLE, (SerdStyle)0, env, NULL, serd_file_sink, fd);
+ serd_writer_new(SERD_TURTLE, 0, env, NULL, serd_file_sink, fd);
assert(writer);
serd_writer_chop_blank_prefix(writer, "tmp");
@@ -261,8 +261,8 @@ test_writer(const char* const path)
// Test buffer sink
SerdBuffer buffer = {NULL, 0};
- writer = serd_writer_new(
- SERD_TURTLE, (SerdStyle)0, env, NULL, serd_buffer_sink, &buffer);
+ writer =
+ serd_writer_new(SERD_TURTLE, 0, env, NULL, serd_buffer_sink, &buffer);
o = serd_node_from_string(SERD_URI, "http://example.org/base");
assert(!serd_writer_set_base_uri(writer, &o));
@@ -277,8 +277,7 @@ test_writer(const char* const path)
SerdNode nothing = serd_node_from_string(SERD_NOTHING, "");
FILE* const empty = tmpfile();
- writer = serd_writer_new(
- SERD_TURTLE, (SerdStyle)0, env, NULL, serd_file_sink, empty);
+ writer = serd_writer_new(SERD_TURTLE, 0, env, NULL, serd_file_sink, empty);
// FIXME: error handling
serd_writer_write_statement(writer, 0, NULL, &s, &p, &nothing, NULL, NULL);
diff --git a/test/test_writer.c b/test/test_writer.c
index bedd6725..e7cfe231 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -26,8 +26,8 @@ test_write_long_literal(void)
{
SerdEnv* env = serd_env_new(NULL);
SerdBuffer buffer = {NULL, 0};
- SerdWriter* writer = serd_writer_new(
- SERD_TURTLE, (SerdStyle)0, env, NULL, serd_buffer_sink, &buffer);
+ SerdWriter* writer =
+ serd_writer_new(SERD_TURTLE, 0u, env, NULL, serd_buffer_sink, &buffer);
assert(writer);