Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -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]]

View file

@ -0,0 +1,3 @@
---
category:
- String manipulation

View file

@ -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
}

View file

@ -0,0 +1,2 @@
(import 'java.net.URLEncoder)
(URLEncoder/encode "http://foo bar/" "UTF-8")

View 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/"

View file

@ -0,0 +1 @@
URL:-Escape("http://foo bar/");

View 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/")

View file

@ -0,0 +1 @@
URLencode("http://foo bar/")

View file

@ -0,0 +1,2 @@
library(RCurl)
curlEscape("http://foo bar/")

View file

@ -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 ? */

View 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]")
}

View 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/")