Expand description
RFC 3986 percent-encoding utilities.
Pure-std, in-house replacement for the external urlencoding crate with
1:1 API semantics so call sites translate directly:
percent_encodemirrorsurlencoding::encode: every byte outside the RFC 3986 unreserved set (A-Z a-z 0-9 - _ . ~) is encoded as%XXwith uppercase hexadecimal digits. Spaces become%20(never+).percent_decodemirrorsurlencoding::decode:%XXsequences are decoded case-insensitively, malformed or truncated%runs are passed through unchanged, and an error is returned only when the decoded bytes are not valid UTF-8.percent_encode_strictmirrorspercent_encoding::NON_ALPHANUMERIC: every byte that is not an ASCII alphanumeric is encoded, including the unreserved punctuation- _ . ~(so_becomes%5F). Used where form-style strict encoding is the established wire contract (e.g. OAuth2 query parameters).
All functions return Cow::Borrowed when the input needs no changes,
avoiding allocation on the fast path.
§Examples
use oxirs_core::encoding::{percent_encode, percent_decode};
let encoded = percent_encode("SELECT * WHERE { ?s ?p ?o }");
assert_eq!(
encoded,
"SELECT%20%2A%20WHERE%20%7B%20%3Fs%20%3Fp%20%3Fo%20%7D"
);
assert_eq!(percent_decode(&encoded)?, "SELECT * WHERE { ?s ?p ?o }");Functions§
- percent_
decode - Decodes a percent-encoded string per RFC 3986.
- percent_
encode - Percent-encodes a string per RFC 3986.
- percent_
encode_ strict - Percent-encodes a string, escaping every byte that is not an ASCII
alphanumeric character (
A-Z a-z 0-9).