added: to misc:

UrlEncode() for char->wstring
         UrlEncode() for wstring->wstring
removed: Request::redirect_url_encoded flag
         the Request::redirect_to string should always be url-encoded
changed: in UrnEncode()
         now characters like '#' and '/' are not allowed in an url
         (will be url-encoded)
         


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@807 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-02-19 00:59:08 +00:00
parent 1a51b1adc7
commit 97c7edafd6
7 changed files with 130 additions and 50 deletions

View File

@@ -991,49 +991,66 @@ return res;
void UrlEncode(const std::string & in, std::string & out, bool clear_out)
void UrlEncode(const char * in, std::string & out, bool clear_out)
{
char buffer[10];
if( clear_out )
out.clear();
// !! we should not use such characters here: '/' '#'
for(size_t i=0 ; i<in.size() ; ++i)
{
if( (in[i] >= 'a' && in[i] <= 'z') ||
(in[i] >= 'A' && in[i] <= 'Z') ||
(in[i] >= '0' && in[i] <= '9') ||
in[i] == '.' || in[i] == ',' || in[i] == '/' || in[i] == ':' || in[i] == '#' ||
in[i] == '-' || in[i] == '_' || in[i] == '(' || in[i] == ')' )
{
out += in[i];
}
else
{
Toa(static_cast<unsigned char>(in[i]), buffer, 10, 16);
out += '%';
if( buffer[1] == 0 )
out += '0'; // there is only one character in the buffer
out += buffer;
}
}
for(size_t i=0 ; in[i] != 0 ; ++i)
UrlEncode(in[i], out, false);
}
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out)
void UrlEncode(const std::string & in, std::string & out, bool clear_out)
{
UrlEncode(in.c_str(), out, clear_out);
}
void UrlEncode(const wchar_t * in, std::string & out, bool clear_out)
{
static std::string ain;
PT::WideToUTF8(in, ain);
UrlEncode(ain, out, clear_out);
if( clear_out )
out.clear();
for(size_t i=0 ; i < ain.size() ; ++i)
UrlEncode(ain[i], out, false);
}
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out)
{
UrlEncode(in.c_str(), out, clear_out);
}
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out)
{
static std::string ain;
PT::WideToUTF8(in, ain);
if( clear_out )
out.clear();
for(size_t i=0 ; i < ain.size() ; ++i)
UrlEncode(ain[i], out, false);
}
void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out)
{
UrlEncode(in.c_str(), out, clear_out);
}
void QEncodeAddChar(wchar_t c, std::string & out)
{