This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.



Test cases

   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".
   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".


 
Module CheckIt {
      Function decodeUrl$(a$) {
            DIM a$()
            a$()=Piece$(a$, "%")
            if len(a$())=1 then =str$(a$):exit
            k=each(a$(),2)
            \\ convert to one byte per character using str$(string)
            acc$=str$(a$(0))
            While k {
                        \\ chr$() convert to UTF16LE 
                        \\ str$()  convert to ANSI using locale (can be 1033 we can set it before as Locale 1033)
                        \\ so chr$(0x93) give 0x201C
                        \\ str$(chr$(0x93)) return one byte 93 in ANSI as string of one byte length
                        \\ numbers are for UTF-8 so we have to preserve them
                  acc$+=str$(Chr$(Eval("0x"+left$(a$(k^),2)))+Mid$(a$(k^),3))
            }
            =acc$
      }
      \\ decode from utf8
      final$=DecodeUrl$("google.com/search?q=%60Abdu%27l-Bah%C3%A1")
      Print string$(final$ as utf8dec)="google.com/search?q=`Abdu'l-Bahá"
      final$=DecodeUrl$("http%3A%2F%2Ffoo%20bar%2F")
      Print string$(final$ as utf8dec)="http://foo bar/"
}
CheckIt
 