Add Url/Html encoding, ISO-8601 interval parse, TempFile, random_string charset

Universal additions (all generic, header-only, tested; full suite 1127 pass):
- Void::Encoding::Url — RFC 3986 percent encode/decode + query_encode.
- Void::Text::html_unescape — numeric + common named HTML entities -> UTF-8.
- Void::Time::parse_iso8601_interval — parse PT#H#M#S / P#DT#H#M#S durations
  (distinct from the unit-suffix parse_duration).
- Void::FileSystem::TempFile — RAII unique temp file (alongside TempDir),
  with keep() to persist.
- Void::Random::random_string(n, charset) overload.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-22 16:15:01 +03:00
1 parent 80293ee56f
commit fb0506581f
9 files changed
+645 -6

No files matched your search

+81
View File
@@ -1,5 +1,7 @@
#include <Void/Text/Base64.hpp>
#include <Void/Text/Hex.hpp>
#include <Void/Text/Html.hpp>
#include <Void/Text/Url.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
@@ -157,3 +159,82 @@ Void::Testing::Test hex_round_trip()
Void::Testing::expect(decoded.has_value());
Void::Testing::expect_eq(*decoded, original);
}
// ── URL / percent encoding ─────────────────────────────────────────────────────
Void::Testing::Test url_encode_unreserved_passthrough()
{
Void::Testing::expect_eq(Void::Encoding::Url::encode("AZaz09-._~"),
std::string{"AZaz09-._~"});
}
Void::Testing::Test url_encode_reserved()
{
Void::Testing::expect_eq(Void::Encoding::Url::encode("a b/c?d=e&f"),
std::string{"a%20b%2Fc%3Fd%3De%26f"});
}
Void::Testing::Test url_query_encode_space_as_plus()
{
Void::Testing::expect_eq(Void::Encoding::Url::query_encode("a b c"),
std::string{"a+b+c"});
}
Void::Testing::Test url_decode_basic()
{
const auto r = Void::Encoding::Url::decode("a%20b%2Fc");
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, std::string{"a b/c"});
}
Void::Testing::Test url_decode_plus_as_space()
{
const auto r = Void::Encoding::Url::decode("a+b", /*plus_as_space=*/true);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, std::string{"a b"});
}
Void::Testing::Test url_decode_malformed_fails()
{
Void::Testing::expect(!Void::Encoding::Url::decode("a%2").has_value());
Void::Testing::expect(!Void::Encoding::Url::decode("a%zz").has_value());
}
Void::Testing::Test url_round_trip_utf8()
{
const std::string original = "café/naïve?x=1 2";
const auto enc = Void::Encoding::Url::encode(original);
const auto dec = Void::Encoding::Url::decode(enc);
Void::Testing::expect(dec.has_value());
Void::Testing::expect_eq(*dec, original);
}
// ── HTML entity decoding ───────────────────────────────────────────────────────
Void::Testing::Test html_named_entities()
{
Void::Testing::expect_eq(
Void::Text::html_unescape("a &amp; b &lt; c &gt; d &quot;e&quot;"),
std::string{"a & b < c > d \"e\""});
}
Void::Testing::Test html_numeric_decimal()
{
Void::Testing::expect_eq(Void::Text::html_unescape("&#65;&#66;&#67;"),
std::string{"ABC"});
}
Void::Testing::Test html_numeric_hex_utf8()
{
// U+1F600 grinning face -> 4-byte UTF-8
const auto r = Void::Text::html_unescape("&#x1F600;");
Void::Testing::expect_eq(r.size(), std::size_t{4});
}
Void::Testing::Test html_unknown_left_verbatim()
{
Void::Testing::expect_eq(Void::Text::html_unescape("a &bogus; b"),
std::string{"a &bogus; b"});
Void::Testing::expect_eq(Void::Text::html_unescape("plain & text"),
std::string{"plain & text"});
}