diff options
author | David Robillard <d@drobilla.net> | 2016-03-16 16:54:49 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-13 15:33:54 -0500 |
commit | faac2e52df494481dc28168a856058a414a913f2 (patch) | |
tree | 96f6d9433fc7f23a0e1aabdffd61404a273a28cc | |
parent | 97258f0e85834d71b17e3c1997a5c7dc136e0b98 (diff) | |
download | serd-faac2e52df494481dc28168a856058a414a913f2.tar.gz serd-faac2e52df494481dc28168a856058a414a913f2.tar.bz2 serd-faac2e52df494481dc28168a856058a414a913f2.zip |
Rename SerdChunk to SerdStringView
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | include/serd/serd.h | 33 | ||||
-rw-r--r-- | src/env.c | 10 | ||||
-rw-r--r-- | src/uri.c | 2 | ||||
-rw-r--r-- | src/uri_utils.h | 6 | ||||
-rw-r--r-- | src/writer.c | 15 | ||||
-rw-r--r-- | test/test_env.c | 4 |
7 files changed, 36 insertions, 35 deletions
@@ -4,6 +4,7 @@ serd (1.0.1) unstable; * Remove serd_uri_to_path() * Remove support for Turtle named inline nodes extension * Remove useless character counting from API + * Rename SerdChunk to SerdStringView * Use char* for strings in public API -- David Robillard <d@drobilla.net> Wed, 13 Jan 2021 13:29:44 +0000 diff --git a/include/serd/serd.h b/include/serd/serd.h index e3184c16..f971d417 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -91,11 +91,16 @@ typedef enum { /// Bitwise OR of SerdNodeFlag values typedef uint32_t SerdNodeFlags; -/// An unterminated string fragment +/** + An immutable slice of a string. + + This type is used for many string parameters, to allow referring to slices + of strings in-place and to avoid redundant string measurement. +*/ typedef struct { - const char* SERD_NULLABLE buf; ///< Start of chunk - size_t len; ///< Length of chunk in bytes -} SerdChunk; + const char* SERD_NULLABLE buf; ///< Start of string + size_t len; ///< Length of string in bytes +} SerdStringView; /// A mutable buffer in memory typedef struct { @@ -234,12 +239,12 @@ typedef size_t (*SerdSink)(const void* SERD_NONNULL buf, 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; static const SerdURI SERD_URI_NULL = @@ -659,7 +664,7 @@ bool serd_env_qualify(const SerdEnv* SERD_NULLABLE env, const SerdNode* SERD_NONNULL uri, SerdNode* SERD_NONNULL prefix, - SerdChunk* SERD_NONNULL suffix); + SerdStringView* SERD_NONNULL suffix); /** Expand `curie`. @@ -671,8 +676,8 @@ SERD_API SerdStatus serd_env_expand(const SerdEnv* SERD_NULLABLE 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. @@ -917,7 +922,7 @@ serd_buffer_sink(const void* SERD_NONNULL buf, void* SERD_NONNULL stream); /** - Finish a serialisation to a chunk with serd_buffer_sink(). + Finish writing 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. @@ -176,7 +176,7 @@ bool serd_env_qualify(const SerdEnv* const env, const SerdNode* const uri, SerdNode* const prefix, - SerdChunk* const suffix) + SerdStringView* const suffix) { if (!env) { return false; @@ -199,8 +199,8 @@ serd_env_qualify(const SerdEnv* const env, SerdStatus serd_env_expand(const SerdEnv* const env, const SerdNode* const curie, - SerdChunk* const uri_prefix, - SerdChunk* const uri_suffix) + SerdStringView* const uri_prefix, + SerdStringView* const uri_suffix) { if (!env) { return SERD_ERR_BAD_CURIE; @@ -240,8 +240,8 @@ serd_env_expand_node(const SerdEnv* const env, const SerdNode* const 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; } @@ -280,7 +280,7 @@ remove_dot_segments(const char* const path, const size_t len, size_t* const up) /// Merge `base` and `path` in-place static void -merge(SerdChunk* const base, SerdChunk* const path) +merge(SerdStringView* const base, SerdStringView* const 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 <string.h> 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 84c704ee..c613b00c 100644 --- a/src/writer.c +++ b/src/writer.c @@ -567,8 +567,8 @@ write_uri_node(SerdWriter* const writer, const SerdNode* node, const Field field) { - SerdNode prefix; - SerdChunk suffix; + SerdNode prefix; + SerdStringView suffix; const bool has_scheme = serd_uri_string_has_scheme(node->buf); if (supports_abbrev(writer)) { @@ -576,10 +576,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(prefix.buf, prefix.n_bytes) && @@ -627,10 +623,9 @@ write_uri_node(SerdWriter* const writer, static bool write_curie(SerdWriter* const writer, const SerdNode* const node) { - 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: diff --git a/test/test_env.c b/test/test_env.c index b6293998..0ca17b79 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_qualify(NULL, &u, &u, &suffix)); assert(serd_env_expand(NULL, &c, &prefix, &suffix)); assert(serd_env_expand(env, &b, &prefix, &suffix)); |