diff options
author | David Robillard <d@drobilla.net> | 2023-02-26 12:39:18 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 16:27:02 -0500 |
commit | 70277ccdb3035db83d81d942777c12a60c4aded3 (patch) | |
tree | 401d570c44167148cb282d1013ec1eaf4abe6283 /src | |
parent | febb30141356df83a56026bbb14099e3cb2c82fc (diff) | |
download | serd-70277ccdb3035db83d81d942777c12a60c4aded3.tar.gz serd-70277ccdb3035db83d81d942777c12a60c4aded3.tar.bz2 serd-70277ccdb3035db83d81d942777c12a60c4aded3.zip |
Rename string view fields
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 18 | ||||
-rw-r--r-- | src/node.c | 8 | ||||
-rw-r--r-- | src/uri.c | 98 | ||||
-rw-r--r-- | src/uri_utils.h | 12 | ||||
-rw-r--r-- | src/writer.c | 8 |
5 files changed, 72 insertions, 72 deletions
@@ -179,9 +179,9 @@ serd_env_qualify(const SerdEnv* const env, const SerdNode* const prefix_uri = &env->prefixes[i].uri; if (uri->n_bytes >= prefix_uri->n_bytes) { if (!strncmp(uri->buf, prefix_uri->buf, prefix_uri->n_bytes)) { - *prefix = env->prefixes[i].name; - suffix->buf = uri->buf + prefix_uri->n_bytes; - suffix->len = uri->n_bytes - prefix_uri->n_bytes; + *prefix = env->prefixes[i].name; + suffix->data = uri->buf + prefix_uri->n_bytes; + suffix->length = uri->n_bytes - prefix_uri->n_bytes; return true; } } @@ -208,10 +208,10 @@ serd_env_expand(const SerdEnv* const env, const size_t name_len = (size_t)(colon - curie->buf); const SerdPrefix* const prefix = serd_env_find(env, curie->buf, name_len); if (prefix) { - uri_prefix->buf = prefix->uri.buf; - uri_prefix->len = prefix->uri.n_bytes; - uri_suffix->buf = colon + 1; - uri_suffix->len = curie->n_bytes - name_len - 1; + uri_prefix->data = prefix->uri.buf; + uri_prefix->length = prefix->uri.n_bytes; + uri_suffix->data = colon + 1; + uri_suffix->length = curie->n_bytes - name_len - 1; return SERD_SUCCESS; } return SERD_BAD_CURIE; @@ -238,10 +238,10 @@ serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node) if (serd_env_expand(env, node, &prefix, &suffix)) { return SERD_NODE_NULL; } - const size_t len = prefix.len + suffix.len; + const size_t len = prefix.length + suffix.length; char* buf = (char*)malloc(len + 1); SerdNode ret = {buf, len, 0, SERD_URI}; - snprintf(buf, ret.n_bytes + 1, "%s%s", prefix.buf, suffix.buf); + snprintf(buf, ret.n_bytes + 1, "%s%s", prefix.data, suffix.data); return ret; } case SERD_BLANK: @@ -31,11 +31,11 @@ static size_t serd_uri_string_length(const SerdURIView* const uri) { - size_t len = uri->path_base.len; + size_t len = uri->path_base.length; -#define ADD_LEN(field, n_delims) \ - if ((field).len) { \ - len += (field).len + (n_delims); \ +#define ADD_LEN(field, n_delims) \ + if ((field).length) { \ + len += (field).length + (n_delims); \ } ADD_LEN(uri->path, 1) // + possible leading '/' @@ -108,8 +108,8 @@ serd_uri_parse(const char* const utf8, SerdURIView* const out) ptr = utf8; goto path; // Relative URI (starts with path by definition) case ':': - out->scheme.buf = utf8; - out->scheme.len = (size_t)((ptr++) - utf8); + out->scheme.data = utf8; + out->scheme.length = (size_t)((ptr++) - utf8); goto maybe_authority; // URI with scheme case '+': case '-': @@ -130,7 +130,7 @@ serd_uri_parse(const char* const utf8, SerdURIView* const out) maybe_authority: if (*ptr == '/' && *(ptr + 1) == '/') { ptr += 2; - out->authority.buf = ptr; + out->authority.data = ptr; for (char c = 0; (c = *ptr) != '\0'; ++ptr) { switch (c) { case '/': @@ -140,7 +140,7 @@ maybe_authority: case '#': goto fragment; default: - ++out->authority.len; + ++out->authority.length; } } } @@ -159,8 +159,8 @@ path: default: break; } - out->path.buf = ptr; - out->path.len = 0; + out->path.data = ptr; + out->path.length = 0; for (char c = 0; (c = *ptr) != '\0'; ++ptr) { switch (c) { case '?': @@ -168,7 +168,7 @@ path: case '#': goto fragment; default: - ++out->path.len; + ++out->path.length; } } @@ -178,12 +178,12 @@ path: */ query: if (*ptr == '?') { - out->query.buf = ++ptr; + out->query.data = ++ptr; for (char c = 0; (c = *ptr) != '\0'; ++ptr) { if (c == '#') { goto fragment; } - ++out->query.len; + ++out->query.length; } } @@ -193,9 +193,9 @@ query: */ fragment: if (*ptr == '#') { - out->fragment.buf = ptr; + out->fragment.data = ptr; while (*ptr++ != '\0') { - ++out->fragment.len; + ++out->fragment.length; } } @@ -239,26 +239,26 @@ static void merge(SerdStringView* const base, SerdStringView* const path) { size_t up = 0; - const char* begin = remove_dot_segments(path->buf, path->len, &up); - const char* end = path->buf + path->len; + const char* begin = remove_dot_segments(path->data, path->length, &up); + const char* end = path->data + path->length; - if (base->len) { + if (base->length) { // Find the up'th last slash - const char* base_last = (base->buf + base->len - 1); + const char* base_last = (base->data + base->length - 1); ++up; do { if (*base_last == '/') { --up; } - } while (up > 0 && (--base_last > base->buf)); + } while (up > 0 && (--base_last > base->data)); // Set path prefix - base->len = (size_t)(base_last - base->buf + 1); + base->length = (size_t)(base_last - base->data + 1); } // Set path suffix - path->buf = begin; - path->len = (size_t)(end - begin); + path->data = begin; + path->length = (size_t)(end - begin); } /// See http://tools.ietf.org/html/rfc3986#section-5.2.2 @@ -267,31 +267,31 @@ serd_uri_resolve(const SerdURIView* const r, const SerdURIView* const base, SerdURIView* const t) { - if (!base->scheme.len) { + if (!base->scheme.length) { *t = *r; // Don't resolve against non-absolute URIs return; } - t->path_base.buf = ""; - t->path_base.len = 0; - if (r->scheme.len) { + t->path_base.data = ""; + t->path_base.length = 0; + if (r->scheme.length) { *t = *r; } else { - if (r->authority.len) { + if (r->authority.length) { t->authority = r->authority; t->path = r->path; t->query = r->query; } else { t->path = r->path; - if (!r->path.len) { + if (!r->path.length) { t->path_base = base->path; - if (r->query.len) { + if (r->query.length) { t->query = r->query; } else { t->query = base->query; } } else { - if (r->path.buf[0] != '/') { + if (r->path.data[0] != '/') { t->path_base = base->path; } merge(&t->path_base, &t->path); @@ -312,16 +312,16 @@ write_path_tail(SerdSink sink, const size_t i) { size_t len = 0; - if (i < uri->path_base.len) { - len += sink(uri->path_base.buf + i, uri->path_base.len - i, stream); + if (i < uri->path_base.length) { + len += sink(uri->path_base.data + i, uri->path_base.length - i, stream); } - if (uri->path.buf) { - if (i < uri->path_base.len) { - len += sink(uri->path.buf, uri->path.len, stream); + if (uri->path.data) { + if (i < uri->path_base.length) { + len += sink(uri->path.data, uri->path.length, stream); } else { - const size_t j = (i - uri->path_base.len); - len += sink(uri->path.buf + j, uri->path.len - j, stream); + const size_t j = (i - uri->path_base.length); + len += sink(uri->path.data + j, uri->path.length - j, stream); } } @@ -373,9 +373,9 @@ write_rel_path(SerdSink sink, static uint8_t serd_uri_path_starts_without_slash(const SerdURIView* uri) { - return ((uri->path_base.len || uri->path.len) && - ((!uri->path_base.len || uri->path_base.buf[0] != '/') && - (!uri->path.len || uri->path.buf[0] != '/'))); + return ((uri->path_base.length || uri->path.length) && + ((!uri->path_base.length || uri->path_base.data[0] != '/') && + (!uri->path.length || uri->path.data[0] != '/'))); } /// See http://tools.ietf.org/html/rfc3986#section-5.3 @@ -394,18 +394,18 @@ serd_uri_serialise_relative(const SerdURIView* const uri, len = write_rel_path(sink, stream, uri, base); } - if (!relative || (!len && base->query.buf)) { - if (uri->scheme.buf) { - len += sink(uri->scheme.buf, uri->scheme.len, stream); + if (!relative || (!len && base->query.data)) { + if (uri->scheme.data) { + len += sink(uri->scheme.data, uri->scheme.length, stream); len += sink(":", 1, stream); } - if (uri->authority.buf) { + if (uri->authority.data) { len += sink("//", 2, stream); - len += sink(uri->authority.buf, uri->authority.len, stream); + len += sink(uri->authority.data, uri->authority.length, stream); const bool authority_ends_with_slash = - (uri->authority.len > 0 && - uri->authority.buf[uri->authority.len - 1] == '/'); + (uri->authority.length > 0 && + uri->authority.data[uri->authority.length - 1] == '/'); if (!authority_ends_with_slash && serd_uri_path_starts_without_slash(uri)) { @@ -417,14 +417,14 @@ serd_uri_serialise_relative(const SerdURIView* const uri, len += write_path_tail(sink, stream, uri, 0); } - if (uri->query.buf) { + if (uri->query.data) { len += sink("?", 1, stream); - len += sink(uri->query.buf, uri->query.len, stream); + len += sink(uri->query.data, uri->query.length, stream); } - if (uri->fragment.buf) { - // Note uri->fragment.buf includes the leading '#' - len += sink(uri->fragment.buf, uri->fragment.len, stream); + if (uri->fragment.data) { + // Note uri->fragment.data includes the leading '#' + len += sink(uri->fragment.data, uri->fragment.length, stream); } return len; diff --git a/src/uri_utils.h b/src/uri_utils.h index 3974b5ce..ebc32b78 100644 --- a/src/uri_utils.h +++ b/src/uri_utils.h @@ -19,23 +19,23 @@ typedef struct { static inline bool slice_equals(const SerdStringView* a, const SerdStringView* b) { - return a->len == b->len && !strncmp(a->buf, b->buf, a->len); + return a->length == b->length && !strncmp(a->data, b->data, a->length); } static inline size_t uri_path_len(const SerdURIView* uri) { - return uri->path_base.len + uri->path.len; + return uri->path_base.length + uri->path.length; } static inline char uri_path_at(const SerdURIView* uri, size_t i) { - if (i < uri->path_base.len) { - return uri->path_base.buf[i]; + if (i < uri->path_base.length) { + return uri->path_base.data[i]; } - return uri->path.buf[i - uri->path_base.len]; + return uri->path.data[i - uri->path_base.length]; } /** @@ -51,7 +51,7 @@ uri_rooted_index(const SerdURIView* uri, const SerdURIView* root) { SlashIndexes indexes = {SIZE_MAX, SIZE_MAX}; - if (!root || !root->scheme.len || + if (!root || !root->scheme.length || !slice_equals(&root->scheme, &uri->scheme) || !slice_equals(&root->authority, &uri->authority)) { return indexes; diff --git a/src/writer.c b/src/writer.c index 43f2ebe5..a177f4f3 100644 --- a/src/writer.c +++ b/src/writer.c @@ -743,10 +743,10 @@ write_uri_node(SerdWriter* const writer, 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)) { + is_name(suffix.data, suffix.length)) { TRY(st, write_uri_from_node(writer, &prefix)); TRY(st, esink(":", 1, writer)); - return ewrite_uri(writer, suffix.buf, suffix.len); + return ewrite_uri(writer, suffix.data, suffix.length); } } @@ -803,8 +803,8 @@ write_curie(SerdWriter* const writer, const SerdNode* const node) if (!supports_abbrev(writer)) { TRY(st, esink("<", 1, writer)); - TRY(st, ewrite_uri(writer, prefix.buf, prefix.len)); - TRY(st, ewrite_uri(writer, suffix.buf, suffix.len)); + TRY(st, ewrite_uri(writer, prefix.data, prefix.length)); + TRY(st, ewrite_uri(writer, suffix.data, suffix.length)); TRY(st, esink(">", 1, writer)); } else { TRY(st, write_lname(writer, node->buf, node->n_bytes)); |