Audacity 3.2.0
UrlDecode.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file UrlDecode.cpp
6 @brief Define a function to decode an URL encode string.
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11#include "UrlDecode.h"
12
13#include "HexHelpers.h"
14
15namespace audacity
16{
17
18std::string UrlDecode (const std::string& url)
19{
20 std::string result;
21
22 const size_t length = url.length ();
23
24 for (auto it = url.begin (), end = url.end (); it != end; ++it)
25 {
26 const char c = *it;
27
28 if (c != '%')
29 {
30 result.push_back (c);
31 }
32 else
33 {
34 if (++it == url.end ())
35 break; // Malformed input string
36
37 const char c1 = *it;
38
39 if (++it == url.end ())
40 break; // Malformed input string
41
42 const char c2 = *it;
43
44 result.push_back (HexCharToNum (c1) << 4 | HexCharToNum (c2));
45 }
46 }
47
48 return result;
49}
50
51}
Define helper functions for hex-to-num conversion.
Declare a function to decode an URL encode string.
uint8_t HexCharToNum(char c) noexcept
Definition: HexHelpers.h:20
std::string UrlDecode(const std::string &url)
Definition: UrlDecode.cpp:18
const char * end(const char *str) noexcept
Definition: StringUtils.h:106