Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1,5 @@
|
|||
This task (the reverse of [[URL encoding]]) is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form.
|
||||
This task (the reverse of [[URL encoding]]) is to provide a function
|
||||
or mechanism to convert an URL-encoded string into its original unencoded form.
|
||||
|
||||
'''Example'''
|
||||
|
||||
|
|
|
|||
3
Task/URL-decoding/Ada/url-decoding-2.ada
Normal file
3
Task/URL-decoding/Ada/url-decoding-2.ada
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.ada
Normal file
28
Task/URL-decoding/Ada/url-decoding-3.ada
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.ada
Normal file
16
Task/URL-decoding/Ada/url-decoding-4.ada
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;
|
||||
15
Task/URL-decoding/Haskell/url-decoding.hs
Normal file
15
Task/URL-decoding/Haskell/url-decoding.hs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import qualified Data.Char as Char
|
||||
|
||||
urlDecode :: String -> Maybe String
|
||||
urlDecode [] = Just []
|
||||
urlDecode ('%':xs) =
|
||||
case xs of
|
||||
(a:b:xss) ->
|
||||
urlDecode xss
|
||||
>>= return . ((Char.chr . read $ "0x" ++ [a,b]) :)
|
||||
_ -> Nothing
|
||||
urlDecode ('+':xs) = urlDecode xs >>= return . (' ' :)
|
||||
urlDecode (x:xs) = urlDecode xs >>= return . (x :)
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn . maybe "Bad decode" id $ urlDecode "http%3A%2F%2Ffoo%20bar%2F"
|
||||
1
Task/URL-decoding/Maple/url-decoding.maple
Normal file
1
Task/URL-decoding/Maple/url-decoding.maple
Normal file
|
|
@ -0,0 +1 @@
|
|||
StringTools:-Decode("http%3A%2F%2Ffoo%20bar%2F", encoding=percent);
|
||||
7
Task/URL-decoding/NewLISP/url-decoding.newlisp
Normal file
7
Task/URL-decoding/NewLISP/url-decoding.newlisp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
;; universal decoder, works for ASCII and UTF-8
|
||||
;; (source http://www.newlisp.org/index.cgi?page=Code_Snippets)
|
||||
(define (url-decode url (opt nil))
|
||||
(if opt (replace "+" url " "))
|
||||
(replace "%([0-9a-f][0-9a-f])" url (pack "b" (int $1 0 16)) 1))
|
||||
|
||||
(url-decode "http%3A%2F%2Ffoo%20bar%2F")
|
||||
1
Task/URL-decoding/R/url-decoding.r
Normal file
1
Task/URL-decoding/R/url-decoding.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
URLdecode("http%3A%2F%2Ffoo%20bar%2F")
|
||||
|
|
@ -1,4 +1,16 @@
|
|||
import java.net._
|
||||
val encoded="http%3A%2F%2Ffoo%20bar%2F"
|
||||
val decoded=URLDecoder.decode(encoded, "UTF-8")
|
||||
println(decoded) // -> http://foo bar/
|
||||
import java.net.{URLDecoder, URLEncoder}
|
||||
import scala.compat.Platform.currentTime
|
||||
|
||||
object UrlCoded extends App {
|
||||
val original = """http://foo bar/"""
|
||||
val encoded: String = URLEncoder.encode(original, "UTF-8")
|
||||
|
||||
assert(encoded == "http%3A%2F%2Ffoo+bar%2F", s"Original: $original not properly encoded: $encoded")
|
||||
|
||||
val percentEncoding = encoded.replace("+", "%20")
|
||||
assert(percentEncoding == "http%3A%2F%2Ffoo%20bar%2F", s"Original: $original not properly percent-encoded: $percentEncoding")
|
||||
|
||||
assert(URLDecoder.decode(encoded, "UTF-8") == URLDecoder.decode(percentEncoding, "UTF-8"))
|
||||
|
||||
println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]")
|
||||
}
|
||||
|
|
|
|||
14
Task/URL-decoding/VBScript/url-decoding.vb
Normal file
14
Task/URL-decoding/VBScript/url-decoding.vb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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
|
||||
End Function
|
||||
|
||||
url = "http%3A%2F%2Ffoo%20bar%2F"
|
||||
WScript.Echo "Encoded URL: " & url & vbCrLf &_
|
||||
"Decoded URL: " & UrlDecode(url)
|
||||
Loading…
Add table
Add a link
Reference in a new issue