September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,23 @@
(defun decode (string &key start)
(assert (char= (char string start) #\%))
(if (>= (length string) (+ start 3))
(multiple-value-bind (code pos)
(parse-integer string :start (1+ start) :end (+ start 3) :radix 16 :junk-allowed t)
(if (= pos (+ start 3))
(values (code-char code) pos)
(values #\% (1+ start))))
(values #\% (1+ start))))
(defun url-decode (url)
(loop with start = 0
for pos = (position #\% url :start start)
collect (subseq url start pos) into chunks
when pos
collect (multiple-value-bind (decoded next) (decode url :start pos)
(setf start next)
(string decoded))
into chunks
while pos
finally (return (apply #'concatenate 'string chunks))))
(url-decode "http%3A%2F%2Ffoo%20bar%2F")

View file

@ -0,0 +1,13 @@
import Data.Char (chr)
import Data.List.Split (splitOn)
deCode :: String -> String
deCode url =
let ps = splitOn "%" url
in concat $
head ps :
((\(a, b) -> (chr . read) (mappend "0x" a) : b) <$> (splitAt 2 <$> tail ps))
-- TEST ------------------------------------------------------------------------
main :: IO ()
main = putStrLn $ deCode "http%3A%2F%2Ffoo%20bar%2F"

View file

@ -0,0 +1,8 @@
// version 1.1.2
import java.net.URLDecoder
fun main(args: Array<String>) {
val encoded = arrayOf("http%3A%2F%2Ffoo%20bar%2F", "google.com/search?q=%60Abdu%27l-Bah%C3%A1")
for (e in encoded) println(URLDecoder.decode(e, "UTF-8"))
}

View file

@ -0,0 +1,11 @@
function decodeChar(hex)
return string.char(tonumber(hex,16))
end
function decodeString(str)
local output, t = string.gsub(str,"%%(%x%x)",decodeChar)
return output
end
-- will print "http://foo bar/"
print(decodeString("http%3A%2F%2Ffoo%20bar%2F"))

View file

@ -0,0 +1,33 @@
--
-- demo\rosetta\decode_url.exw
-- ===========================
--
function decode_url(string s)
integer skip = 0
string res = ""
for i=1 to length(s) do
if skip then
skip -= 1
else
integer ch = s[i]
if ch='%' then
sequence scanres = {}
if i+2<=length(s) then
scanres = scanf("#"&s[i+1..i+2],"%x")
end if
if length(scanres)!=1 then
return "decode error"
end if
skip = 2
ch = scanres[1][1]
elsif ch='+' then
ch = ' '
end if
res &= ch
end if
end for
return res
end function
printf(1,"%s\n",{decode_url("http%3A%2F%2Ffoo%20bar%2F")})
printf(1,"%s\n",{decode_url("google.com/search?q=%60Abdu%27l-Bah%C3%A1")})

View file

@ -1,21 +1,21 @@
/*REXX program converts an URL─encoded string ──► its original unencoded form.*/
/*REXX program converts & displays an URL─encoded string ──► its original unencoded form*/
url.1='http%3A%2F%2Ffoo%20bar%2F'
url.2='mailto%3A%22Ivan%20Aim%22%20%3Civan%2Eaim%40email%2Ecom%3E'
url.3='%6D%61%69%6C%74%6F%3A%22%49%72%6D%61%20%55%73%65%72%22%20%3C%69%72%6D%61%2E%75%73%65%72%40%6D%61%69%6C%2E%63%6F%6D%3E'
URLs=3
do j=1 for URLs; say /*process each URL; display blank line.*/
say url.j /*display the original URL. */
say URLdecode(url.j) /* " " decoded " */
do j=1 for URLs; say /*process each URL; display blank line.*/
say url.j /*display the original URL. */
say URLdecode(url.j) /* " " decoded " */
end /*j*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
URLdecode: procedure; parse arg yyy /*get encoded URL from argument list. */
yyy=translate(yyy,,'+') /*a special case for an encoded blank. */
URL=
do until yyy=''
parse var yyy plain '%' +1 code +2 yyy
URL=URL || plain
if datatype(code,'X') then URL=URL || x2c(code)
else URL=URL'%'code
end /*until*/
return URL
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
URLdecode: procedure; parse arg yyy /*get encoded URL from argument list. */
yyy=translate(yyy, , '+') /*a special case for an encoded blank. */
URL=
do until yyy=''
parse var yyy plain '%' +1 code +2 yyy
URL=URL || plain
if datatype(code, 'X') then URL=URL || x2c(code)
else URL=URL'%'code
end /*until*/
return URL

View file

@ -0,0 +1,3 @@
"http%3A%2F%2Ffoo%20bar%2F".pump(String, // push each char through these fcns:
fcn(c){ if(c=="%") return(Void.Read,2); return(Void.Skip,c) },// %-->read 2 chars else pass through
fcn(_,b,c){ (b+c).toInt(16).toChar() }) // "%" (ignored) "3"+"1"-->0x31-->"1"

View file

@ -0,0 +1,2 @@
var Curl=Import("zklCurl");
Curl.urlDecode("http%3A%2F%2Ffoo%20bar%2F");