mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-08 23:45:37 +01:00
Adds lib-string-utils
This commit is contained in:
44
libraries/lib-string-utils/UrlEncode.cpp
Normal file
44
libraries/lib-string-utils/UrlEncode.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*!********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
@file UrlEncode.cpp
|
||||
@brief Define a function to perfom URL encoding of a string.
|
||||
|
||||
Dmitry Vedenko
|
||||
**********************************************************************/
|
||||
|
||||
#include "UrlEncode.h"
|
||||
|
||||
namespace audacity
|
||||
{
|
||||
|
||||
std::string UrlEncode (const std::string& url)
|
||||
{
|
||||
std::string escaped;
|
||||
|
||||
for (char c : url)
|
||||
{
|
||||
if (('0' <= c && c <= '9') ||
|
||||
('A' <= c && c <= 'Z') ||
|
||||
('a' <= c && c <= 'z') ||
|
||||
(c == '~' || c == '-' || c == '_' || c == '.')
|
||||
)
|
||||
{
|
||||
escaped.push_back (c);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const char symbolLookup[] = "0123456789ABCDEF";
|
||||
|
||||
escaped.push_back ('%');
|
||||
|
||||
escaped.push_back (symbolLookup[(c & 0xF0) >> 4]);
|
||||
escaped.push_back (symbolLookup[(c & 0x0F) >> 0]);
|
||||
}
|
||||
}
|
||||
|
||||
return escaped;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user