September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,26 @@
function urlDecode(data: String): AnsiString;
var
ch: Char;
pos, skip: Integer;
begin
pos := 0;
skip := 0;
Result := '';
for ch in data do begin
if skip = 0 then begin
if (ch = '%') and (pos < data.length -2) then begin
skip := 2;
Result := Result + AnsiChar(Hex2Dec('$' + data[pos+2] + data[pos+3]));
end else begin
Result := Result + ch;
end;
end else begin
skip := skip - 1;
end;
pos := pos +1;
end;
end;

View file

@ -1,2 +1,6 @@
#Python 2.X
import urllib
print urllib.unquote("http%3A%2F%2Ffoo%20bar%2F")
#Python 3.5+
from urllib.parse import unquote
print(unquote('http%3A%2F%2Ffoo%20bar%2F'))

View file

@ -1,32 +1,29 @@
/*REXX program converts an URL─encoded string ──► its original unencoded form.*/
/*REXX program converts a 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
URLs =3
do j=1 for URLs
say url.j
say decodeURL(url.j)
say
end /*j*/
exit
/*────────────────────────────────────────────────────────────────────────────*/
decodeURL: procedure; parse arg encoded; decoded=''
encoded=translate(encoded,,'+') /*special case for encoded blank.*/
do while length(encoded)\==0
parse var encoded head '%' +1 code +2 tail
decoded=decoded || head
/*──────────────────────────────────────────────────────────────────────────────────────*/
decodeURL: procedure; parse arg encoded; decoded= ''
do while encoded\==''
parse var encoded head '%' +1 code +2 tail
decoded= decoded || head
L= length( strip( code, 'T') )
select
when length(strip(code,'T'))==2 &,
datatype(code,'X') then decoded=decoded || x2c(code)
when length(strip(code,'T'))\==0 then do
decoded=decoded'%'
tail=code || tail
when L==2 & datatype(code, "X") then decoded= decoded || x2c(code)
when L\==0 then do; decoded= decoded'%'
tail= code || tail
end
otherwise nop
end /*select*/
encoded=tail
end /*while*/
encoded= tail
end /*while*/
return decoded
return decoded

View file

@ -1,21 +1,22 @@
/*REXX program converts & displays an URL─encoded string ──► its original unencoded form*/
/*REXX program converts & displays a URL─encoded string ──► its original unencoded form.*/
url. =
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.*/
do j=1 until url.j==''; 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. */
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*/
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,36 @@
const INPUT1: &str = "http%3A%2F%2Ffoo%20bar%2F";
const INPUT2: &str = "google.com/search?q=%60Abdu%27l-Bah%C3%A1";
fn append_frag(text: &mut String, frag: &mut String) {
if !frag.is_empty() {
let encoded = frag.chars()
.collect::<Vec<char>>()
.chunks(2)
.map(|ch| {
u8::from_str_radix(&ch.iter().collect::<String>(), 16).unwrap()
}).collect::<Vec<u8>>();
text.push_str(&std::str::from_utf8(&encoded).unwrap());
frag.clear();
}
}
fn decode(text: &str) -> String {
let mut output = String::new();
let mut encoded_ch = String::new();
let mut iter = text.chars();
while let Some(ch) = iter.next() {
if ch == '%' {
encoded_ch.push_str(&format!("{}{}", iter.next().unwrap(), iter.next().unwrap()));
} else {
append_frag(&mut output, &mut encoded_ch);
output.push(ch);
}
}
append_frag(&mut output, &mut encoded_ch);
output
}
fn main() {
println!("{}", decode(INPUT1));
println!("{}", decode(INPUT2));
}

View file

@ -1,14 +1,45 @@
Function UrlDecode(s)
For i = 1 To Len(s)
If Mid(s,i,1) = "%" Then
UrlDecode = UrlDecode & Chr("&H" & Mid(s,i+1,2))
i = i + 2
Else
UrlDecode = UrlDecode & Mid(s,i,1)
End If
Next
Function RegExTest(str,patrn)
Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Pattern = patrn
RegExTest = regEx.Test(str)
End Function
url = "http%3A%2F%2Ffoo%20bar%2F"
Function URLDecode(sStr)
Dim str,code,a0
str=""
code=sStr
code=Replace(code,"+"," ")
While len(code)>0
If InStr(code,"%")>0 Then
str = str & Mid(code,1,InStr(code,"%")-1)
code = Mid(code,InStr(code,"%"))
a0 = UCase(Mid(code,2,1))
If a0="U" And RegExTest(code,"^%u[0-9A-F]{4}") Then
str = str & ChrW((Int("&H" & Mid(code,3,4))))
code = Mid(code,7)
ElseIf a0="E" And RegExTest(code,"^(%[0-9A-F]{2}){3}") Then
str = str & ChrW((Int("&H" & Mid(code,2,2)) And 15) * 4096 + (Int("&H" & Mid(code,5,2)) And 63) * 64 + (Int("&H" & Mid(code,8,2)) And 63))
code = Mid(code,10)
ElseIf a0>="C" And a0<="D" And RegExTest(code,"^(%[0-9A-F]{2}){2}") Then
str = str & ChrW((Int("&H" & Mid(code,2,2)) And 3) * 64 + (Int("&H" & Mid(code,5,2)) And 63))
code = Mid(code,7)
ElseIf (a0<="B" Or a0="F") And RegExTest(code,"^%[0-9A-F]{2}") Then
str = str & Chr(Int("&H" & Mid(code,2,2)))
code = Mid(code,4)
Else
str = str & "%"
code = Mid(code,2)
End If
Else
str = str & code
code = ""
End If
Wend
URLDecode = str
End Function
url = "http%3A%2F%2Ffoo%20bar%C3%A8%2F"
WScript.Echo "Encoded URL: " & url & vbCrLf &_
"Decoded URL: " & UrlDecode(url)