1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-17 00:07:54 +01:00

Adds lib-string-utils

This commit is contained in:
Dmitry Vedenko
2021-05-25 16:07:10 +03:00
parent 733cf89cff
commit 52a835bd61
11 changed files with 356 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
/*!********************************************************************
Audacity: A Digital Audio Editor
@file UrlDecode.cpp
@brief Define a function to decode an URL encode string.
Dmitry Vedenko
**********************************************************************/
#include "UrlDecode.h"
#include "HexHelpers.h"
namespace audacity
{
std::string UrlDecode (const std::string& url)
{
std::string result;
const size_t length = url.length ();
for (auto it = url.begin (), end = url.end (); it != end; ++it)
{
const char c = *it;
if (c != '%')
{
result.push_back (c);
}
else
{
if (++it == url.end ())
break; // Malformed input string
const char c1 = *it;
if (++it == url.end ())
break; // Malformed input string
const char c2 = *it;
result.push_back (HexCharToNum (c1) << 4 | HexCharToNum (c2));
}
}
return result;
}
}