From b7cce4a24dbc544129a9fabc44cb22025767f10b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 28 Feb 2021 14:24:24 -0500 Subject: Make serd_uri_string_length() precise and add it to public API --- include/serd/uri.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/serd/uri.h b/include/serd/uri.h index 93409075..3170fa89 100644 --- a/include/serd/uri.h +++ b/include/serd/uri.h @@ -122,6 +122,17 @@ serd_relative_uri(SerdURIView r, SerdURIView base); SERD_PURE_API bool serd_uri_is_within(SerdURIView r, SerdURIView base); +/** + Return the length of `uri` as a string. + + This can be used to get the expected number of bytes that will be written by + serd_write_uri(). + + @return A string length in bytes, not including the null terminator. +*/ +SERD_PURE_API size_t +serd_uri_string_length(SerdURIView uri); + /** Write `uri` as a string to `sink`. @@ -130,7 +141,9 @@ serd_uri_is_within(SerdURIView r, SerdURIView base); @param uri URI to write as a string. @param sink Sink to write string output to. @param stream Opaque user argument to pass to `sink`. - @return The number of bytes written. + + @return The number of bytes written, which is less than + `serd_uri_string_length(uri)` on error. */ SERD_API size_t serd_write_uri(SerdURIView uri, -- cgit v1.2.1