C + + URL Encode/decode (gb2312)

Source: Internet
Author: User

    Char Dec2hexchar (short int n) {if (0 <= n && n <= 9) {return char          (' 0 ') + N);          } else if (<= n && n <=) {return char (short (' A ') + n-10);          } else {return char (0); }}} short int hexchar2dec (char c) {if (' 0 ' <=c && c<= ' 9 ') {RET          Urn Short (c ' 0 ');          } else if (' a ' <=c && c<= ' F ') {return (short (c ' a ') + 10);          } else if (' A ' <=c && c<= ' F ') {return (short (c ' a ') + 10);          } else {return-1;          }} string Encodeurl (const string &url) {string strresult = "";              for (unsigned int i=0; i<url.size (); i++) {char c = url[i];                  if (' 0 ' <=c && c<= ' 9 ') | | (' A ' <=c && c< = ' Z ') | |                  (' A ' <=c && c<= ' Z ') | | c== '/' | |                  c== '. '              ) {strresult + = C;                  } else {int j = (short int) C;                  if (J < 0) {j + = 256;                  } int i1, i0;                  I1 = J/16;                  I0 = j-i1*16;                  strresult + = '% ';                  Strresult + = Dec2hexchar (I1);              Strresult + = Dec2hexchar (I0);      }} return strresult;          } std::string decodeurl (const std::string &url) {string result = "";              for (unsigned int i=0; i<url.size (); i++) {char c = url[i];              if (c! = '% ') {result + = C;        } else {char C1 = url[++i];          char c0 = url[++i];                  int num = 0;                  num + = HEXCHAR2DEC (C1) * + HEXCHAR2DEC (C0);              Result + = char (num);      }} return result;   }

C + + URL Encode/decode (gb2312)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.