URL decoding: Difference between revisions
→{{header|langur}}
No edit summary |
Langurmonkey (talk | contribs) |
||
(20 intermediate revisions by 9 users not shown) | |||
Line 10:
* The encoded string "<code><nowiki>google.com/search?q=%60Abdu%27l-Bah%C3%A1</nowiki></code>" should revert to the unencoded form "<code><nowiki>google.com/search?q=`Abdu'l-Bahá</nowiki></code>".
* The encoded string "<code><nowiki>%25%32%35</nowiki></code>" should revert to the unencoded form "<code><nowiki>%25</nowiki></code>" and '''not''' "<code><nowiki>%</nowiki></code>".
<br><br>
=={{header|11l}}==
<
V r = ‘’
V i = 0
Line 30 ⟶ 32:
print(url_decode(‘http%3A%2F%2Ffoo%20bar%2F’))
print(url_decode(‘https://ru.wikipedia.org/wiki/%D0%A2%D1%80%D0%B0%D0%BD%D1%81%D0%BF%D0%B0%D0%B9%D0%BB%D0%B5%D1%80’))</
{{out}}
Line 40 ⟶ 42:
=={{header|ABAP}}==
<
DATA: lv_encoded_url TYPE string VALUE 'http%3A%2F%2Ffoo%20bar%2F',
Line 51 ⟶ 53:
UNESCAPED = lv_decoded_url.
WRITE: 'Encoded URL: ', lv_encoded_url, /, 'Decoded URL: ', lv_decoded_url.</
=={{header|Action!}}==
<
s(0)==+1
s(s(0))=c
Line 118 ⟶ 120:
Test("http%3A%2F%2Ffoo%20bar%2F")
Test("http%3A%2F%2Ffoo+bar%2F*_-.html")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/URL_decoding.png Screenshot from Atari 8-bit computer]
Line 131 ⟶ 133:
=={{header|Ada}}==
{{libheader|AWS}}
<
with Ada.Text_IO; use Ada.Text_IO;
procedure Decode is
Line 138 ⟶ 140:
Put_Line (AWS.URL.Decode (Encoded));
end Decode;
</syntaxhighlight>
Without external libraries:
<
function Decode (URL : in String) return String;
end URL;</
<
function Decode (URL : in String) return String is
Buffer : String (1 .. URL'Length);
Line 173 ⟶ 175:
return Buffer (1 .. Filled);
end Decode;
end URL;</
<
Ada.Text_IO;
Line 190 ⟶ 192:
end loop;
end if;
end Test_URL_Decode;</
=={{header|ALGOL 68}}==
Line 197 ⟶ 199:
<br>
For the second task example, this outputs the encoded UTF-8 characters, what you see depends on what you look at it with...
<
PROC hex value = ( CHAR c )INT: IF c >= "0" AND c <= "9" THEN ABS c - ABS "0"
ELIF c >= "A" AND c <= "F" THEN 10 + ( ABS c - ABS "A" )
Line 232 ⟶ 234:
# test the url decode procedure #
print( ( url decode( "http%3A%2F%2Ffoo%20bar%2F" ), newline ) );
print( ( url decode( "google.com/search?q=%60Abdu%27l-Bah%C3%A1" ), newline ) )</
{{out}}
<pre>
Line 240 ⟶ 242:
=={{header|Apex}}==
<
EncodingUtil.urlDecode('google.com/search?q=%60Abdu%27l-Bah%C3%A1', 'UTF-8');</
<pre>http://foo bar/
google.com/search?q=`Abdu'l-Bahá</pre>
Line 247 ⟶ 249:
=={{header|AppleScript}}==
{{libheader|AppleScript Toolbox}}
<
=={{header|Arturo}}==
<
print decode.url "google.com/search?q=%60Abdu%27l-Bah%C3%A1"</
{{out}}
Line 260 ⟶ 262:
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">
UriDecode(Uri) {
LoopOffset := 0
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
{
If (A_Index < LoopOffset) {
If (A_LoopField = Chr(37)) {
Number := "0x" . SubStr(Uri, A_Index + 1, 2)
LoopOffset := A_Index + 3
}
Else {
Number := Ord(A_LoopField)
}
NumPut(Number, Var, VarLength++, "UChar")
}
Return StrGet(&Var, VarLength, "UTF-8")
}
MsgBox % UriDecode("http%3A%2F%2Ffoo%20bar%2F")
MsgBox % UriDecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")
MsgBox % UriDecode("%25%32%35")
</syntaxhighlight>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax:
awk '
Line 299 ⟶ 312:
return num + (length(s) ? 16*hex2dec(s) : 0)
} '
</syntaxhighlight>
{{out}}
<pre>
Line 308 ⟶ 321:
OR:
<
LC_ALL=C
echo "http%3A%2F%2Ffoo%20bar%2F" | gawk -vRS='%[[:xdigit:]]{2}' '
RT {RT = sprintf("%c",strtonum("0x" substr(RT, 2)))}
{gsub(/+/," ");printf "%s", $0 RT}'
</syntaxhighlight>
{{out}}
Line 321 ⟶ 334:
=={{header|BaCon}}==
<
LOCAL result$
Line 334 ⟶ 347:
PRINT Url_Decode$("http%3A%2F%2Ffoo%20bar%2F")
PRINT Url_Decode$("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</
{{out}}
<pre>
Line 340 ⟶ 353:
google.com/search?q=`Abdu'l-Bahá
</pre>
=={{header|Bash}}==
See [[#UNIX Shell]]
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
END
Line 364 ⟶ 380:
IF C% >= 97 IF C% <= 122 MID$(A$,A%,1) = CHR$(C%-32)
NEXT
= A$</
{{out}}
<pre>
Line 371 ⟶ 387:
=={{header|Bracmat}}==
<
= decoded hexcode notencoded
. :?decoded
Line 381 ⟶ 397:
)
& out$(decode$http%3A%2F%2Ffoo%20bar%2F)
);</
{{out}}
<pre>http://foo bar/</pre>
=={{header|C}}==
<
#include <string.h>
Line 425 ⟶ 441:
return 0;
}</
=={{header|C sharp}}==
<
namespace URLEncode
Line 445 ⟶ 461:
}
}
}</
{{out}}
Line 455 ⟶ 471:
{{libheader|Poco}}
{{works with|g++}}
<
#include "Poco/URI.h"
#include <iostream>
Line 465 ⟶ 481:
std::cout << encoded << " is decoded: " << decoded << " !" << std::endl ;
return 0 ;
}</
{{out}}
<pre>http%3A%2F%2Ffoo%20bar%2F is decoded: http://foo bar/ !</pre>
Line 476 ⟶ 492:
=={{header|Clojure}}==
<
=={{header|CoffeeScript}}==
<
console.log decodeURIComponent "http%3A%2F%2Ffoo%20bar%2F?name=Foo%20Barson"
</syntaxhighlight>
<syntaxhighlight lang="text">
> coffee foo.coffee
http://foo bar/?name=Foo Barson
</syntaxhighlight>
=={{header|Common Lisp}}==
<
(assert (char= (char string start) #\%))
(if (>= (length string) (+ start 3))
Line 512 ⟶ 528:
finally (return (apply #'concatenate 'string chunks))))
(url-decode "http%3A%2F%2Ffoo%20bar%2F")</
{{out}}
<pre>"http://foo bar/"</pre>
=={{header|Crystal}}==
<
puts URI.decode "http%3A%2F%2Ffoo%20bar%2F"
puts URI.decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"</
{{out}}
<pre>http://foo bar/
Line 526 ⟶ 542:
=={{header|D}}==
<
void main() {
writeln(decodeComponent("http%3A%2F%2Ffoo%20bar%2F"));
}</
<pre>http://foo bar/</pre>
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 542 ⟶ 558:
begin
Writeln(TIdURI.URLDecode('http%3A%2F%2Ffoo%20bar%2F'));
end.</
=={{header|Elixir}}==
<
IO.inspect URI.decode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</
{{out}}
Line 563 ⟶ 579:
=={{header|F_Sharp|F#}}==
{{trans|C#}}
<
let decode uri = Uri.UnescapeDataString(uri)
Line 570 ⟶ 586:
let main argv =
printfn "%s" (decode "http%3A%2F%2Ffoo%20bar%2F")
0</
=={{header|Factor}}==
<
IN: rosetta-code.url-decoding
"http%3A%2F%2Ffoo%20bar%2F"
"google.com/search?q=%60Abdu%27l-Bah%C3%A1"
[ url-decode print ] bi@</
{{out}}
<pre>
Line 587 ⟶ 603:
=={{header|Free Pascal}}==
<
var
ch: Char;
Line 612 ⟶ 628:
pos := pos +1;
end;
end;</
Line 618 ⟶ 634:
{{trans|Liberty BASIC}}
{{trans|Pascal}}
<
Const alphanum = "0123456789abcdefghijklmnopqrstuvwxyz"
Line 658 ⟶ 674:
Print "URL decoding '"; url2string(URL); "'"
Sleep
</syntaxhighlight>
=={{header|Frink}}==
While the default is to decode parameters as UTF-8 (which is the W3C recommendation,) the characters may have been encoded in another encoding scheme, and this can be handled correctly.
<
=={{header|Go}}==
<
import (
Line 685 ⟶ 701:
fmt.Println(u)
}
}</
{{out}}
<pre>
Line 693 ⟶ 709:
=={{header|Groovy}}==
<
=={{header|Haskell}}==
<
urlDecode :: String -> Maybe String
Line 710 ⟶ 726:
main :: IO ()
main = putStrLn . maybe "Bad decode" id $ urlDecode "http%3A%2F%2Ffoo%20bar%2F"</
{{out}}
<pre>http://foo bar/</pre>
Another approach:
<
import Data.List.Split (splitOn)
Line 727 ⟶ 743:
-- TEST ------------------------------------------------------------------------
main :: IO ()
main = putStrLn $ deCode "http%3A%2F%2Ffoo%20bar%2F"</
{{Out}}
<pre>http://foo bar/</pre>
=={{header|Icon}} and {{header|Unicon}}==
<
procedure main()
Line 753 ⟶ 769:
else move(1)
return c
end</
{{libheader|Icon Programming Library}}
Line 767 ⟶ 783:
Here is an implementation:
<
urldecode=: rplc&(~.,/;"_1&a."2(,:tolower)'%',.toupper hfd i.#a.)</
Example use:
<
http://foo bar/</
Note that an earlier implementation assumed the j6 implementation of <code>hfd</code> which where hexadecimal letters resulting from <code>hfd</code> were upper case. J8, in contrast, provides a lower case result from hfd. The addition of <code>toupper</code> guarantees the case insensitivity required by [http://tools.ietf.org/html/rfc3986#section-2.1 RFC 3986] regardless of which version of J you are using. As the parenthesized expression containing <code>hfd</code> is only evaluated at definition time, there's no performance penalty from the use of <code>toupper</code>.
Line 779 ⟶ 795:
Example use:
<
google.com/search?q=`Abdu'l-Bahá</
=={{header|Java}}==
Java offers the ''URLDecoder'' and ''URLEncoder'' classes for this specific task.
<syntaxhighlight lang="java">
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
</syntaxhighlight>
<syntaxhighlight lang="java">
URLDecoder.decode("http%3A%2F%2Ffoo%20bar%2F", StandardCharsets.UTF_8)
</syntaxhighlight>
Alternately, you could use a regular expression capture
<syntaxhighlight lang="java">
import java.util.regex.Matcher;
import java.util.regex.Pattern;
</syntaxhighlight>
<syntaxhighlight lang="java">
String decode(String string) {
Pattern pattern = Pattern.compile("%([A-Za-z\\d]{2})");
Matcher matcher = pattern.matcher(string);
StringBuilder decoded = new StringBuilder(string);
char character;
int start, end, offset = 0;
while (matcher.find()) {
character = (char) Integer.parseInt(matcher.group(1), 16);
/* offset the matched index since were adjusting the string */
start = matcher.start() - offset;
end = matcher.end() - offset;
decoded.replace(start, end, String.valueOf(character));
offset += 2;
}
return decoded.toString();
}
</syntaxhighlight>
<pre>
http://foo bar/
google.com/search?q=`Abdu'l-Bahá
</pre>
=={{header|JavaScript}}==
<
=={{header|jq}}==
{{works with|jq|1.4}}
If your jq already has "until", then the definition given below may be omitted.
<
def until(condition; next):
def u: if condition then . else (next|u) end;
Line 832 ⟶ 867:
else [ $i + 1, .[1] + $in[$i:$i+1] ]
end)
| .[1]; # answer</
'''Example''':
<
{{out}}
<syntaxhighlight lang="sh">
"http://foo bar/"</
=={{header|Julia}}==
<syntaxhighlight lang="julia">
using URIParser
Line 848 ⟶ 883:
println(enc, " => ", dcd)
</syntaxhighlight>
{{out}}
Line 856 ⟶ 891:
=={{header|Kotlin}}==
<
import java.net.URLDecoder
Line 863 ⟶ 898:
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"))
}</
{{out}}
Line 872 ⟶ 907:
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
url_decode()
{
Line 881 ⟶ 916:
url_decode "http%3A%2F%2Ffoo%20bar%2F"
url_decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
</syntaxhighlight>
{{out}}
Line 891 ⟶ 926:
=={{header|Lambdatalk}}==
Currently lambdatalk has no builtin primitive for decoding URLs. Let's define it using Javascript.
<
1) define a new javascript primitive:
{script
Line 905 ⟶ 940:
</syntaxhighlight>
=={{header|langur}}==
<syntaxhighlight lang="langur">val .finish = fn(.s) { b2s map fn(.x) { number(.x, 16) }, rest split "%", .s }
val .decode = fn(.s) { replace .s, re/(%[0-9A-Fa-f]{2})+/, .finish }
writeln .decode("http%3A%2F%2Ffoo%20bar%2F")
writeln .decode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")
</syntaxhighlight>
{{out}}
<pre>http://foo bar/
google.com/search?q=`Abdu'l-Bahá
</pre>
=={{header|Lasso}}==
<
-> http://foo bar/
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
dim lookUp$( 256)
Line 938 ⟶ 987:
next j
end function
</syntaxhighlight>
Supplied URL 'http%3A%2F%2Ffoo%20bar%2F'
As string 'http://foo bar/'
=={{header|Lingo}}==
<
-- URL decodes a string
-- @param {string} str
Line 966 ⟶ 1,015:
ba.position = 1
return ba.readRawString(ba.length)
end</
<
put urldecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</
{{Out}}
<pre>
Line 976 ⟶ 1,025:
=={{header|LiveCode}}==
<
urlDecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</
google.com/search?q=`Abdu'l-Bah√°</
=={{header|Lua}}==
<
return string.char(tonumber(hex,16))
end
Line 991 ⟶ 1,040:
-- will print "http://foo bar/"
print(decodeString("http%3A%2F%2Ffoo%20bar%2F"))</
=={{header|M2000 Interpreter}}==
Line 1,001 ⟶ 1,050:
b$=chr$(a$) revert bytes to words adding zeroes after each character
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Function decodeUrl$(a$) {
Line 1,027 ⟶ 1,076:
}
CheckIt
</syntaxhighlight>
=={{header|Maple}}==
<
{{Out}}
Line 1,036 ⟶ 1,085:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
StringReplace[url, "%" ~~ x_ ~~ y_ :> FromDigits[x ~~ y, 16]] //.
StringExpression[x___, Longest[n__Integer], y___] :>
StringExpression[x, FromCharacterCode[{n}, "UTF8"], y]</
Example use:
<
{{out}}
<pre>http://foo bar/</pre>
Line 1,061 ⟶ 1,110:
=={{header|MATLAB}} / {{header|Octave}}==
<
u = '';
k = 1;
Line 1,073 ⟶ 1,122:
end
end
end</
Usage:
<pre>octave:3> urldecoding('http%3A%2F%2Ffoo%20bar%2F')
Line 1,079 ⟶ 1,128:
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols nobinary
Line 1,122 ⟶ 1,171:
return decoded
</syntaxhighlight>
{{out}}
Line 1,137 ⟶ 1,186:
=={{header|NewLISP}}==
<
;; (source http://www.newlisp.org/index.cgi?page=Code_Snippets)
(define (url-decode url (opt nil))
Line 1,143 ⟶ 1,192:
(replace "%([0-9a-f][0-9a-f])" url (pack "b" (int $1 0 16)) 1))
(url-decode "http%3A%2F%2Ffoo%20bar%2F")</
=={{header|Nim}}==
<
echo decodeUrl("http%3A%2F%2Ffoo%20bar%2F")</
{{out}}
Line 1,155 ⟶ 1,204:
=={{header|Oberon-2}}==
{{works with|oo2c}}
<
MODULE URLDecoding;
IMPORT
Line 1,164 ⟶ 1,213:
Out.String(URI.Unescape("google.com/search?q=%60Abdu%27l-Bah%C3%A1"));Out.Ln;
END URLDecoding.
</syntaxhighlight>
{{out}}
<pre>
Line 1,172 ⟶ 1,221:
=={{header|Objeck}}==
<
class UrlDecode {
function : Main(args : String[]) ~ Nil {
Line 1,178 ⟶ 1,227:
}
}
</syntaxhighlight>
=={{header|Objective-C}}==
<
NSString *normal = [encoded stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", normal);</
{{works with|Mac OS X|10.9+}}{{works with|iOS|7+}}
<
NSString *normal = [encoded stringByRemovingPercentEncoding];
NSLog(@"%@", normal);</
=={{header|OCaml}}==
Line 1,193 ⟶ 1,242:
Using the library [http://projects.camlcity.org/projects/ocamlnet.html ocamlnet] from the interactive loop:
<
# #use "topfind";;
# #require "netstring";;
# Netencoding.Url.decode "http%3A%2F%2Ffoo%20bar%2F" ;;
- : string = "http://foo bar/"</
=={{header|ooRexx}}==
While the implementation shown for [[#REXX|Rexx]] will also work with ooRexx, this version uses ooRexx syntax to invoke the built-in functions.
<
X = 0
url. = ''
Line 1,241 ⟶ 1,290:
End e_
Return decoded</
{{out}}
Line 1,257 ⟶ 1,306:
=={{header|Perl}}==
<
my $s = shift;
$s =~ tr/\+/ /;
Line 1,265 ⟶ 1,314:
print urldecode('http%3A%2F%2Ffoo+bar%2F')."\n";
</syntaxhighlight>
<
use strict ;
use URI::Escape ;
Line 1,273 ⟶ 1,322:
my $encoded = "http%3A%2F%2Ffoo%20bar%2F" ;
my $unencoded = uri_unescape( $encoded ) ;
print "The unencoded string is $unencoded !\n" ;</
=={{header|Phix}}==
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\decode_url.exw
Line 1,313 ⟶ 1,362:
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</
{{Out}}
<pre>
Line 1,321 ⟶ 1,370:
=={{header|PHP}}==
<
$encoded = "http%3A%2F%2Ffoo%20bar%2F";
$unencoded = rawurldecode($encoded);
echo "The unencoded string is $unencoded !\n";
?></
=={{header|PicoLisp}}==
Line 1,332 ⟶ 1,381:
=={{header|Pike}}==
<syntaxhighlight lang="pike">
void main()
{
Line 1,346 ⟶ 1,395:
}
}
</syntaxhighlight>
{{Out}}
<pre>
Line 1,354 ⟶ 1,403:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
[System.Web.HttpUtility]::UrlDecode("http%3A%2F%2Ffoo%20bar%2F")
</syntaxhighlight>
{{Out}}
<pre>
Line 1,363 ⟶ 1,412:
=={{header|PureBasic}}==
<
Debug URL$ ; http://foo bar/</
=={{header|Python}}==
<syntaxhighlight lang="python">
#Python 2.X
import urllib
Line 1,375 ⟶ 1,424:
from urllib.parse import unquote
print(unquote('http%3A%2F%2Ffoo%20bar%2F'))
</syntaxhighlight>
=={{header|R}}==
<
=={{header|Racket}}==
<
#lang racket
(require net/uri-codec)
(uri-decode "http%3A%2F%2Ffoo%20bar%2F")
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
google.com/search?q=%60Abdu%27l-Bah%C3%A1 >;
say .subst( :g,
/ [ '%' ( <
{ Blob.new((:16(~$_) for $0)).decode }
) for @urls;</
{{out}}
<pre>http://foo bar/
Line 1,404 ⟶ 1,453:
=={{header|Red}}==
<
== "http://foo bar/"
>> dehex "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
== "google.com/search?q=`Abdu'l-Bahá"</
=={{header|Retro}}==
This is provided by the '''casket''' library (used for web app development).
<
{{
Line 1,427 ⟶ 1,476:
}}
"http%3A%2F%2Ffoo%20bar%2F" decode buffer puts</
=={{header|REXX}}==
Line 1,433 ⟶ 1,482:
{{Trans|ooRexx}}
Tested with the ooRexx and Regina interpreters.
<
Do
Line 1,481 ⟶ 1,530:
End
Exit
</syntaxhighlight>
{{out}}
Line 1,497 ⟶ 1,546:
===version 2===
This REXX version is identical to version 1, but with superfluous and dead code removed.
<
url.1='http%3A%2F%2Ffoo%20bar%2F'
url.2='mailto%3A%22Ivan%20Aim%22%20%3Civan%2Eaim%40email%2Ecom%3E'
Line 1,525 ⟶ 1,574:
end /*while*/
return decoded</
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}}
===version 3===
This REXX version is a shorter version of version 2.
<
url. =
url.1='http%3A%2F%2Ffoo%20bar%2F'
Line 1,551 ⟶ 1,600:
else URL= URL'%'code
end /*until*/
return URL</
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}}
Line 1,557 ⟶ 1,606:
Use any one of <code>CGI.unescape</code> or <code>URI.decode_www_form_component</code>. These methods also convert "+" to " ".
<
puts CGI.unescape("http%3A%2F%2Ffoo%20bar%2F")
# => "http://foo bar/"</
{{works with|Ruby|1.9.2}}
<
puts URI.decode_www_form_component("http%3A%2F%2Ffoo%20bar%2F")
# => "http://foo bar/"</
<code>URI.unescape</code> (alias <code>URI.unencode</code>) still works. <code>URI.unescape</code> is obsolete since Ruby 1.9.2 because of problems with its sibling <code>URI.escape</code>.
=={{header|Rust}}==
<
const INPUT2: &str = "google.com/search?q=%60Abdu%27l-Bah%C3%A1";
Line 1,604 ⟶ 1,653:
println!("{}", decode(INPUT1));
println!("{}", decode(INPUT2));
}</
{{out}}
<pre>
Line 1,612 ⟶ 1,661:
=={{header|Scala}}==
{{libheader|Scala}}<
import scala.compat.Platform.currentTime
Line 1,627 ⟶ 1,676:
println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]")
}</
=={{header|Seed7}}==
Line 1,637 ⟶ 1,686:
works like ''fromPercentEncoded'' and additionally decodes '+' with a space.
Both functions return byte sequences.
To decode Unicode characters it is necessary to convert them from UTF-8 with
<
include "encoding.s7i";
Line 1,645 ⟶ 1,694:
writeln(fromPercentEncoded("http%3A%2F%2Ffoo%20bar%2F"));
writeln(fromUrlEncoded("http%3A%2F%2Ffoo+bar%2F"));
end func;</
{{out}}
Line 1,655 ⟶ 1,704:
=={{header|Sidef}}==
{{trans|Perl}}
<
str.gsub!('+', ' ');
str.gsub!(/\%([A-Fa-f0-9]{2})/, {|a| 'C'.pack(a.hex)});
Line 1,661 ⟶ 1,710:
}
say urldecode('http%3A%2F%2Ffoo+bar%2F'); # => "http://foo bar/"</
=={{header|Swift}}==
<
let encoded = "http%3A%2F%2Ffoo%20bar%2F"
if let normal = encoded.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
println(normal)
}</
=={{header|Tcl}}==
This code is careful to ensure that any untoward metacharacters in the input string still do not cause any problems.
<
set specialMap {"[" "%5B" "]" "%5D"}
set seqRE {%([0-9a-fA-F]{2})}
Line 1,679 ⟶ 1,728:
set modStr [regsub -all $seqRE [string map $specialMap $str] $replacement]
return [encoding convertfrom utf-8 [subst -nobackslash -novariable $modStr]]
}</
Demonstrating:
<
{{out}}
<pre>http://foo bar/</pre>
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
url_encoded="http%3A%2F%2Ffoo%20bar%2F"
Line 1,695 ⟶ 1,744:
PRINT "encoded: ", url_encoded
PRINT "decoded: ", url_decoded
</syntaxhighlight>
{{out}}
<pre>
Line 1,707 ⟶ 1,756:
{{works with|ksh}}
<
Alternative: Replace <code>printf '%b' "${u//%/\\x}"</code> with <code>echo -e "${u//%/\\x}"</code>
Example:
<
http://foo bar/
urldecode google.com/search?q=%60Abdu%27l-Bah%C3%A1
google.com/search?q=`Abdu'l-Bahároot@
</syntaxhighlight>
<
{
typeset encoded=$1 decoded= rest= c= c1= c2=
Line 1,784 ⟶ 1,833:
fi
}
</syntaxhighlight>
=={{header|VBScript}}==
<
Dim regEx
Set regEx = New RegExp
Line 1,831 ⟶ 1,880:
url = "http%3A%2F%2Ffoo%20bar%C3%A8%2F"
WScript.Echo "Encoded URL: " & url & vbCrLf &_
"Decoded URL: " & UrlDecode(url)</
{{out}}
Line 1,837 ⟶ 1,886:
Decoded URL: http://foo barè/</pre>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import net.urllib
fn main() {
for escaped in [
Line 1,847 ⟶ 1,896:
println(u)
}
}</
{{out}}
<pre>
Line 1,856 ⟶ 1,905:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var urlDecode = Fn.new { |enc|
Line 1,880 ⟶ 1,929:
"google.com/search?q=\%60Abdu\%27l-Bah\%C3\%A1"
]
for (enc in encs)System.print(urlDecode.call(enc))</
{{out}}
Line 1,889 ⟶ 1,938:
=={{header|XPL0}}==
<
string 0; \use zero-terminated strings
Line 1,911 ⟶ 1,960:
];
Text(0, Decode("http%3A%2F%2Ffoo%20bar%2f"))</
{{out}}
Line 1,920 ⟶ 1,969:
=={{header|Yabasic}}==
{{trans|Phix}}
<
local res$, ch$
Line 1,938 ⟶ 1,987:
print decode_url$("http%3A%2F%2Ffoo%20bar%2F")
print decode_url$("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</
=={{header|zkl}}==
<
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"</
{{out}}
<pre>http://foo bar/</pre>
or use libCurl:
<
Curl.urlDecode("http%3A%2F%2Ffoo%20bar%2F");</
{{out}}<pre>http://foo bar/</pre>
|