Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -1,23 +1,23 @@
BEGIN {
for (i = 0; i <= 255; i++)
ord[sprintf("%c", i)] = i
for (i = 0; i <= 255; i++)
ord[sprintf("%c", i)] = i
}
# Encode string with application/x-www-form-urlencoded escapes.
function escape(str, c, len, res) {
len = length(str)
res = ""
for (i = 1; i <= len; i++) {
c = substr(str, i, 1);
if (c ~ /[0-9A-Za-z]/)
#if (c ~ /[-._*0-9A-Za-z]/)
res = res c
#else if (c == " ")
# res = res "+"
else
res = res "%" sprintf("%02X", ord[c])
}
return res
len = length(str)
res = ""
for (i = 1; i <= len; i++) {
c = substr(str, i, 1);
if (c ~ /[0-9A-Za-z]/)
#if (c ~ /[-._*0-9A-Za-z]/)
res = res c
#else if (c == " ")
# res = res "+"
else
res = res "%" sprintf("%02X", ord[c])
}
return res
}
# Escape every line of input.

View file

@ -0,0 +1,7 @@
with AWS.URL;
with Ada.Text_IO; use Ada.Text_IO;
procedure Encode is
Normal : constant String := "http://foo bar/";
begin
Put_Line (AWS.URL.Encode (Normal));
end Encode;

View file

@ -3,15 +3,15 @@ MsgBox, % UriEncode("http://foo bar/")
; Modified from http://goo.gl/0a0iJq
UriEncode(Uri, Reserved:="!#$&'()*+,/:;=?@[]") {
Unreserved := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
StrPut(Uri, &Var, "UTF-8")
While (Code := NumGet(Var, A_Index - 1, "UChar")) {
If InStr(Unreserved . Reserved, Chr(Code)) {
Encoded .= Chr(Code)
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
StrPut(Uri, &Var, "UTF-8")
While (Code := NumGet(Var, A_Index - 1, "UChar")) {
If InStr(Unreserved . Reserved, Chr(Code)) {
Encoded .= Chr(Code)
}
Else {
Encoded .= Format("%{:02X}", Code)
Else {
Encoded .= Format("%{:02X}", Code)
}
}
Return Encoded
Return Encoded
}

View file

@ -0,0 +1,24 @@
@echo off
setlocal enableextensions enabledelayedexpansion
for /f "tokens=2 delims=:." %%G in ('chcp') do set _codepage=%%G
chcp 65001 >nul
set /p str=||goto:eof
set tempFile="%temp%\hex-urlencoding.txt"
set "letters=ABCDEFGHIKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz-._~"
<nul set /p=%letters%>%tempFile%
certutil -encodehex -f %tempFile% %tempFile% 4 >nul
set pos=0
for /f "delims==" %%A in ('set char. 2^>nul') do set "%%A="
for /f "usebackq tokens=*" %%# in (%tempFile%) do for %%h in (%%#) do (
for %%i in (^!pos^!) do set char.%%h=!letters:~%%i,1!
set /a pos+=1
)
<nul set /p"=!str!">%tempFile%
certutil -encodehex -f %tempFile% %tempFile% 4 >nul
set str=
for /f "usebackq tokens=*" %%# in (%tempFile%) do for %%h in (%%#) do (
if defined char.%%h (set "str=!str!!char.%%h!") else (set "str=!str!%%%%h")
)
del %tempFile%
echo(!str!
chcp %_codepage% >nul

View file

@ -7,28 +7,28 @@ char html5[256] = {0};
/* caller responsible for memory */
void encode(const char *s, char *enc, char *tb)
{
for (; *s; s++) {
if (tb[*s]) sprintf(enc, "%c", tb[*s]);
else sprintf(enc, "%%%02X", *s);
while (*++enc);
}
for (; *s; s++) {
if (tb[*s]) sprintf(enc, "%c", tb[*s]);
else sprintf(enc, "%%%02X", *s);
while (*++enc);
}
}
int main()
{
const char url[] = "http://foo bar/";
char enc[(strlen(url) * 3) + 1];
const char url[] = "http://foo bar/";
char enc[(strlen(url) * 3) + 1];
int i;
for (i = 0; i < 256; i++) {
rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
? i : 0;
html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
? i : (i == ' ') ? '+' : 0;
}
int i;
for (i = 0; i < 256; i++) {
rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
? i : 0;
html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
? i : (i == ' ') ? '+' : 0;
}
encode(url, enc, rfc3986);
puts(enc);
encode(url, enc, rfc3986);
puts(enc);
return 0;
return 0;
}

View file

@ -1,9 +1,9 @@
val urlEncode = fn(s) {
replace(
s,
by=re/[^A-Za-z0-9]/,
with=fn r:join(map(s2b(r), by=fn b:"%{{b:X02}}")),
)
replace(
s,
by=re/[^A-Za-z0-9]/,
with=fn(r) { join map(s2b(r), by=fn(b) { "%{{b:X02}}" }) },
)
}
writeln urlEncode("https://some website.com/")

View file

@ -1,10 +1,10 @@
function encodeChar(chr)
return string.format("%%%X",string.byte(chr))
return string.format("%%%X",string.byte(chr))
end
function encodeString(str)
local output, t = string.gsub(str,"[^%w]",encodeChar)
return output
local output, t = string.gsub(str,"[^%w]",encodeChar)
return output
end
-- will print "http%3A%2F%2Ffoo%20bar%2F"

View file

@ -1,10 +1,10 @@
function u = urlencoding(s)
u = '';
for k = 1:length(s),
if isalnum(s(k))
u(end+1) = s(k);
else
u=[u,'%',dec2hex(s(k)+0)];
end;
end
u = '';
for k = 1:length(s),
if isalnum(s(k))
u(end+1) = s(k);
else
u=[u,'%',dec2hex(s(k)+0)];
end;
end
end

View file

@ -0,0 +1,3 @@
[uri]::EscapeDataString('http://foo bar/')
http%3A%2F%2Ffoo%20bar%2F

View file

@ -0,0 +1,23 @@
Rebol [
title: "Rosetta code: URL encoding"
file: %URL_encoding.r3
url: https://rosettacode.org/wiki/URL_encoding
]
task-except: charset [#"0"-#"9" #"A"-#"Z" #"a"-#"z"]
RFC-3986: charset [#"0"-#"9" #"A"-#"Z" #"a"-#"z" "-._~"]
js-except: charset [#"0"-#"9" #"A"-#"Z" #"a"-#"z" "-._~;,/?:@&=+$!*'()#"]
foreach src [
"http://foo bar/"
"https://rosettacode.org/wiki/URL_encoding"
"https://en.wikipedia.org/wiki/Pikes Peak granite"
][
probe src
print ["enhex: " enhex src]
print ["enhex/uri: " enhex/uri src]
print ["RFC-3986: " enhex/except src RFC-3986]
print ["Custom: " enhex/except src task-except]
print ["JavaScript:" enhex/except src js-except]
print ""
]

View file

@ -2,7 +2,7 @@
# See http://tools.ietf.org/html/rfc3986 §2.4 and §2.5
proc urlEncode {str} {
set uStr [encoding convertto utf-8 $str]
set chRE {[^-A-Za-z0-9._~\n]}; # Newline is special case!
set chRE {[^-A-Za-z0-9._~\n]}; # Newline is special case!
set replacement {%[format "%02X" [scan "\\\0" "%c"]]}
return [string map {"\n" "%0A"} [subst [regsub -all $chRE $uStr $replacement]]]
}

View file

@ -1,47 +1,47 @@
function urlencode
{
typeset decoded=$1 encoded= rest= c=
typeset rest2= bug='rest2=${rest}'
typeset decoded=$1 encoded= rest= c=
typeset rest2= bug='rest2=${rest}'
if [[ -z ${BASH_VERSION} ]]; then
# bug /usr/bin/sh HP-UX 11.00
typeset _decoded='xyz%26xyz'
rest="${_decoded#?}"
c="${_decoded%%${rest}}"
if (( ${#c} != 1 )); then
typeset qm='????????????????????????????????????????????????????????????????????????'
typeset bug='(( ${#rest} > 0 )) && typeset -L${#rest} rest2="${qm}" || rest2=${rest}'
fi
fi
if [[ -z ${BASH_VERSION} ]]; then
# bug /usr/bin/sh HP-UX 11.00
typeset _decoded='xyz%26xyz'
rest="${_decoded#?}"
c="${_decoded%%${rest}}"
if (( ${#c} != 1 )); then
typeset qm='????????????????????????????????????????????????????????????????????????'
typeset bug='(( ${#rest} > 0 )) && typeset -L${#rest} rest2="${qm}" || rest2=${rest}'
fi
fi
rest="${decoded#?}"
eval ${bug}
c="${decoded%%${rest2}}"
decoded="${rest}"
rest="${decoded#?}"
eval ${bug}
c="${decoded%%${rest2}}"
decoded="${rest}"
while [[ -n ${c} ]]; do
case ${c} in
[-a-zA-z0-9.])
;;
' ')
c='+'
;;
*)
c=$(printf "%%%02X" "'$c")
;;
esac
while [[ -n ${c} ]]; do
case ${c} in
[-a-zA-z0-9.])
;;
' ')
c='+'
;;
*)
c=$(printf "%%%02X" "'$c")
;;
esac
encoded="${encoded}${c}"
encoded="${encoded}${c}"
rest="${decoded#?}"
eval ${bug}
c="${decoded%%${rest2}}"
decoded="${rest}"
done
rest="${decoded#?}"
eval ${bug}
c="${decoded%%${rest2}}"
decoded="${rest}"
done
if [[ -n ${BASH_VERSION:-} ]]; then
\echo -E "${encoded}"
else
print -r -- "${encoded}"
fi
if [[ -n ${BASH_VERSION:-} ]]; then
\echo -E "${encoded}"
else
print -r -- "${encoded}"
fi
}

View file

@ -1,4 +1,4 @@
import net.urllib
fn main() {
println(urllib.query_escape("http://foo bar/"))
println(urllib.query_escape("http://foo bar/"))
}

View file

@ -0,0 +1,16 @@
Function UrlEncode(url)
For i = 1 To Len(url)
n = Asc(Mid(url,i,1))
If (n >= 48 And n <= 57) Or (n >= 65 And n <= 90) _
Or (n >= 97 And n <= 122) Then
UrlEncode = UrlEncode & Mid(url,i,1)
Else
ChrHex = Hex(Asc(Mid(url,i,1)))
For j = 0 to (Len(ChrHex) / 2) - 1
UrlEncode = UrlEncode & "%" & Mid(ChrHex,(2*j) + 1,2)
Next
End If
Next
End Function
WScript.Echo UrlEncode("http://foo baré/")

View file

@ -1,6 +1,6 @@
sub encode_url$(s$, exclusions$, spaceplus)
local res$, i, ch$
for i=1 to len(s$)
ch$ = mid$(s$, i, 1)
if ch$ = " " and spaceplus then