2017-12-15

Navigation

Skip Navigation Links

Hash algorithms

Asymmetric Algorithms

Symmetric Cipher Algorithms

Encoding Algorithms

Compression Algorithms

Pseudo Random Number Algorithms

Steganography

Library Wrappers

String Comparison

Others

Syntax highlighting by Prism
PBCrypto.com Mirror

URLDecode

Algorithm creator(s)

n/a


PB author(s)

Alban Dominic Read


Description

Decodes encoded URLs of the application/x-www-form-urlencoded media type


Note

n/a


Source

https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/24460-decode-urlencoded-string?t=23824


See also

n/a


Source Code

Download source code file urldecode.bas (Right-click -> "Save as ...")

FUNCTION URLUnEncode( url AS STRING) AS STRING
LOCAL pbByte AS BYTE PTR
LOCAL pbUrl AS BYTE PTR
LOCAL pbTable AS BYTE PTR
LOCAL b1 AS BYTE
STATIC table AS STRING
LOCAL pszReturnStr AS ASCIIZ PTR
IF table="" THEN
table=table+CHR$(0)+CHR$(1)+CHR$(2)+CHR$(3)+CHR$(4)+CHR$(5)+CHR$(6)+CHR$(7)+CHR$(8)+CHR$(9)
table=table+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)
table=table+CHR$(10)+CHR$(11)+CHR$(12)+CHR$(13)+CHR$(14)+CHR$(15)+CHR$(16)
END IF
pbByte = STRPTR( url )
pbUrl = STRPTR( url )
pbTable = STRPTR(table)
DO WHILE @pbByte <> 0
IF @pbByte = ASC("%") AND NOT @pbByte[1] = ASC("%") THEN
INCR pbByte
b1 = @pbTable[@pbByte-48]
SHIFT LEFT b1,4
INCR pbByte
@pbUrl= @pbTable[@pbByte-48]+b1
INCR pbByte
INCR pbUrl
ITERATE DO
END IF
@pbUrl = @pbByte
INCR pbByte
INCR pbUrl
LOOP
@pbUrl = 0
pszReturnStr = STRPTR( url )
FUNCTION = @pszReturnStr
END FUNCTION 

Mirror provided by Knuth Konrad