From b4dee10576e9916c0c8d80033bc429dc38a70c1c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 16 Mar 2016 16:54:49 -0400 Subject: Rename SerdChunk to SerdStringView --- NEWS | 1 + include/serd/serd.h | 26 +++++++++++++------------- src/env.c | 10 +++++----- src/uri.c | 2 +- src/uri_utils.h | 6 +++--- src/writer.c | 16 +++++----------- test/test_env.c | 4 ++-- 7 files changed, 30 insertions(+), 35 deletions(-) diff --git a/NEWS b/NEWS index c3e1508d..11998f09 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ serd (1.0.1) unstable; * Add SerdBuffer for mutable buffers to keep SerdChunk const-correct * Remove serd_uri_to_path() * Remove useless character counting from API + * Rename SerdChunk to SerdStringView * Use char* for strings in public API -- David Robillard Wed, 13 Jan 2021 13:29:44 +0000 diff --git a/include/serd/serd.h b/include/serd/serd.h index 7b3d0cf7..d0811911 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -191,11 +191,11 @@ typedef struct { SerdType type; ///< Node type } SerdNode; -/// An unterminated string fragment +/// An unterminated immutable slice of a string typedef struct { const char* SERD_NULLABLE buf; ///< Start of chunk size_t len; ///< Length of chunk in bytes -} SerdChunk; +} SerdStringView; /// A mutable buffer in memory typedef struct { @@ -216,17 +216,17 @@ typedef struct { /** A parsed URI - This struct directly refers to chunks in other strings, it does not own any + This struct directly refers to slices in other strings, it does not own any memory itself. Thus, URIs can be parsed and/or resolved against a base URI in-place without allocating memory. */ typedef struct { - SerdChunk scheme; ///< Scheme - SerdChunk authority; ///< Authority - SerdChunk path_base; ///< Path prefix if relative - SerdChunk path; ///< Path suffix - SerdChunk query; ///< Query - SerdChunk fragment; ///< Fragment + SerdStringView scheme; ///< Scheme + SerdStringView authority; ///< Authority + SerdStringView path_base; ///< Path prefix if relative + SerdStringView path; ///< Path suffix + SerdStringView query; ///< Query + SerdStringView fragment; ///< Fragment } SerdURI; /** @@ -675,7 +675,7 @@ bool serd_env_qualify(const SerdEnv* SERD_NONNULL env, const SerdNode* SERD_NONNULL uri, SerdNode* SERD_NONNULL prefix, - SerdChunk* SERD_NONNULL suffix); + SerdStringView* SERD_NONNULL suffix); /** Expand `curie`. @@ -687,8 +687,8 @@ SERD_API SerdStatus serd_env_expand(const SerdEnv* SERD_NONNULL env, const SerdNode* SERD_NONNULL curie, - SerdChunk* SERD_NONNULL uri_prefix, - SerdChunk* SERD_NONNULL uri_suffix); + SerdStringView* SERD_NONNULL uri_prefix, + SerdStringView* SERD_NONNULL uri_suffix); /** Expand `node`, which must be a CURIE or URI, to a full URI. @@ -912,7 +912,7 @@ serd_buffer_sink(const void* SERD_NONNULL buf, void* SERD_NONNULL stream); /** - Finish a serialisation to a chunk with serd_buffer_sink(). + Finish a serialisation to a buffer with serd_buffer_sink(). The returned string is the result of the serialisation, which is null terminated (by this function) and owned by the caller. diff --git a/src/env.c b/src/env.c index 9d4721d2..c319ce54 100644 --- a/src/env.c +++ b/src/env.c @@ -170,7 +170,7 @@ bool serd_env_qualify(const SerdEnv* env, const SerdNode* uri, SerdNode* prefix, - SerdChunk* suffix) + SerdStringView* suffix) { for (size_t i = 0; i < env->n_prefixes; ++i) { const SerdNode* const prefix_uri = &env->prefixes[i].uri; @@ -189,8 +189,8 @@ serd_env_qualify(const SerdEnv* env, SerdStatus serd_env_expand(const SerdEnv* env, const SerdNode* curie, - SerdChunk* uri_prefix, - SerdChunk* uri_suffix) + SerdStringView* uri_prefix, + SerdStringView* uri_suffix) { const char* const colon = (const char*)memchr(curie->buf, ':', curie->n_bytes + 1); @@ -222,8 +222,8 @@ serd_env_expand_node(const SerdEnv* env, const SerdNode* node) return serd_node_new_uri_from_node(node, &env->base_uri, &ignored); } case SERD_CURIE: { - SerdChunk prefix; - SerdChunk suffix; + SerdStringView prefix; + SerdStringView suffix; if (serd_env_expand(env, node, &prefix, &suffix)) { return SERD_NODE_NULL; } diff --git a/src/uri.c b/src/uri.c index 93beeffe..01384072 100644 --- a/src/uri.c +++ b/src/uri.c @@ -279,7 +279,7 @@ remove_dot_segments(const char* path, size_t len, size_t* up) /// Merge `base` and `path` in-place static void -merge(SerdChunk* base, SerdChunk* path) +merge(SerdStringView* base, SerdStringView* path) { size_t up = 0; const char* begin = remove_dot_segments(path->buf, path->len, &up); diff --git a/src/uri_utils.h b/src/uri_utils.h index 2544eea2..735555c4 100644 --- a/src/uri_utils.h +++ b/src/uri_utils.h @@ -25,7 +25,7 @@ #include static inline bool -chunk_equals(const SerdChunk* a, const SerdChunk* b) +slice_equals(const SerdStringView* a, const SerdStringView* b) { return a->len == b->len && !strncmp(a->buf, b->buf, a->len); } @@ -54,8 +54,8 @@ static inline SERD_PURE_FUNC size_t uri_rooted_index(const SerdURI* uri, const SerdURI* root) { if (!root || !root->scheme.len || - !chunk_equals(&root->scheme, &uri->scheme) || - !chunk_equals(&root->authority, &uri->authority)) { + !slice_equals(&root->scheme, &uri->scheme) || + !slice_equals(&root->authority, &uri->authority)) { return 0; } diff --git a/src/writer.c b/src/writer.c index dce47599..e97af301 100644 --- a/src/writer.c +++ b/src/writer.c @@ -564,8 +564,8 @@ write_uri_node(SerdWriter* const writer, const Field field, const SerdStatementFlags flags) { - SerdNode prefix; - SerdChunk suffix; + SerdNode prefix; + SerdStringView suffix; if (is_inline_start(writer, field, flags)) { ++writer->indent; @@ -579,10 +579,6 @@ write_uri_node(SerdWriter* const writer, return sink("a", 1, writer) == 1; } - if (!strcmp(node->buf, NS_RDF "nil")) { - return sink("()", 2, writer) == 2; - } - if (has_scheme && (writer->style & SERD_STYLE_CURIED) && serd_env_qualify(writer->env, node, &prefix, &suffix) && is_name(suffix.buf, suffix.len)) { @@ -636,10 +632,9 @@ write_curie(SerdWriter* const writer, const Field field, const SerdStatementFlags flags) { - SerdChunk prefix = {NULL, 0}; - SerdChunk suffix = {NULL, 0}; - SerdStatus st = SERD_SUCCESS; - + SerdStringView prefix = {NULL, 0}; + SerdStringView suffix = {NULL, 0}; + SerdStatus st = SERD_SUCCESS; switch (writer->syntax) { case SERD_NTRIPLES: case SERD_NQUADS: @@ -665,7 +660,6 @@ write_curie(SerdWriter* const writer, write_newline(writer); } } - return true; } diff --git a/test/test_env.c b/test/test_env.c index 7c38d481..6882ae62 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -44,8 +44,8 @@ test_env(void) assert(serd_env_set_base_uri(env, &SERD_NODE_NULL)); assert(serd_node_equals(serd_env_get_base_uri(env, NULL), &SERD_NODE_NULL)); - SerdChunk prefix; - SerdChunk suffix; + SerdStringView prefix; + SerdStringView suffix; assert(serd_env_expand(env, &b, &prefix, &suffix)); SerdNode xnode = serd_env_expand_node(env, &SERD_NODE_NULL); -- cgit v1.2.1