From b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 15 Jun 2018 09:26:17 -0400 Subject: Bring read/write interface closer to the C standard --- src/uri.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/uri.c') diff --git a/src/uri.c b/src/uri.c index eec9c7fc..0c0f3736 100644 --- a/src/uri.c +++ b/src/uri.c @@ -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; } -- cgit v1.2.1