[#absl-UrlEscape] = xref:absl.adoc[absl]::UrlEscape :relfileprefix: ../ :mrdocs: Escapes a string so it can be safely used as a value in a URL component by replacing all characters that are not "unreserved characters" with percent‐escapes. See https://tools.ietf.org/html/rfc3986 == Synopsis Declared in `<absl/strings/escaping.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[nodiscard]] std::string UrlEscape(std::string_view input); ---- == Description Usage note: URLs use "reserved characters" (like ?, &, =, /) as structural syntax. This function escapes these syntax characters. The correct use of this function is to clean individual URL components _before_ assembling them into the final URL structure. Do not run it on a fully constructed URL, as this will turn structural delimiters into URL component data. Example (encoding "gift for mom & dad" as a URL query parameter): std::string url = absl::StrFormat("https://www.google.com/search?q=%s", absl::UrlEscape("gift for mom & dad")); assert(url == "https://www.google.com/search?q=gift%20for%20mom%20%26%20dad"); == Return Value The escaped string. [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== == Parameters [cols="1,4"] |=== | Name| Description | *input* | The URL component to escape. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#