Results 1 to 8 of 8

Thread: QHttpResponseHeader encode & Save COOKIE value %20

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QHttpResponseHeader encode & Save COOKIE value %20

    I'd prefer something like that (not tested):

    Qt Code:
    1. QString stringToDecode;
    2. QRegExp rx("%(\\d\\d)");
    3. int pos = 0;
    4. while((pos=rx.indexIn(stringToDecode, pos))!=-1){
    5. uint val = rx.cap(1).toUInt(0, 16);
    6. stringToDecode.replace(pos, 3, QString(QChar(val)));
    7. }
    To copy to clipboard, switch view to plain text mode 

    After this "stringToDecode" should contain the converted string.

  2. The following user says thank you to wysota for this useful post:

    patrik08 (2nd November 2006)

  3. #2
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows
    Wiki edits
    2

    Exclamation Re: QHttpResponseHeader encode & Save COOKIE value %20

    Quote Originally Posted by wysota View Post
    I'd prefer something like that (not tested):

    Qt Code:
    1. QString stringToDecode;
    2. QRegExp rx("%(\\d\\d)");
    3. int pos = 0;
    4. while((pos=rx.indexIn(stringToDecode, pos))!=-1){
    5. uint val = rx.cap(1).toUInt(0, 16);
    6. stringToDecode.replace(pos, 3, QString(QChar(val)));
    7. }
    To copy to clipboard, switch view to plain text mode 

    After this "stringToDecode" should contain the converted string.
    I recommend this code - it eliminates errors caused by previous code (hex A-F are not decimal = unrecognized by previous code, "hi%25there" represents "hi%there" = causes unwanted character creation "%th" - last replaced character has to be jumped over)

    Qt Code:
    1. QString stringToDecode;
    2. QRegExp rx("%(\\S\\S)");
    3. int pos = 0;
    4. while ((pos = rx.indexIn(stringToDecode, pos)) != -1) {
    5. stringToDecode.replace(pos, 3, QString(QChar(rx.cap(1).toUInt(0, 16))));
    6. pos++; // jumps over currently replaced character
    7. }
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.