diff options
author | David Robillard <d@drobilla.net> | 2021-01-13 14:31:00 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-07 15:32:23 -0500 |
commit | a7be33a7640ee51066c41eded5812d9cee5ad27e (patch) | |
tree | 8c2cbe96a6973c73320ff793d452e36fe511b745 /src/uri.c | |
parent | 96bcba9cd94879794de477ae7c5c04971fbd6f32 (diff) | |
download | serd-a7be33a7640ee51066c41eded5812d9cee5ad27e.tar.gz serd-a7be33a7640ee51066c41eded5812d9cee5ad27e.tar.bz2 serd-a7be33a7640ee51066c41eded5812d9cee5ad27e.zip |
Add SerdBuffer type for mutable buffers
This avoids const violations from abusing SerdChunk as a mutable buffer
for string sinks.
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -41,7 +41,6 @@ serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname) if (!(path = (const uint8_t*)strchr((const char*)auth, '/'))) { return NULL; } - if (hostname) { *hostname = (uint8_t*)calloc((size_t)(path - auth + 1), 1); memcpy(*hostname, auth, (size_t)(path - auth)); @@ -53,26 +52,25 @@ serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname) ++path; } - SerdChunk chunk = {NULL, 0}; + SerdBuffer buffer = {NULL, 0}; for (const uint8_t* s = path; *s; ++s) { if (*s == '%') { if (*(s + 1) == '%') { - serd_chunk_sink("%", 1, &chunk); + serd_buffer_sink("%", 1, &buffer); ++s; } else if (is_hexdig(*(s + 1)) && is_hexdig(*(s + 2))) { const uint8_t code[3] = {*(s + 1), *(s + 2), 0}; const uint8_t c = (uint8_t)strtoul((const char*)code, NULL, 16); - serd_chunk_sink(&c, 1, &chunk); + serd_buffer_sink(&c, 1, &buffer); s += 2; } else { s += 2; // Junk escape, ignore } } else { - serd_chunk_sink(s, 1, &chunk); + serd_buffer_sink(s, 1, &buffer); } } - - return serd_chunk_sink_finish(&chunk); + return serd_buffer_sink_finish(&buffer); } bool |