URLEncode: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(Created page with "This is a function to URL-encode a string in NSIS found in [http://forums.winamp.com/showthread.php?t=345400 the forums], it was made by WindBridges. == Usage == <highlight-n...") |
m (added Category:String Functions) |
||
Line 81: | Line 81: | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:String Functions]] |
Revision as of 17:38, 1 September 2015
This is a function to URL-encode a string in NSIS found in the forums, it was made by WindBridges.
Usage
!include "URLEncode.nsh" Push "hello dolly!" Call URLEncode Pop $0 ; now $0 contains "hello+dolly%21"
Requirements
Requires the CharToASCII and LogicLib header files put in your include directory.
Code
Just create a URLEncode.nsh
file in your include dir with this content:
!include "LogicLib.nsh" !include "CharToASCII.nsh" Function URLEncode Pop $0 ;param StrCpy $1 -1 ;init counter StrCpy $9 "" ; init buffer NextChar: IntOp $1 $1 + 1 StrCpy $2 $0 1 $1 ;get char ${If} $2 == "" Goto Done ${EndIf} ${CharToASCII} $3 $2 ; get charcode ${If} $3 == 32 StrCpy $9 "$9+" Goto NextChar ${EndIf} ${If} $3 == 95 ${OrIf} $3 == 45 StrCpy $9 $9$2 Goto NextChar ${EndIf} ${If} $3 >= 33 ${AndIf} $3 <= 47 IntFmt $4 "%X" $3 StrCpy $9 $9%$4 Goto NextChar ${EndIf} ${If} $3 >= 58 ${AndIf} $3 <= 64 IntFmt $4 "%X" $3 StrCpy $9 $9%$4 Goto NextChar ${EndIf} ${If} $3 >= 91 ${AndIf} $3 <= 96 IntFmt $4 "%X" $3 StrCpy $9 $9%$4 Goto NextChar ${EndIf} ${If} $3 >= 123 IntFmt $4 "%X" $3 StrCpy $9 $9%$4 Goto NextChar ${EndIf} StrCpy $9 $9$2 Goto NextChar Done: Push $9 FunctionEnd