Tuesday, October 22, 2019

#1 2003-02-25 04:55:26 pm

Clayster
Member
Registered: 2003-02-25
Posts: 2

OS X Native URL Decoding

Hi,

I'm getting started with a small project that requires OSX Native AppleScript CGI. All is going well so far, except for the issue of decoding URLs.

All I've seen so far out there in the world is Chuck Shotton's old "Decode URL" OSAX, which doesn't appear to have been updated for native OS X compatibility.

Can anyone suggest another method for decoding URLs that would be OS X native?

Thanks!

-Clay
(AppleScript Greenhorn)

Offline

 

#2 2003-02-26 04:11:50 am

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: OS X Native URL Decoding

*Still*, as far as I know, there is no osaxen to do this job.  You can use applescript vanilla, which is very fast. A start point is Apple's routine:
http://www.apple.com/applescript/guideb … 0.htm#1005
And you  can create your own:
UNTESTED AND OPTIMIZABLE:

Applescript:

URL_Decode("Die%2Fa")

to URL_Decode(t)
   set AppleScript's text item delimiters to "%"
   set t to t's text items
   set AppleScript's text item delimiters to {""}
   set final_string to t's item 1
   repeat with i in (items 2 thru -1 of t)
       set to_decode to text from character 1 of i to character 2 of i
       try
           set the_rest to text from character 3 of i to character -1 of i
       on error
           set the_rest to ""
       end try
       hextoString(text from character 1 of i to character 2 of i)
       set final_string to final_string & result & the_rest
   end repeat
   final_string
end URL_Decode
on hextoString(t)
   set z to ""
   repeat with i from 1 to t's length by 252
       try
           set z to z & (run script "«data cstr" & ¬
               text from character i of t to character (i + 251) of t & "00» as string")
       on error
           set z to z & (run script "«data cstr" & ¬
               text from character i of t to character -1 of t & "00» as string")
       end try
   end repeat
   z
end hextoString

For long strings to decode, I'd suggest the old method of "offseting" both ASCII and HEX tables. The main objective: do not call standard additions for "run script" nor for "ascii char", not for... nothing.
For a cool sample, take a look to Has' "conversionLib" (routines related to hex-to-ascii conversion) at http://www.barple.pwp.blueyonder.co.uk/ … versionLib

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)