|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
Implements URI percent-encoding and decoding utilities. More...
Functions | |
| std::string | encode (const std::string_view &input) |
| Encode a string into URI percent-encoded form. | |
| std::string | decode (const std::string_view &input) |
| Decode a percent-encoded URI string. | |
| std::string | encode_safe (const std::string_view &input) |
| Encode a string into URI percent-encoded form with legality validation. | |
| std::string | decode_safe (const std::string_view &input) |
| Decode a percent-encoded URI string with output validation. | |
Implements URI percent-encoding and decoding utilities.
URI percent-encoding converts unsafe characters into a textual representation using the %XX hexadecimal format. This ensures that arbitrary data can be safely embedded within URI strings and transported through text-based protocols such as HTTP, REST APIs, or web forms.
This namespace provides high-level wrappers built on top of the optimized primitives in jh::detail::uri_common.
Whether to use the unchecked version has no impact on performance. The additional checks in the *_safe functions are nearly equivalent to traversing a string_view.
jh::serio::base64 and jh::serio::base64url. URI percent-encoding is primarily intended for encoding textual data.
|
nodiscard |
Decode a percent-encoded URI string.
This function converts percent-encoded sequences (%XX) back into their original byte representation.
The input is validated to ensure that all percent-encoded sequences are syntactically correct.
| input | Percent-encoded URI string. |
| std::runtime_error | Thrown if the input contains malformed percent-encoding. |
|
nodiscard |
Decode a percent-encoded URI string with output validation.
This function first performs percent-decoding and then verifies that the resulting string is a legal textual representation.
| input | Percent-encoded URI string. |
| std::runtime_error | If the input contains malformed percent-encoding. Or if the decoded result is not a legal UTF-8 string. |
|
nodiscard |
Encode a string into URI percent-encoded form.
Characters that are not part of the unreserved URI character set are converted into their percent-encoded representation (%XX).
This function performs no input validation and assumes that the input string is already legal UTF-8.
| input | Input string to encode. |
encode_safe() when input validation is required.
|
nodiscard |
Encode a string into URI percent-encoded form with legality validation.
This variant verifies that the input string represents a legal textual payload before performing the encoding.
| input | Input string to encode. |
| std::runtime_error | Thrown if the input string contains invalid UTF-8 or control characters. |
encode().