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.
Loading...
Searching...
No Matches
uri.h File Reference

High-level URI percent-encoding and decoding interface for the JH Toolkit. More...

#include <string>
#include <vector>
#include <stdexcept>
#include "jh/macros/header_begin.h"
#include "jh/macros/header_end.h"

Go to the source code of this file.

Namespaces

namespace  jh::serio
 Aggregated entry point for serialization and codec utilities.
namespace  jh::serio::uri
 Implements URI percent-encoding and decoding utilities.

Functions

std::string jh::serio::uri::encode (const std::string_view &input)
 Encode a string into URI percent-encoded form.
std::string jh::serio::uri::decode (const std::string_view &input)
 Decode a percent-encoded URI string.
std::string jh::serio::uri::encode_safe (const std::string_view &input)
 Encode a string into URI percent-encoded form with legality validation.
std::string jh::serio::uri::decode_safe (const std::string_view &input)
 Decode a percent-encoded URI string with output validation.

Detailed Description

High-level URI percent-encoding and decoding interface for the JH Toolkit.

Author
JeongHan-Bae <mastropseudo@gmail.com>

This header provides a modern, safe, and portable implementation of URI percent-encoding and percent-decoding. It belongs to the JH Toolkit Serialization I/O module (jh::serio) and provides text-safe encoding utilities for URI and URL components.

Design overview

  • Implements URI percent-encoding according to RFC 3986.
  • Provides both unchecked and validated encoding/decoding interfaces.
  • Supports fast encoding using precomputed character classification.
  • Validation-aware APIs ensure UTF-8 correctness and prevent control characters.
  • Fully portable and suitable for network, HTTP, and web serialization.
Note
Unlike the base64 module, although the uri module could theoretically support constexpr at the implementation level, it does not provide a compile-time solution like jh::meta::base64.
This is because, in practical use, jh::meta::base64 enables embedding NTTP strings via macros and parsing them into binary resources.
However, URI processing does not require this capability. The data handled by URI is semantically UTF-8 strings, which should only be utilized within the runtime serialization module jh::serio.
This header participates in the Dual-Mode Header system of the JH Toolkit.
  • Linked through jh::jh-toolkit โ€” the module behaves as a header-only implementation compiled in user translation units.
  • Linked through jh::jh-toolkit-static โ€” the module uses a precompiled implementation built with aggressive optimization (typically -O3).
This design allows fast incremental builds while preserving the option of using a fully optimized static implementation.
Version
1.4.1
Date
2025