31 #include "../Exception.h" 32 #include "../translator/Translator.h" 33 #include "../utils/HexUtils.h" 40 #include <boost/format.hpp> 41 #include <boost/tokenizer.hpp> 43 std::map<std::string, std::string>
46 std::map<std::string, std::string> result;
48 boost::char_separator<char> kvp_sep(
"&");
50 boost::tokenizer<boost::char_separator<char> > key_value_pairs(query_str, kvp_sep);
52 boost::tokenizer<boost::char_separator<char> >::iterator ikv_pair = key_value_pairs.begin();
54 while(ikv_pair != key_value_pairs.end())
56 std::string kv = *ikv_pair;
58 boost::char_separator<char> kv_sep(
"=");
60 boost::tokenizer<boost::char_separator<char> > key_value_pair(kv, kv_sep);
62 boost::tokenizer<boost::char_separator<char> >::iterator ikv = key_value_pair.begin();
64 if(ikv == key_value_pair.end())
66 boost::format err_msg(
TE_TR(
"Invalid key-value pair format in query string!"));
74 if (ikv == key_value_pair.end())
76 boost::format err_msg(
TE_TR(
"Invalid key-value pair format in query string!"));
84 result[k] = decodedValue;
95 const unsigned char * pSrc = (
const unsigned char *)srcUri.c_str();
96 const size_t SRC_LEN = srcUri.length();
97 const unsigned char *
const SRC_END = pSrc + SRC_LEN;
98 const unsigned char *
const SRC_LAST_DEC = SRC_END - 2;
100 char *
const pStart =
new char[SRC_LEN];
101 char * pEnd = pStart;
103 while (pSrc < SRC_LAST_DEC)
107 char * hex =
new char[2];
108 hex[0] = *(pSrc + 1);
109 hex[1] = *(pSrc + 2);
124 while (pSrc < SRC_END)
127 std::string sResult(pStart, pEnd);
135 const unsigned char * pSrc = (
const unsigned char *)srcUri.c_str();
136 const size_t SRC_LEN = srcUri.length();
137 unsigned char *
const pStart =
new unsigned char[SRC_LEN * 3];
138 unsigned char * pEnd = pStart;
139 const unsigned char *
const SRC_END = pSrc + SRC_LEN;
141 for (; pSrc < SRC_END; ++pSrc)
143 const char& c = *pSrc;
144 if ((48 <= c && c <= 57) ||
145 (65 <= c && c <= 90) ||
146 (97 <= c && c <= 122) ||
147 (c==
'-' || c==
'_' || c==
'.' || c==
'~'))
155 char* res =
new char[2];
166 std::string sResult((
char *)pStart, (
char *)pEnd);
TECOREEXPORT std::string URIEncode(const std::string &srcUri)
Encodes an decoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
#define TE_TR(message)
It marks a string in order to get translated.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
char Hex2Char(const char *hex)
It converts the character from a hex representation to a byte.
This file contains utility functions used to manipulate data from a URI.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
void Char2Hex(unsigned char c, char *r)
It converts the character to a hex representation.
TECOREEXPORT std::string URIDecode(const std::string &srcUri)
Decodes an encoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
Base exception class for TerraLib Core Runtime Library.