Loading...
Searching...
No Matches
urlparser::percent_codec Namespace Reference

Percent-encoding (RFC 3986 "quote") / percent-decoding ("unquote"). More...

Typedefs

using character_set = std::array<uint64_t, 4>

Functions

constexpr bool contains (const character_set &set, unsigned char c) noexcept
URLPARSER_API std::string decode (std::string_view input)
 Percent-decode ("unquote") a string: every XX triplet (two hex digits) becomes the corresponding byte; anything that isn't a valid XX triplet (e.g. a trailing "%", or "%" followed by non-hex digits) is left untouched, byte-for-byte, matching Python's urllib.parse.unquote() behaviour for malformed input rather than throwing.
URLPARSER_API std::string encode (std::string_view input, const character_set &safe=unreserved_set())
 Percent-encode ("quote") a string: every byte not in safe is replaced by XX (uppercase hex). Defaults to unreserved_set() (RFC 3986 unreserved characters only) when no character_set is given.
URLPARSER_API character_set path_safe_set ()
URLPARSER_API character_set unreserved_set ()

Detailed Description

Percent-encoding (RFC 3986 "quote") / percent-decoding ("unquote").

liburlparser exposes path()/query()/params() as the raw (still percent-encoded) substrings of the URL - same as the WHATWG URL standard and every URL library that follows it (including ada). None of them decode automatically, on purpose: it can be lossy/ambiguous to do so implicitly. But unlike Python's urllib.parse (quote/unquote) or ada's internal (and) ada::unicode::percent_encode/percent_decode, liburlparser did not expose any public helper to do this decoding explicitly - so callers had to reach for a second library just to read "café" out of "caf%C3%A9". This closes that gap, implemented from scratch (no external dependency): a 256-bit membership bitmap gives O(1) "does this byte need encoding" checks, and both functions do a single allocation sized to a conservative upper bound.

Typedef Documentation

◆ character_set

using urlparser::percent_codec::character_set = std::array<uint64_t, 4>

A 256-bit set of bytes, used to mark which bytes are left untouched by encode(). Bit i set means "byte value `i` is safe, do not encode it".

Function Documentation

◆ contains()

bool urlparser::percent_codec::contains ( const character_set & set,
unsigned char c )
constexprnoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode()

URLPARSER_API std::string urlparser::percent_codec::decode ( std::string_view input)

Percent-decode ("unquote") a string: every XX triplet (two hex digits) becomes the corresponding byte; anything that isn't a valid XX triplet (e.g. a trailing "%", or "%" followed by non-hex digits) is left untouched, byte-for-byte, matching Python's urllib.parse.unquote() behaviour for malformed input rather than throwing.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode()

URLPARSER_API std::string urlparser::percent_codec::encode ( std::string_view input,
const character_set & safe = unreserved_set() )

Percent-encode ("quote") a string: every byte not in safe is replaced by XX (uppercase hex). Defaults to unreserved_set() (RFC 3986 unreserved characters only) when no character_set is given.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_safe_set()

URLPARSER_API character_set urlparser::percent_codec::path_safe_set ( )

unreserved_set() plus '/' - the common default when encoding a full path component (mirrors Python's urllib.parse.quote(..., safe="/")).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unreserved_set()

URLPARSER_API character_set urlparser::percent_codec::unreserved_set ( )

RFC 3986 "unreserved" characters: A-Z a-z 0-9 - _ . ~ (the default safe set for encode()).

Here is the call graph for this function:
Here is the caller graph for this function: