diff options
author | David Robillard <d@drobilla.net> | 2018-06-15 09:26:17 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 16:27:02 -0500 |
commit | b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9 (patch) | |
tree | 70a49bcc4d79d83d0f80f115da457514e09977d0 /src/uri.c | |
parent | fe0b6d5d4d78cb31e1bf2381198890d070e46ed1 (diff) | |
download | serd-b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9.tar.gz serd-b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9.tar.bz2 serd-b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9.zip |
Bring read/write interface closer to the C standard
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 33 |
1 files changed, 17 insertions, 16 deletions
@@ -48,19 +48,19 @@ serd_parse_file_uri(const char* const uri, char** const hostname) for (const char* s = path; *s; ++s) { if (*s == '%') { if (*(s + 1) == '%') { - serd_buffer_sink("%", 1, &buffer); + serd_buffer_sink("%", 1, 1, &buffer); ++s; } else if (is_hexdig(*(s + 1)) && is_hexdig(*(s + 2))) { const uint8_t hi = hex_digit_value((const uint8_t)s[1]); const uint8_t lo = hex_digit_value((const uint8_t)s[2]); const char c = (char)((hi << 4U) | lo); - serd_buffer_sink(&c, 1, &buffer); + serd_buffer_sink(&c, 1, 1, &buffer); s += 2; } else { s += 2; // Junk escape, ignore } } else { - serd_buffer_sink(s, 1, &buffer); + serd_buffer_sink(s, 1, 1, &buffer); } } @@ -398,48 +398,49 @@ serd_uri_is_within(const SerdURIView uri, const SerdURIView base) /// See http://tools.ietf.org/html/rfc3986#section-5.3 size_t -serd_write_uri(const SerdURIView uri, SerdSink sink, void* const stream) +serd_write_uri(const SerdURIView uri, + const SerdWriteFunc sink, + void* const stream) { size_t len = 0; if (uri.scheme.data) { - len += sink(uri.scheme.data, uri.scheme.length, stream); - len += sink(":", 1, stream); + len += sink(uri.scheme.data, 1, uri.scheme.length, stream); + len += sink(":", 1, 1, stream); } if (uri.authority.data) { - len += sink("//", 2, stream); - len += sink(uri.authority.data, uri.authority.length, stream); + len += sink("//", 1, 2, stream); + len += sink(uri.authority.data, 1, uri.authority.length, stream); if (uri.authority.length > 0 && uri_path_len(&uri) > 0 && uri_path_at(&uri, 0) != '/') { // Special case: ensure path begins with a slash // https://tools.ietf.org/html/rfc3986#section-3.2 - len += sink("/", 1, stream); + len += sink("/", 1, 1, stream); } } if (uri.path_prefix.data) { - len += sink(uri.path_prefix.data, uri.path_prefix.length, stream); + len += sink(uri.path_prefix.data, 1, uri.path_prefix.length, stream); } else if (uri.path_prefix.length) { for (size_t i = 0; i < uri.path_prefix.length; ++i) { - len += sink("../", 3, stream); + len += sink("../", 1, 3, stream); } } if (uri.path.data) { - len += sink(uri.path.data, uri.path.length, stream); + len += sink(uri.path.data, 1, uri.path.length, stream); } if (uri.query.data) { - len += sink("?", 1, stream); - len += sink(uri.query.data, uri.query.length, stream); + len += sink("?", 1, 1, stream); + len += sink(uri.query.data, 1, uri.query.length, stream); } if (uri.fragment.data) { // Note that uri.fragment.data includes the leading '#' - len += sink(uri.fragment.data, uri.fragment.length, stream); + len += sink(uri.fragment.data, 1, uri.fragment.length, stream); } - return len; } |