newLISP URL Encoding

Source: Internet
Author: User
Tags urlencode

The NEWLISP standard library does not provide URL-encoded support, so find the following code from the Dragonfly library, which can be used for 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 cn VRT) (Unpack (DUP "B" (length 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 has foreign characters in it, or simply;; Characters that should is placed into urls:</p>;; <b>example:</b>;;  <pre> (Utf8-urlencode "What's 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 $) 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 (p Ack "B" (int nil)) 0x10000))




newLISP URL Encoding

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.