{"id":8230,"date":"2023-01-07T15:26:19","date_gmt":"2023-01-07T07:26:19","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=8230"},"modified":"2023-01-07T15:26:19","modified_gmt":"2023-01-07T07:26:19","slug":"url%e7%bc%96%e8%a7%a3%e7%a0%81","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=8230","title":{"rendered":"url\u7f16\u89e3\u7801"},"content":{"rendered":"<pre><code class=\"language-cpp\">#include &lt;iostream&gt;\n#include &lt;assert.h&gt;\n\nusing namespace std;\n\nunsigned char ToHex(unsigned char x) \n{ \n    return  x &gt; 9 ? x + 55 : x + 48; \n}\n\nunsigned char FromHex(unsigned char x) \n{ \n    unsigned char y;\n    if (x &gt;= &#039;A&#039; &amp;&amp; x &lt;= &#039;Z&#039;) y = x - &#039;A&#039; + 10;\n    else if (x &gt;= &#039;a&#039; &amp;&amp; x &lt;= &#039;z&#039;) y = x - &#039;a&#039; + 10;\n    else if (x &gt;= &#039;0&#039; &amp;&amp; x &lt;= &#039;9&#039;) y = x - &#039;0&#039;;\n    else assert(0);\n    return y;\n}\n\nstd::string UrlEncode(const std::string&amp; str)\n{\n    std::string strTemp = &quot;&quot;;\n    size_t length = str.length();\n    for (size_t i = 0; i &lt; length; i++)\n    {\n        if (isalnum((unsigned char)str[i]) || \n            (str[i] == &#039;-&#039;) ||\n            (str[i] == &#039;_&#039;) || \n            (str[i] == &#039;.&#039;) || \n            (str[i] == &#039;~&#039;))\n            strTemp += str[i];\n        else if (str[i] == &#039; &#039;)\n            strTemp += &quot;+&quot;;\n        else\n        {\n            strTemp += &#039;%&#039;;\n            strTemp += ToHex((unsigned char)str[i] &gt;&gt; 4);\n            strTemp += ToHex((unsigned char)str[i] % 16);\n        }\n    }\n    return strTemp;\n}\n\nstd::string UrlDecode(const std::string&amp; str)\n{\n    std::string strTemp = &quot;&quot;;\n    size_t length = str.length();\n    for (size_t i = 0; i &lt; length; i++)\n    {\n        if (str[i] == &#039;+&#039;) strTemp += &#039; &#039;;\n        else if (str[i] == &#039;%&#039;)\n        {\n            assert(i + 2 &lt; length);\n            unsigned char high = FromHex((unsigned char)str[++i]);\n            unsigned char low = FromHex((unsigned char)str[++i]);\n            strTemp += high*16 + low;\n        }\n        else strTemp += str[i];\n    }\n    return strTemp;\n}\n\nint main(int argc,char *argv[])\n{\n\n    string unencode_url(argv[1]);\n    cout &lt;&lt; &quot;unencode_url: &quot; &lt;&lt; unencode_url &lt;&lt; endl;\n    string   encode_url = UrlEncode(unencode_url);\n    cout &lt;&lt; &quot;encode_url: &quot; &lt;&lt; encode_url &lt;&lt; endl;   \n    string   decode_url = UrlDecode(encode_url);\n    cout &lt;&lt; &quot;decode_url: &quot; &lt;&lt; decode_url &lt;&lt; endl;    \n}<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"8230\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>#include &lt;iostream&gt; #include &lt;assert.h&#038;gt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[610],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/8230"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8230"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/8230\/revisions"}],"predecessor-version":[{"id":8231,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/8230\/revisions\/8231"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8230"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}