Newlisp url encoding, newlispurl

Source: Internet
Author: User

Newlisp url encoding, newlispurl

The newlisp standard library does not support url encoding. Therefore, you can find the following code from the dragonfly library and use it after testing.

;===============================================================================; !UTF8 Compatible URL encoding/decoding;===============================================================================(constant 'REGEX_HTTP_SPECIAL_STR (regex-comp {([^.0-9a-z]+)} 1))(constant 'REGEX_HEX_ENCODED_CHAR (regex-comp {%([0-9A-F][0-9A-F])} 1))(define (hex-encode-str str , cnvrt)(setf cnvrt(dup "%%%X" (length str)))(eval (append '(format cnvrt) (unpack (dup "b" (length str)) str))));; @syntax (utf8-urlencode <str> [<bool-everything>]);; @param str the string to encode;; @param bool-everything whether to escape the entire string or just most of the "non-ascii friendly" parts.;; <p>Use this function to safely encode data that might have foreign characters in it, or simply;; characters that should be placed into URLs:</p>;; <b>example:</b>;; <pre> (utf8-urlencode "What time is it?")  => "What%20time%20is%20it%3F"</pre>(define (utf8-urlencode str everything)(if everything(hex-encode-str str)(replace REGEX_HTTP_SPECIAL_STR str (hex-encode-str $1) 0x10000)));; @syntax (utf8-urldecode <str>);; <p>Decodes a utf8-urlencoded string. Converts '+''s to spaces.</p>(define (utf8-urldecode str)(replace "+" str " ")(replace REGEX_HEX_ENCODED_CHAR str (pack "b" (int $1 nil 16)) 0x10000))




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.