Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

What does "URLEncode" stand for?

(1/1)

BlueHazzard:
Hi, i try to write a test bench for the scripting binding, and found this function:


--- Code: ---wxString URLEncode(const wxString &str) // not sure this is 100% standards compliant, but I hope so
{
    wxString ret;
    wxString t;
    for (unsigned int i = 0; i < str.length(); ++i)
    {
        wxChar c = str[i];
        if (  (c >= _T('A') && c <= _T('Z'))
           || (c >= _T('a') && c <= _T('z'))
           || (c >= _T('0') && c <= _T('9'))
           || (c == _T('.'))
           || (c == _T('-'))
           || (c == _T('_')) )

            ret.Append(c);
        else if (c == _T(' '))
            ret.Append(_T('+'));
        else
        {
            t.sprintf(_T("%%%02X"), (unsigned int) c);
            ret.Append(t);
        }
    }
    return ret;
}

--- End code ---

What does this encoding stand for? As far as i know in URL Encoding the " " gets "%20" and not "+" like in this encoding...

greetings

oBFusCATed:
It just converts the character to two hex numbers. I think. Space is 32==20 in hex.

BlueHazzard:
then the current implementation is wrong:
see line

--- Code: ---else if (c == _T(' '))
            ret.Append(_T('+'));
--- End code ---

Alpha:

--- Quote from: BlueHazzard on February 03, 2015, 12:36:32 am ---As far as i know in URL Encoding the " " gets "%20" and not "+" like in this encoding...

--- End quote ---
According to this, both "%20" and "+" are valid alternatives.

Navigation

[0] Message Index

Go to full version