Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
7
Task/URL-decoding/Ada/url-decoding-1.adb
Normal file
7
Task/URL-decoding/Ada/url-decoding-1.adb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
with AWS.URL;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
procedure Decode is
|
||||
Encoded : constant String := "http%3A%2F%2Ffoo%20bar%2F";
|
||||
begin
|
||||
Put_Line (AWS.URL.Decode (Encoded));
|
||||
end Decode;
|
||||
3
Task/URL-decoding/Ada/url-decoding-2.adb
Normal file
3
Task/URL-decoding/Ada/url-decoding-2.adb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package URL is
|
||||
function Decode (URL : in String) return String;
|
||||
end URL;
|
||||
28
Task/URL-decoding/Ada/url-decoding-3.adb
Normal file
28
Task/URL-decoding/Ada/url-decoding-3.adb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package body URL is
|
||||
function Decode (URL : in String) return String is
|
||||
Buffer : String (1 .. URL'Length);
|
||||
Filled : Natural := 0;
|
||||
Position : Positive := URL'First;
|
||||
begin
|
||||
while Position in URL'Range loop
|
||||
Filled := Filled + 1;
|
||||
|
||||
case URL (Position) is
|
||||
when '+' =>
|
||||
Buffer (Filled) := ' ';
|
||||
Position := Position + 1;
|
||||
when '%' =>
|
||||
Buffer (Filled) :=
|
||||
Character'Val
|
||||
(Natural'Value
|
||||
("16#" & URL (Position + 1 .. Position + 2) & "#"));
|
||||
Position := Position + 3;
|
||||
when others =>
|
||||
Buffer (Filled) := URL (Position);
|
||||
Position := Position + 1;
|
||||
end case;
|
||||
end loop;
|
||||
|
||||
return Buffer (1 .. Filled);
|
||||
end Decode;
|
||||
end URL;
|
||||
16
Task/URL-decoding/Ada/url-decoding-4.adb
Normal file
16
Task/URL-decoding/Ada/url-decoding-4.adb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
with Ada.Command_Line,
|
||||
Ada.Text_IO;
|
||||
|
||||
with URL;
|
||||
|
||||
procedure Test_URL_Decode is
|
||||
use Ada.Command_Line, Ada.Text_IO;
|
||||
begin
|
||||
if Argument_Count = 0 then
|
||||
Put_Line (URL.Decode ("http%3A%2F%2Ffoo%20bar%2F"));
|
||||
else
|
||||
for I in 1 .. Argument_Count loop
|
||||
Put_Line (URL.Decode (Argument (I)));
|
||||
end loop;
|
||||
end if;
|
||||
end Test_URL_Decode;
|
||||
35
Task/URL-decoding/Batch-File/url-decoding-1.bat
Normal file
35
Task/URL-decoding/Batch-File/url-decoding-1.bat
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
@echo off
|
||||
setlocal enableextensions enabledelayedexpansion
|
||||
set /p str=|| goto:eof
|
||||
(set LF=^
|
||||
|
||||
)
|
||||
for /f "delims==" %%a in ('set h. 2^>nul') do set "%%a="
|
||||
set hexlist=
|
||||
for %%L in ("!LF!") DO set tempstr=!str:%%=%%~L!
|
||||
for /f "skip=1 tokens=* delims=" %%a in ("!tempstr!") do (
|
||||
set "cur=%%a"
|
||||
set hex=!cur:~0,2!
|
||||
if not defined h.!hexlist! (
|
||||
set h.!hexlist!=1
|
||||
set hexlist=!hexlist! !hex!
|
||||
)
|
||||
)
|
||||
set hex=%temp%\hex.txt
|
||||
echo/!hexlist!>"%hex%"
|
||||
certutil -f -decodehex "%hex%" "%hex%" >nul
|
||||
for /f "tokens=2 delims=:." %%G in ('chcp') do set _codepage=%%G
|
||||
chcp 437>nul
|
||||
set/p tempstr=<"%hex%"&& (
|
||||
set cur=0
|
||||
for %%i in (!hexlist!) do (
|
||||
for %%j in ("!cur!") do for %%p in ("%%%%i=!tempstr:~%%~j,1!") do set str=!str:%%~p!
|
||||
set /a cur+=1
|
||||
)
|
||||
) || for %%i in (!hexlist!) do set str=!str:%%%%i=!
|
||||
:print
|
||||
echo/!str!>"%hex%"
|
||||
chcp 65001>nul
|
||||
type "%hex%"
|
||||
del "%hex%"
|
||||
chcp %_codepage%>nul
|
||||
9
Task/URL-decoding/Batch-File/url-decoding-2.bat
Normal file
9
Task/URL-decoding/Batch-File/url-decoding-2.bat
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
...
|
||||
certutil -f -decodehex "%hex%" "%hex%" >nul
|
||||
del "%hex%"
|
||||
for %%i in (!hexlist!) do (
|
||||
set /a dec=0x%%i
|
||||
cmd/cexit !dec!
|
||||
for %%p in ("%%%%i=!=exitcodeascii!") do set str=!str:%%~p!
|
||||
)
|
||||
echo !str!
|
||||
|
|
@ -3,38 +3,38 @@
|
|||
|
||||
inline int ishex(int x)
|
||||
{
|
||||
return (x >= '0' && x <= '9') ||
|
||||
(x >= 'a' && x <= 'f') ||
|
||||
(x >= 'A' && x <= 'F');
|
||||
return (x >= '0' && x <= '9') ||
|
||||
(x >= 'a' && x <= 'f') ||
|
||||
(x >= 'A' && x <= 'F');
|
||||
}
|
||||
|
||||
int decode(const char *s, char *dec)
|
||||
{
|
||||
char *o;
|
||||
const char *end = s + strlen(s);
|
||||
int c;
|
||||
char *o;
|
||||
const char *end = s + strlen(s);
|
||||
int c;
|
||||
|
||||
for (o = dec; s <= end; o++) {
|
||||
c = *s++;
|
||||
if (c == '+') c = ' ';
|
||||
else if (c == '%' && ( !ishex(*s++) ||
|
||||
!ishex(*s++) ||
|
||||
!sscanf(s - 2, "%2x", &c)))
|
||||
return -1;
|
||||
for (o = dec; s <= end; o++) {
|
||||
c = *s++;
|
||||
if (c == '+') c = ' ';
|
||||
else if (c == '%' && ( !ishex(*s++) ||
|
||||
!ishex(*s++) ||
|
||||
!sscanf(s - 2, "%2x", &c)))
|
||||
return -1;
|
||||
|
||||
if (dec) *o = c;
|
||||
}
|
||||
if (dec) *o = c;
|
||||
}
|
||||
|
||||
return o - dec;
|
||||
return o - dec;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *url = "http%3A%2F%2ffoo+bar%2fabcd";
|
||||
char out[strlen(url) + 1];
|
||||
const char *url = "http%3A%2F%2ffoo+bar%2fabcd";
|
||||
char out[strlen(url) + 1];
|
||||
|
||||
printf("length: %d\n", decode(url, 0));
|
||||
puts(decode(url, out) < 0 ? "bad string" : out);
|
||||
printf("length: %d\n", decode(url, 0));
|
||||
puts(decode(url, out) < 0 ? "bad string" : out);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
57
Task/URL-decoding/EasyLang/url-decoding.easy
Normal file
57
Task/URL-decoding/EasyLang/url-decoding.easy
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
func fromhex s$ .
|
||||
n = number ("0x" & s$)
|
||||
if error = 1 : return -1
|
||||
return n
|
||||
.
|
||||
func$ utf8dec b[] .
|
||||
ind = 1
|
||||
while ind <= len b[]
|
||||
n = b[ind]
|
||||
if n < 0x80
|
||||
cnt = 0
|
||||
elif n >= 0xf0
|
||||
cnt = 3
|
||||
n = bitand n 0x7
|
||||
elif n >= 0xe0
|
||||
cnt = 2
|
||||
n = bitand n 0xf
|
||||
elif n >= 0xc0
|
||||
cnt = 1
|
||||
n = bitand n 0x1f
|
||||
else
|
||||
return ""
|
||||
.
|
||||
for i = 1 to cnt
|
||||
h = b[ind + i]
|
||||
if bitand h 0xc0 <> 0x80 : return ""
|
||||
h = bitand h 0x3f
|
||||
n = n * 64 + h
|
||||
.
|
||||
ind += cnt + 1
|
||||
res$ &= strchar n
|
||||
.
|
||||
return res$
|
||||
.
|
||||
func$ url2decode s$ .
|
||||
c$[] = strchars s$
|
||||
lng = len c$[]
|
||||
ind = 1
|
||||
while ind < lng
|
||||
if c$[ind] = "%"
|
||||
b[] = [ ]
|
||||
while ind <= lng and c$[ind] = "%"
|
||||
if ind + 2 > lng : return ""
|
||||
n = fromhex (c$[ind + 1] & c$[ind + 2])
|
||||
if n = -1 : return ""
|
||||
b[] &= n
|
||||
ind += 3
|
||||
.
|
||||
res$ &= utf8dec b[]
|
||||
else
|
||||
res$ &= c$[ind]
|
||||
ind += 1
|
||||
.
|
||||
.
|
||||
return res$
|
||||
.
|
||||
print url2decode "https%3A%2F%2Fbn%2Ewikipedia%2Eorg%2Fwiki%2F%E0%A6%B0%E0%A7%8B%E0%A6%B8%E0%A7%87%E0%A6%9F%E0%A6%BE%5F%E0%A6%95%E0%A7%8B%E0%A6%A1"
|
||||
|
|
@ -1,21 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for _, escaped := range []string{
|
||||
"http%3A%2F%2Ffoo%20bar%2F",
|
||||
"google.com/search?q=%60Abdu%27l-Bah%C3%A1",
|
||||
} {
|
||||
u, err := url.QueryUnescape(escaped)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
fmt.Println(u)
|
||||
}
|
||||
for _, escaped := range []string{
|
||||
"http%3A%2F%2Ffoo%20bar%2F",
|
||||
"google.com/search?q=%60Abdu%27l-Bah%C3%A1",
|
||||
} {
|
||||
u, err := url.QueryUnescape(escaped)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
fmt.Println(u)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
val finish = fn s:b2s(map(
|
||||
less(split(s, delim="%"), of=1),
|
||||
by=fn x:number(x, fmt=16),
|
||||
))
|
||||
val decode = fn s:replace(
|
||||
s,
|
||||
by=re/(%[0-9A-Fa-f]{2})+/,
|
||||
with=finish,
|
||||
)
|
||||
val finish = fn(s) {
|
||||
b2s(map(
|
||||
less(split(s, delim="%"), of=1),
|
||||
by=fn(x) { number x, fmt=16 },
|
||||
))
|
||||
}
|
||||
val decode = fn(s) {
|
||||
replace(
|
||||
s,
|
||||
by=re/(%[0-9A-Fa-f]{2})+/,
|
||||
with=finish,
|
||||
)
|
||||
}
|
||||
|
||||
writeln decode("http%3A%2F%2Fno%20more%20foo%20bars%20please%2F")
|
||||
writeln decode("google.com/search?q=%22unbroken%20string%22")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
function decodeChar(hex)
|
||||
return string.char(tonumber(hex,16))
|
||||
return string.char(tonumber(hex,16))
|
||||
end
|
||||
|
||||
function decodeString(str)
|
||||
local output, t = string.gsub(str,"%%(%x%x)",decodeChar)
|
||||
return output
|
||||
local output, t = string.gsub(str,"%%(%x%x)",decodeChar)
|
||||
return output
|
||||
end
|
||||
|
||||
-- will print "http://foo bar/"
|
||||
|
|
|
|||
1
Task/URL-decoding/PowerShell/url-decoding.ps1
Normal file
1
Task/URL-decoding/PowerShell/url-decoding.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
[System.Web.HttpUtility]::UrlDecode("http%3A%2F%2Ffoo%20bar%2F")
|
||||
22
Task/URL-decoding/Rebol/url-decoding.rebol
Normal file
22
Task/URL-decoding/Rebol/url-decoding.rebol
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: URL decoding"
|
||||
file: %URL_decoding.r3
|
||||
url: https://rosettacode.org/wiki/URL_decoding
|
||||
]
|
||||
|
||||
foreach [src expected] [
|
||||
"http%3A%2F%2Ffoo%20bar%2F"
|
||||
"http://foo bar/"
|
||||
|
||||
"google.com/search?q=%60Abdu%27l-Bah%C3%A1"
|
||||
"google.com/search?q=`Abdu'l-Bahá"
|
||||
|
||||
"%25%32%35"
|
||||
"%25"
|
||||
][
|
||||
|
||||
probe src
|
||||
probe url: dehex src
|
||||
print either expected = url ["OK"]["FAILED!"]
|
||||
print ""
|
||||
]
|
||||
|
|
@ -16,49 +16,49 @@ function urldecode
|
|||
fi
|
||||
fi
|
||||
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
|
||||
while [[ -n ${c} ]]; do
|
||||
if [[ ${c} = '%' ]]; then
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c1="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
while [[ -n ${c} ]]; do
|
||||
if [[ ${c} = '%' ]]; then
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c1="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c2="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c2="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
|
||||
if [[ -z ${c1} || -z ${c2} ]]; then
|
||||
c="%${c1}${c2}"
|
||||
echo "WARNING: invalid % encoding: ${c}" >&2
|
||||
elif [[ -n ${BASH_VERSION:-} ]]; then
|
||||
c="\\x${c1}${c2}"
|
||||
c=$(\echo -e "${c}")
|
||||
else
|
||||
hex="16#${c1}${c2}"; oct=hex
|
||||
c="\\0${oct#8\#}"
|
||||
c=$(print -- "${c}")
|
||||
fi
|
||||
elif [[ ${c} = '+' ]]; then
|
||||
c=' '
|
||||
fi
|
||||
if [[ -z ${c1} || -z ${c2} ]]; then
|
||||
c="%${c1}${c2}"
|
||||
echo "WARNING: invalid % encoding: ${c}" >&2
|
||||
elif [[ -n ${BASH_VERSION:-} ]]; then
|
||||
c="\\x${c1}${c2}"
|
||||
c=$(\echo -e "${c}")
|
||||
else
|
||||
hex="16#${c1}${c2}"; oct=hex
|
||||
c="\\0${oct#8\#}"
|
||||
c=$(print -- "${c}")
|
||||
fi
|
||||
elif [[ ${c} = '+' ]]; then
|
||||
c=' '
|
||||
fi
|
||||
|
||||
decoded="${decoded}${c}"
|
||||
decoded="${decoded}${c}"
|
||||
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
done
|
||||
rest="${encoded#?}"
|
||||
eval ${bug}
|
||||
c="${encoded%%${rest2}}"
|
||||
encoded="${rest}"
|
||||
done
|
||||
|
||||
if [[ -n ${BASH_VERSION:-} ]]; then
|
||||
\echo -E "${decoded}"
|
||||
else
|
||||
print -r -- "${decoded}"
|
||||
fi
|
||||
if [[ -n ${BASH_VERSION:-} ]]; then
|
||||
\echo -E "${decoded}"
|
||||
else
|
||||
print -r -- "${decoded}"
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import net.urllib
|
||||
fn main() {
|
||||
for escaped in [
|
||||
"http%3A%2F%2Ffoo%20bar%2F",
|
||||
"google.com/search?q=%60Abdu%27l-Bah%C3%A1",
|
||||
for escaped in [
|
||||
"http%3A%2F%2Ffoo%20bar%2F",
|
||||
"google.com/search?q=%60Abdu%27l-Bah%C3%A1",
|
||||
] {
|
||||
u := urllib.query_unescape(escaped)!
|
||||
println(u)
|
||||
}
|
||||
u := urllib.query_unescape(escaped)!
|
||||
println(u)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
45
Task/URL-decoding/VBScript/url-decoding.vbs
Normal file
45
Task/URL-decoding/VBScript/url-decoding.vbs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
Function RegExTest(str,patrn)
|
||||
Dim regEx
|
||||
Set regEx = New RegExp
|
||||
regEx.IgnoreCase = True
|
||||
regEx.Pattern = patrn
|
||||
RegExTest = regEx.Test(str)
|
||||
End Function
|
||||
|
||||
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)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
sub decode_url$(s$)
|
||||
local res$, ch$
|
||||
|
||||
|
||||
while(s$ <> "")
|
||||
ch$ = left$(s$, 1)
|
||||
if ch$ = "%" then
|
||||
|
|
@ -9,7 +9,7 @@ sub decode_url$(s$)
|
|||
else
|
||||
if ch$ = "+" ch$ = " "
|
||||
s$ = right$(s$, len(s$) - 1)
|
||||
endif
|
||||
endif
|
||||
res$ = res$ + ch$
|
||||
wend
|
||||
return res$
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue