AutoHotkey Community

It is currently May 27th, 2012, 3:24 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: uriEncoder/Decoder gui
PostPosted: June 5th, 2010, 6:27 pm 
Offline

Joined: January 10th, 2009, 6:40 pm
Posts: 32
Hey!

I had to do some excessive url encoding/decoding the other day so I wrote this simple gui to Titan's functions.

Cheers
gahks

Code:
;----------
; 2010 URI encoder/decoder gui
; http://autohotkey.net/~gahks
;
; functions by Titam
; http://www.autohotkey.com/forum/topic18876.html#119507
;----------
;VARS
;----------
edit_width = 600 ;width of edit controls
edit_height = 300 ;height of edit controls
font_size = 13 ;font size in edit controls
;----------
gui, add, radio, vradio gcode, Encode
gui, add, radio, checked1 gcode, Decode
gui, font, s%font_size%
gui, add, edit, w%edit_width% h%edit_height% gcode vedit1,
gui, add, edit, w%edit_width% h%edit_height% vedit2,
gui, show,, URI Encoder/Decoder GUI
return

code:
gui, submit, nohide
guicontrol,,edit2, % radio=2 ? uriDecode(edit1) : uriEncode(edit1)
return

guiclose:
exitapp

uriDecode(str) {
;by Titam
   Loop
      If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
         StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
      Else Break
   Return, str
}

uriEncode(str)
{
;by Titam & ESUHSD
   ; Replace characters with uri encoded version except for letters, numbers,
   ; and the following: /.~:&=-
   f = %A_FormatInteger%
   SetFormat, Integer, Hex
   pos = 1
   Loop
      If pos := RegExMatch(str, "i)[^\/\w\.~`:%&=-]", char, pos++)
         StringReplace, str, str, %char%, % "%" . Asc(char), All
      Else Break
   SetFormat, Integer, %f%
   StringReplace, str, str, 0x, , All
   Return, str
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Stigg, tidbit and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group