Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,6 +1,9 @@
|
|||
The task is to provide a function or mechanism to convert a provided string into URL encoding representation.
|
||||
The task is to provide a function or mechanism to convert a provided string
|
||||
into URL encoding representation.
|
||||
|
||||
In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string.
|
||||
In URL encoding, special characters, control characters and extended characters
|
||||
are converted into a percent symbol followed by a two digit hexadecimal code,
|
||||
So a space character encodes into %20 within the string.
|
||||
|
||||
For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default:
|
||||
|
||||
|
|
@ -22,10 +25,9 @@ The string "<code><nowiki>http://foo bar/</nowiki></code>" would be encoded as "
|
|||
|
||||
'''Options'''
|
||||
|
||||
It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task.
|
||||
|
||||
'''See also'''
|
||||
It is permissible to use an exception string (containing a set of symbols
|
||||
that do not need to be converted).
|
||||
However, this is an optional feature and is not a requirement of this task.
|
||||
|
||||
;See also
|
||||
[[URL decoding]]
|
||||
|
||||
[[Category:String manipulation]]
|
||||
|
|
|
|||
3
Task/URL-encoding/00META.yaml
Normal file
3
Task/URL-encoding/00META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
|
|
@ -1,7 +1,19 @@
|
|||
rawURL = http://foo bar/
|
||||
SetFormat, Integer, Hex
|
||||
Loop Parse, rawURL
|
||||
If A_LoopField is not alnum ; not a-zA-Z0-9
|
||||
encURL .= "%" . SubStr(Asc(A_LoopField), 3)
|
||||
else encURL .= A_LoopField
|
||||
MsgBox % encURL
|
||||
MsgBox, % UriEncode("http://foo bar/")
|
||||
|
||||
; Modified from http://goo.gl/0a0iJq
|
||||
UriEncode(Uri)
|
||||
{
|
||||
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
|
||||
StrPut(Uri, &Var, "UTF-8")
|
||||
f := A_FormatInteger
|
||||
SetFormat, IntegerFast, H
|
||||
While Code := NumGet(Var, A_Index - 1, "UChar")
|
||||
If (Code >= 0x30 && Code <= 0x39 ; 0-9
|
||||
|| Code >= 0x41 && Code <= 0x5A ; A-Z
|
||||
|| Code >= 0x61 && Code <= 0x7A) ; a-z
|
||||
Res .= Chr(Code)
|
||||
Else
|
||||
Res .= "%" . SubStr(Code + 0x100, -1)
|
||||
SetFormat, IntegerFast, %f%
|
||||
Return, Res
|
||||
}
|
||||
|
|
|
|||
2
Task/URL-encoding/Clojure/url-encoding.clj
Normal file
2
Task/URL-encoding/Clojure/url-encoding.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(import 'java.net.URLEncoder)
|
||||
(URLEncoder/encode "http://foo bar/" "UTF-8")
|
||||
14
Task/URL-encoding/Haskell/url-encoding.hs
Normal file
14
Task/URL-encoding/Haskell/url-encoding.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import qualified Data.Char as Char
|
||||
import Text.Printf
|
||||
|
||||
encode :: Char -> String
|
||||
encode c
|
||||
| c == ' ' = "+"
|
||||
| Char.isAlphaNum c || c `elem` "-._~" = [c]
|
||||
| otherwise = printf "%%%02X" c
|
||||
|
||||
urlEncode :: String -> String
|
||||
urlEncode = concatMap encode
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn $ urlEncode "http://foo bar/"
|
||||
1
Task/URL-encoding/Maple/url-encoding.maple
Normal file
1
Task/URL-encoding/Maple/url-encoding.maple
Normal file
|
|
@ -0,0 +1 @@
|
|||
URL:-Escape("http://foo bar/");
|
||||
6
Task/URL-encoding/NewLISP/url-encoding.newlisp
Normal file
6
Task/URL-encoding/NewLISP/url-encoding.newlisp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
;; simple encoder
|
||||
;; (source http://www.newlisp.org/index.cgi?page=Code_Snippets)
|
||||
(define (url-encode str)
|
||||
(replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0))
|
||||
|
||||
(url-encode "http://foo bar/")
|
||||
1
Task/URL-encoding/R/url-encoding-1.r
Normal file
1
Task/URL-encoding/R/url-encoding-1.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
URLencode("http://foo bar/")
|
||||
2
Task/URL-encoding/R/url-encoding-2.r
Normal file
2
Task/URL-encoding/R/url-encoding-2.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
library(RCurl)
|
||||
curlEscape("http://foo bar/")
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
/*REXX pgm encodes an URL text, blanks──►+, preserves -._* and -._~ */
|
||||
url.1= 'http://foo bar/'
|
||||
url.2= 'mailto:"Ivan Aim" <ivan.aim@email.com>'
|
||||
url.3= 'mailto:"Irma User" <irma.user@mail.com>'
|
||||
url.4= 'http://foo.bar.com/~user-name/_subdir/*~.html'
|
||||
URLs=4
|
||||
url.1 = 'http://foo bar/'
|
||||
url.2 = 'mailto:"Ivan Aim" <ivan.aim@email.com>'
|
||||
url.3 = 'mailto:"Irma User" <irma.user@mail.com>'
|
||||
url.4 = 'http://foo.bar.com/~user-name/_subdir/*~.html'
|
||||
URLs = 4
|
||||
do j=1 for URLs; say
|
||||
say url.j
|
||||
say URLencode(url.j)
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────URENCODE subroutine─────────────────*/
|
||||
/*──────────────────────────────────URLENCODE subroutine────────────────*/
|
||||
URLencode: procedure; parse arg yyy; t1= '-._~' ; skip=0
|
||||
t2= '-._*' ; z=''
|
||||
|
||||
do k=1 for length(yyy); _=substr(yyy,k,1) /*pickoff 1char*/
|
||||
if skip\==0 then do /*skip t1 | t2?*/
|
||||
skip=skip-1 /*skip a char. */
|
||||
iterate
|
||||
end
|
||||
do k=1 for length(yyy); _=substr(yyy,k,1) /*pickoff 1char*/
|
||||
if skip\==0 then do /*skip t1 | t2?*/
|
||||
skip=skip-1 /*skip a char. */
|
||||
iterate
|
||||
end
|
||||
select
|
||||
when datatype(_,'A') then z=z || _ /*alphanumeric?*/
|
||||
when _==' ' then z=z'+' /*is a blank ? */
|
||||
|
|
|
|||
16
Task/URL-encoding/Scala/url-encoding.scala
Normal file
16
Task/URL-encoding/Scala/url-encoding.scala
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
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]")
|
||||
}
|
||||
13
Task/URL-encoding/VBScript/url-encoding.vb
Normal file
13
Task/URL-encoding/VBScript/url-encoding.vb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
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
|
||||
UrlEncode = UrlEncode & "%" & Hex(Asc(Mid(url,i,1)))
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
WScript.Echo UrlEncode("http://foo bar/")
|
||||
Loading…
Add table
Add a link
Reference in a new issue