aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/string.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-09-29 10:36:32 +0200
committerGitHub Enterprise <[email protected]>2025-09-29 10:36:32 +0200
commit2f0efec7ab0430f4f4858db87b7eecfbccc0f47c (patch)
tree80ce35992a220260cf070fac739626f555de738a /src/zencore/string.cpp
parentfixed race condition in zen::logging::Get (#519) (diff)
downloadzen-2f0efec7ab0430f4f4858db87b7eecfbccc0f47c.tar.xz
zen-2f0efec7ab0430f4f4858db87b7eecfbccc0f47c.zip
make cpr a HttpClient implementation detail (#517)
these changes remove cpr from anything which is not `HttpClient` internals. The goal is to eventually replace cpr with a more direct curl interface to eliminate cpr since it's proven problematic due to their development practices which frequently breaks APIs and prevents us from updating vcpkg. But this PR is limited to refactoring existing cpr code to use `HttpClient` instead.
Diffstat (limited to 'src/zencore/string.cpp')
-rw-r--r--src/zencore/string.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/zencore/string.cpp b/src/zencore/string.cpp
index a0d8c927f..c8c7c2cde 100644
--- a/src/zencore/string.cpp
+++ b/src/zencore/string.cpp
@@ -483,12 +483,67 @@ template class StringBuilderImpl<char>;
template class StringBuilderImpl<wchar_t>;
//////////////////////////////////////////////////////////////////////////
+
+void
+UrlDecode(std::string_view InUrl, StringBuilderBase& OutUrl)
+{
+ std::string_view::size_type i = 0;
+
+ for (; i != InUrl.size();)
+ {
+ char c = InUrl[i];
+
+ if ((c == '%') && ((i + 2) < InUrl.size()))
+ {
+ char hex[2] = {InUrl[i + 1], InUrl[i + 2]};
+ uint8_t HexedChar;
+ if (ParseHexBytes(hex, 2, &HexedChar))
+ {
+ OutUrl.Append(HexedChar);
+ i += 3;
+
+ continue;
+ }
+ }
+
+ OutUrl.Append(c);
+ ++i;
+ }
+}
+
+std::string
+UrlDecode(std::string_view InUrl)
+{
+ ExtendableStringBuilder<128> Url;
+ UrlDecode(InUrl, Url);
+
+ return std::string(Url.ToView());
+}
+
+//////////////////////////////////////////////////////////////////////////
//
// Unit tests
//
#if ZEN_WITH_TESTS
+TEST_CASE("url")
+{
+ using namespace std::literals;
+
+ ExtendableStringBuilder<32> OutUrl;
+ UrlDecode("http://blah.com/foo?bar=hi%20ho", OutUrl);
+ CHECK_EQ(OutUrl.ToView(), "http://blah.com/foo?bar=hi ho"sv);
+
+ OutUrl.Reset();
+
+ UrlDecode("http://blah.com/foo?bar=hi%ho", OutUrl);
+ CHECK_EQ(OutUrl.ToView(), "http://blah.com/foo?bar=hi%ho"sv);
+
+ CHECK_EQ(UrlDecode("http://blah.com/foo?bar=hi%20ho"), "http://blah.com/foo?bar=hi ho"sv);
+ CHECK_EQ(UrlDecode("http://blah.com/foo?bar=hi%ho"), "http://blah.com/foo?bar=hi%ho"sv);
+}
+
TEST_CASE("niceNum")
{
char Buffer[16];