Audacity 3.2.0
UrlEncode.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file UrlEncode.cpp
6 @brief Define a function to perform URL encoding of a string.
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11#include "UrlEncode.h"
12
13namespace audacity
14{
15
16std::string UrlEncode (const std::string& url)
17{
18 std::string escaped;
19
20 for (char c : url)
21 {
22 if (('0' <= c && c <= '9') ||
23 ('A' <= c && c <= 'Z') ||
24 ('a' <= c && c <= 'z') ||
25 (c == '~' || c == '-' || c == '_' || c == '.')
26 )
27 {
28 escaped.push_back (c);
29 }
30 else
31 {
32 static const char symbolLookup[] = "0123456789ABCDEF";
33
34 escaped.push_back ('%');
35
36 escaped.push_back (symbolLookup[(c & 0xF0) >> 4]);
37 escaped.push_back (symbolLookup[(c & 0x0F) >> 0]);
38 }
39 }
40
41 return escaped;
42}
43
44}
Declare a function to perform URL encoding of a string.
std::string UrlEncode(const std::string &url)
Definition: UrlEncode.cpp:16