Static Public Member Functions | List of all members
UrlDecode Struct Reference

Utility for splitting and decoding URL encoded data. More...

#include <UrlDecode.hpp>

Static Public Member Functions

static std::string decode (const std::string_view input, bool validateUtf8=true, bool throwOnError=false)
 Decode the percent encoded input string into a UTF-8 string, according to the following rules. More...
 
static std::unordered_map< std::string_view, std::string_view > split (const std::string_view data)
 Split the URL encoded parameters into a map of string views. More...
 
static std::unordered_map< std::string, std::string > splitAndDecode (const std::string_view &data, bool validateUtf8=true, bool throwOnError=false)
 Split the URL encoded parameters then decode each one. More...
 

Detailed Description

Utility for splitting and decoding URL encoded data.

Member Function Documentation

◆ decode()

static std::string decode ( const std::string_view  input,
bool  validateUtf8 = true,
bool  throwOnError = false 
)
inlinestatic

Decode the percent encoded input string into a UTF-8 string, according to the following rules.

  • If the character is a '+', decode it as a space.
  • If the character is a '', consume characters according to the decode algorithm given below.
  • Otherwise, output the character as is.

The decode algorithm is as follows.

  • Decode all successive sequences of XX, where each X is a hexadecimal ascii character in the ranges '0' to '9', 'a' to 'f', and 'A' to 'F', into bytes corresponding to the value obtained by converting the hexadecimal XX into an unsigned integer.
  • Optionally, verify that the resulting byte sequence is valid UTF-8.
Parameters
inputthe percent encoded input string
validateUtf8if true, the decoded percent encoded data will only be added if it is valid UTF-8
throwOnErrorif true, errors will cause an exception to be thrown instead of being silently ignored
Exceptions
NetworkExceptionif throwOnError was set to true and the input was invalid

◆ split()

static std::unordered_map<std::string_view, std::string_view> split ( const std::string_view  data)
inlinestatic

Split the URL encoded parameters into a map of string views.

The caller is responsible for maintaining the original string onto which the views are pointing.

Parameters
datathe input string view containing the URL encoded parameters
Returns
a hash map of split parameters, represented by string views onto the input string
Exceptions
NetworkExceptionif the parameter list was invalid

◆ splitAndDecode()

static std::unordered_map<std::string, std::string> splitAndDecode ( const std::string_view &  data,
bool  validateUtf8 = true,
bool  throwOnError = false 
)
inlinestatic

Split the URL encoded parameters then decode each one.

Parameters
datathe input string containing the URL encoded parameters
Returns
a hash map of split parameters, represented by strings
Exceptions
NetworkExceptionif the parameter list was invalid

The documentation for this struct was generated from the following file: