added deguix's collection of string functions
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3479 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
8c8a8a701d
commit
58efd7312d
4 changed files with 1697 additions and 0 deletions
167
Examples/StrFunc.nsi
Normal file
167
Examples/StrFunc.nsi
Normal file
|
@ -0,0 +1,167 @@
|
|||
Name "NSIS StrFunc Example"
|
||||
OutFile "StrFunc.exe"
|
||||
ShowInstDetails show
|
||||
|
||||
!include "StrFunc.nsh"
|
||||
|
||||
# declare used functions
|
||||
${StrClbGet}
|
||||
${StrClbSet}
|
||||
${StrIOToNSIS}
|
||||
${StrLoc}
|
||||
${StrLowerCase}
|
||||
${StrNSISToIO}
|
||||
${StrRep}
|
||||
${StrStr}
|
||||
${StrStrAdv}
|
||||
${StrTok}
|
||||
${StrTrimNewLines}
|
||||
${StrUpperCase}
|
||||
|
||||
Section
|
||||
|
||||
# test clipboard functions
|
||||
${StrClbSet} "StrFunc clipboard test"
|
||||
${StrClbGet} $0
|
||||
StrCmp $0 "StrFunc clipboard test" +3
|
||||
DetailPrint "FAILED StrClbGet/StrClbSet test"
|
||||
Goto +2
|
||||
DetailPrint "PASSED StrClbGet/StrClbSet test"
|
||||
|
||||
# test IO functions
|
||||
!macro testio str
|
||||
${StrNSISToIO} $0 "${str}"
|
||||
${StrIOToNSIS} $0 $0
|
||||
StrCmp $0 "${str}" 0 ioerror
|
||||
!macroend
|
||||
!insertmacro testio "$\rtest$\n"
|
||||
!insertmacro testio "test$\n"
|
||||
!insertmacro testio "$\rtest"
|
||||
!insertmacro testio "test"
|
||||
!insertmacro testio "$\r\$\t$\n"
|
||||
!insertmacro testio "$\r \ $\t $\n $$"
|
||||
!insertmacro testio ""
|
||||
!insertmacro testio " "
|
||||
DetailPrint "PASSED StrNSISToIO/StrIOToNSIS test"
|
||||
Goto +2
|
||||
ioerror:
|
||||
DetailPrint "FAILED StrNSISToIO/StrIOToNSIS test"
|
||||
|
||||
# test string search functions
|
||||
${StrLoc} $0 "This is just an example" "just" "<"
|
||||
StrCmp $0 "11" 0 strlocerror
|
||||
${StrLoc} $0 a abc <
|
||||
StrCmp $0 "" 0 strlocerror
|
||||
${StrLoc} $0 a abc >
|
||||
StrCmp $0 "" 0 strlocerror
|
||||
${StrLoc} $0 abc a >
|
||||
StrCmp $0 "0" 0 strlocerror
|
||||
${StrLoc} $0 abc b >
|
||||
StrCmp $0 "1" 0 strlocerror
|
||||
${StrLoc} $0 abc c >
|
||||
StrCmp $0 "2" 0 strlocerror
|
||||
${StrLoc} $0 abc a <
|
||||
StrCmp $0 "2" 0 strlocerror
|
||||
${StrLoc} $0 abc b <
|
||||
StrCmp $0 "1" 0 strlocerror
|
||||
${StrLoc} $0 abc c <
|
||||
StrCmp $0 "0" 0 strlocerror
|
||||
${StrLoc} $0 abc d <
|
||||
StrCmp $0 "" 0 strlocerror
|
||||
DetailPrint "PASSED StrLoc test"
|
||||
Goto +2
|
||||
strlocerror:
|
||||
DetailPrint "FAILED StrLoc test"
|
||||
|
||||
${StrStr} $0 "abcefghijklmnopqrstuvwxyz" "g"
|
||||
StrCmp $0 "ghijklmnopqrstuvwxyz" 0 strstrerror
|
||||
${StrStr} $0 "abcefghijklmnopqrstuvwxyz" "ga"
|
||||
StrCmp $0 "" 0 strstrerror
|
||||
${StrStr} $0 "abcefghijklmnopqrstuvwxyz" ""
|
||||
StrCmp $0 "abcefghijklmnopqrstuvwxyz" 0 strstrerror
|
||||
${StrStr} $0 "a" "abcefghijklmnopqrstuvwxyz"
|
||||
StrCmp $0 "" 0 strstrerror
|
||||
DetailPrint "PASSED StrStr test"
|
||||
Goto +2
|
||||
strstrerror:
|
||||
DetailPrint "FAILED StrStr test"
|
||||
|
||||
${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "0"
|
||||
StrCmp $0 "abcabcabc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "1"
|
||||
StrCmp $0 "abcabc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "2"
|
||||
StrCmp $0 "abc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "3"
|
||||
StrCmp $0 "" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "abc" ">" "<" "1" "1"
|
||||
StrCmp $0 "abcabc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "abc" ">" "<" "0" "1"
|
||||
StrCmp $0 "abcabc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "abc" "<" "<" "1" "0"
|
||||
StrCmp $0 "abcabcabc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "abc" "<" "<" "0" "0"
|
||||
StrCmp $0 "abcabc" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "0"
|
||||
StrCmp $0 "" 0 strstradverror
|
||||
${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "1"
|
||||
StrCmp $0 "abc" 0 strstradverror
|
||||
DetailPrint "PASSED StrStrAdv test"
|
||||
Goto +2
|
||||
strstradverror:
|
||||
DetailPrint "FAILED StrStrAdv test"
|
||||
|
||||
# test string replacement
|
||||
${StrRep} $0 "This is just an example" "an" "one"
|
||||
StrCmp $0 "This is just one example" 0 strreperror
|
||||
${StrRep} $0 "test... test... 1 2 3..." "test" "testing"
|
||||
StrCmp $0 "testing... testing... 1 2 3..." 0 strreperror
|
||||
${StrRep} $0 "" "test" "testing"
|
||||
StrCmp $0 "" 0 strreperror
|
||||
${StrRep} $0 "test" "test" "testing"
|
||||
StrCmp $0 "testing" 0 strreperror
|
||||
${StrRep} $0 "test" "test" ""
|
||||
StrCmp $0 "" 0 strreperror
|
||||
${StrRep} $0 "test" "" "abc"
|
||||
StrCmp $0 "test" 0 strreperror
|
||||
${StrRep} $0 "test" "" ""
|
||||
StrCmp $0 "test" 0 strreperror
|
||||
DetailPrint "PASSED StrRep test"
|
||||
Goto +2
|
||||
strreperror:
|
||||
DetailPrint "FAILED StrRep test"
|
||||
|
||||
# test lower/upper case
|
||||
${StrLowerCase} $0 "abcefghijklmnopqrstuvwxyz"
|
||||
${StrUpperCase} $0 $0
|
||||
StrCmp $0 "abcefghijklmnopqrstuvwxyz" +3
|
||||
DetailPrint "FAILED StrLowerCase/StrUpperCase test"
|
||||
Goto +2
|
||||
DetailPrint "PASSED StrLowerCase/StrUpperCase test"
|
||||
|
||||
# test tokenizer
|
||||
${StrTok} $0 "This is, or is not, just an example" " ," "5" "1"
|
||||
StrCmp $0 "not" 0 strtokerror
|
||||
${StrTok} $0 "This is, or is not, just an example" " ," "5" "0"
|
||||
StrCmp $0 "is" 0 strtokerror
|
||||
${StrTok} $0 "This is, or is not, just an example" " ," "152" "0"
|
||||
StrCmp $0 "" 0 strtokerror
|
||||
${StrTok} $0 "This is, or is not, just an example" " ," "0" "0"
|
||||
StrCmp $0 "example" 0 strtokerror
|
||||
${StrTok} $0 "This is, or is not, just an example" " ," "-1" "0"
|
||||
StrCmp $0 "example" 0 strtokerror
|
||||
${StrTok} $0 "This is, or is not, just an example" " ," "1" "0"
|
||||
StrCmp $0 "This" 0 strtokerror
|
||||
DetailPrint "PASSED StrTok test"
|
||||
Goto +2
|
||||
strtokerror:
|
||||
DetailPrint "FAILED StrTok test"
|
||||
|
||||
# test trim new lines
|
||||
${StrTrimNewLines} $0 "$\r$\ntest$\r$\ntest$\r$\n"
|
||||
StrCmp $0 "$\r$\ntest$\r$\ntest" +3
|
||||
DetailPrint "FAILED StrTrimNewLines test"
|
||||
Goto +2
|
||||
DetailPrint "PASSED StrTrimNewLines test"
|
||||
|
||||
SectionEnd
|
|
@ -118,6 +118,8 @@ Section "NSIS Core Files (required)" SecCore
|
|||
File ..\Include\Sections.nsh
|
||||
File ..\Include\UpgradeDLL.nsh
|
||||
File ..\Include\LogicLib.nsh
|
||||
File ..\Include\StrFunc.nsh
|
||||
File ..\Include\StrFunc.txt
|
||||
|
||||
SetOutPath $INSTDIR\Contrib\Makensisw
|
||||
File ..\contrib\makensisw\*.txt
|
||||
|
@ -190,6 +192,7 @@ Section "Script Examples" SecExample
|
|||
File ..\Examples\UserVars.nsi
|
||||
File ..\Examples\LogicLib.nsi
|
||||
File ..\Examples\silent.nsi
|
||||
File ..\Examples\StrFunc.nsi
|
||||
SectionEnd
|
||||
|
||||
!ifndef NO_STARTMENUSHORTCUTS
|
||||
|
|
976
Include/StrFunc.nsh
Normal file
976
Include/StrFunc.nsh
Normal file
|
@ -0,0 +1,976 @@
|
|||
/*
|
||||
|
||||
Functions Header File for NSIS
|
||||
|
||||
StrFunc.nsh
|
||||
This file contains functions for string manipulation for NSIS
|
||||
|
||||
by Diego Pedroso (aka deguix)
|
||||
|
||||
*/
|
||||
|
||||
!ifndef MUI_VERBOSE
|
||||
!define MUI_VERBOSE 3
|
||||
!endif
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nNSIS String Functions Header File 1.01 - © 2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define StrClbGet "!insertmacro FUNCTION_STRING_StrClbGet"
|
||||
!define StrClbSet "!insertmacro FUNCTION_STRING_StrClbSet"
|
||||
!define StrIOToNSIS "!insertmacro FUNCTION_STRING_StrIOToNSIS"
|
||||
!define StrLoc "!insertmacro FUNCTION_STRING_StrLoc"
|
||||
!define StrLowerCase "!insertmacro FUNCTION_STRING_StrLowerCase"
|
||||
!define StrNSISToIO "!insertmacro FUNCTION_STRING_StrNSISToIO"
|
||||
!define StrRep "!insertmacro FUNCTION_STRING_StrRep"
|
||||
!define StrStr "!insertmacro FUNCTION_STRING_StrStr"
|
||||
!define StrStrAdv "!insertmacro FUNCTION_STRING_StrStrAdv"
|
||||
!define StrTok "!insertmacro FUNCTION_STRING_StrTok"
|
||||
!define StrTrimNewLines "!insertmacro FUNCTION_STRING_StrTrimNewLines"
|
||||
!define StrUpperCase "!insertmacro FUNCTION_STRING_StrUpperCase"
|
||||
|
||||
!macro FUNCTION_STRING_StrStr
|
||||
|
||||
!ifndef FUNCTION_STRING_StrStr
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nSearch in String Function - 2002-2004 Ximon Eighteen\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrStr
|
||||
!undef StrStr
|
||||
!define StrStr "!insertmacro FUNCTION_STRING_StrStr_Call"
|
||||
|
||||
Function StrStr
|
||||
Exch $R1 ; st=haystack,old$R1, $R1=needle
|
||||
Exch ; st=old$R1,haystack
|
||||
Exch $R2 ; st=old$R1,old$R2, $R2=haystack
|
||||
Push $R3
|
||||
Push $R4
|
||||
Push $R5
|
||||
StrLen $R3 $R1
|
||||
StrCpy $R4 0
|
||||
; $R1=needle
|
||||
; $R2=haystack
|
||||
; $R3=len(needle)
|
||||
; $R4=cnt
|
||||
; $R5=tmp
|
||||
loop:
|
||||
StrCpy $R5 $R2 $R3 $R4
|
||||
StrCmp $R5 $R1 done
|
||||
StrCmp $R5 "" done
|
||||
IntOp $R4 $R4 + 1
|
||||
Goto loop
|
||||
done:
|
||||
StrCpy $R1 $R2 "" $R4
|
||||
Pop $R5
|
||||
Pop $R4
|
||||
Pop $R3
|
||||
Pop $R2
|
||||
Exch $R1
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrStr_Call ResultVar String StrToSearchFor
|
||||
|
||||
!echo `$ {StrStr} "${ResultVar}" "${String}" "${StrToSearchFor}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
Push `${StrToSearchFor}`
|
||||
|
||||
Call StrStr
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrLoc
|
||||
|
||||
!ifndef FUNCTION_STRING_StrLoc
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nLocalize in String Function - © 2004 Diego Pedroso\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrLoc
|
||||
!undef StrLoc
|
||||
!define StrLoc "!insertmacro FUNCTION_STRING_StrLoc_Call"
|
||||
|
||||
Function StrLoc
|
||||
Exch $R0
|
||||
Exch
|
||||
Exch $R1 ; st=haystack,old$R1, $R1=needle
|
||||
Exch 2 ; st=old$R1,haystack
|
||||
Exch $R2 ; st=old$R1,old$R2, $R2=haystack
|
||||
|
||||
Push $R3
|
||||
Push $R4
|
||||
Push $R5
|
||||
StrLen $R3 $R1
|
||||
StrCpy $R4 0
|
||||
loop:
|
||||
StrCpy $R5 $R2 $R3 $R4
|
||||
StrCmp $R5 $R1 done
|
||||
StrCmp $R5 "" error
|
||||
IntOp $R4 $R4 + 1
|
||||
Goto loop
|
||||
done:
|
||||
|
||||
StrCmp $R0 "<" 0 +5
|
||||
StrLen $R0 $R2
|
||||
IntOp $R0 $R0 - $R4
|
||||
IntOp $R0 $R0 - $R3
|
||||
Goto +2
|
||||
|
||||
StrCpy $R0 $R4
|
||||
Goto +2
|
||||
|
||||
error:
|
||||
StrCpy $R0 ""
|
||||
|
||||
Pop $R5
|
||||
Pop $R4
|
||||
Pop $R3
|
||||
Pop $R2
|
||||
Pop $R1
|
||||
Exch $R0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrLoc_Call ResultVar String StrToSearchFor Direction
|
||||
|
||||
!echo `$ {StrLoc} "${ResultVar}" "${String}" "${StrToSearchFor}" "${Direction}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
Push `${StrToSearchFor}`
|
||||
Push `${Direction}`
|
||||
|
||||
Call StrLoc
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrStrAdv
|
||||
|
||||
!ifndef FUNCTION_STRING_StrStrAdv
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nAdvanced Search in String Function - © 2003-2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrStrAdv
|
||||
!undef StrStrAdv
|
||||
|
||||
!define StrStrAdv "!insertmacro FUNCTION_STRING_StrStrAdv_Call"
|
||||
|
||||
Function AdvancedStrStr
|
||||
|
||||
# Preparing Variables
|
||||
|
||||
Exch $R9
|
||||
Exch
|
||||
Exch $R8
|
||||
Exch
|
||||
Exch 2
|
||||
Exch $R7
|
||||
Exch 2
|
||||
Exch 3
|
||||
Exch $R6
|
||||
Exch 3
|
||||
Exch 4
|
||||
Exch $R5
|
||||
Exch 4
|
||||
Exch 5
|
||||
Exch $R4
|
||||
Exch 5
|
||||
Push $R3
|
||||
Push $R2
|
||||
Push $R1
|
||||
Push $R0
|
||||
Push $9
|
||||
Push $8
|
||||
Push $7
|
||||
Push $6
|
||||
StrCpy $R2 $R4
|
||||
StrCpy $R1 $R5
|
||||
StrCpy $R4 ""
|
||||
StrCpy $R5 ""
|
||||
StrCpy $7 $R2
|
||||
|
||||
# Detect Empty Input
|
||||
|
||||
StrCmp $R1 "" 0 +3
|
||||
SetErrors
|
||||
Goto granddone
|
||||
|
||||
StrCmp $R2 "" 0 +3
|
||||
SetErrors
|
||||
Goto granddone
|
||||
|
||||
StrCmp $R6 "" 0 +2
|
||||
StrCpy $R6 >
|
||||
|
||||
StrCmp $R7 "" 0 +2
|
||||
StrCpy $R7 >
|
||||
|
||||
# Preparing StrStr
|
||||
|
||||
StrCpy $R0 0
|
||||
|
||||
IntCmp $R9 1 +2 0 +2
|
||||
StrCpy $R9 0
|
||||
|
||||
IntOp $R9 $R9 + 1
|
||||
|
||||
# Loops and more loops if you want...
|
||||
|
||||
grandloop:
|
||||
|
||||
# Detect if the loops number given by user = code runs...
|
||||
|
||||
StrCpy $R4 0
|
||||
StrLen $R3 $R1
|
||||
StrCpy $6 $R3
|
||||
StrCmp $9 1 0 +4
|
||||
StrCmp $R6 "<" 0 +2
|
||||
IntOp $R3 $R3 + 1
|
||||
IntOp $R4 $R4 + 1
|
||||
|
||||
StrCmp $R6 "<" 0 +5
|
||||
IntOp $R3 $R3 * -1
|
||||
StrCpy $6 $R3
|
||||
IntCmp $R0 0 +2 0 0
|
||||
IntOp $6 $6 + 1
|
||||
|
||||
# Searching the string
|
||||
|
||||
loop:
|
||||
|
||||
# RTL...
|
||||
|
||||
StrCmp $R6 "<" 0 EndBack
|
||||
|
||||
IntOp $9 $R4 * -1
|
||||
|
||||
StrCmp $9 0 0 +3
|
||||
StrCpy $R5 $R2 "" $R3
|
||||
Goto +2
|
||||
StrCpy $R5 $R2 $9 $R3
|
||||
Goto +2
|
||||
|
||||
EndBack:
|
||||
|
||||
# LTR...
|
||||
|
||||
StrCpy $R5 $R2 $R3 $R4
|
||||
|
||||
# Detect if the value returned is the searched...
|
||||
|
||||
StrCmp $R5 $R1 done
|
||||
|
||||
StrCmp $R5 "" granddone
|
||||
|
||||
# If not, make a loop...
|
||||
|
||||
IntOp $R4 $R4 + 1
|
||||
StrCmp $R6 "<" 0 +2
|
||||
IntOp $R3 $R3 - 1
|
||||
|
||||
Goto loop
|
||||
|
||||
done:
|
||||
|
||||
StrCmp $R6 "<" 0 +3
|
||||
IntOp $8 $9 + $8
|
||||
Goto +2
|
||||
IntOp $8 $R4 + $8
|
||||
|
||||
# Looping Calculation...
|
||||
|
||||
IntOp $R0 $R0 + 1
|
||||
|
||||
IntCmp $R0 $R9 0 continueloop 0
|
||||
|
||||
# Customizing the string to fit user conditions (supported by loops)...
|
||||
|
||||
# RTL...
|
||||
|
||||
StrCmp $R6 "<" 0 EndBackward
|
||||
StrCmp $R7 ">" 0 +7
|
||||
StrCmp $8 0 0 +3
|
||||
StrCpy $R2 ""
|
||||
Goto +2
|
||||
StrCpy $R2 $7 "" $8
|
||||
StrCpy $R2 $R1$R2
|
||||
Goto +3
|
||||
|
||||
StrCmp $9 0 +2
|
||||
StrCpy $R2 $R2 $9
|
||||
|
||||
StrCmp $R8 1 EndForward 0
|
||||
StrCmp $R7 ">" 0 End>
|
||||
Push $6
|
||||
IntOp $6 $6 * -1
|
||||
StrCpy $R2 $R2 "" $6
|
||||
Pop $6
|
||||
Goto +2
|
||||
End>:
|
||||
StrCpy $R2 $R2 $6
|
||||
Goto EndForward
|
||||
EndBackward:
|
||||
|
||||
# LTR...
|
||||
|
||||
StrCmp $R7 "<" 0 +4
|
||||
StrCpy $R2 $7 $8
|
||||
StrCpy $R2 $R2$R1
|
||||
Goto +2
|
||||
StrCpy $R2 $R2 "" $R4
|
||||
StrCmp $R8 1 EndForward 0
|
||||
StrCmp $R7 "<" 0 End<
|
||||
Push $6
|
||||
IntOp $6 $6 * 2
|
||||
StrCpy $R2 $R2 $6
|
||||
Pop $6
|
||||
Goto +2
|
||||
End<:
|
||||
StrCpy $R2 $R2 "" $R3
|
||||
EndForward:
|
||||
|
||||
Goto stoploop
|
||||
|
||||
continueloop:
|
||||
|
||||
# Customizing the string to fits user conditions (not supported by loops)...
|
||||
|
||||
# RTL...
|
||||
|
||||
StrCmp $R6 "<" 0 +4
|
||||
StrCmp $9 0 +4
|
||||
StrCpy $R2 $R2 $9
|
||||
Goto +2
|
||||
|
||||
# LTR...
|
||||
|
||||
StrCpy $R2 $R2 "" $R4
|
||||
|
||||
stoploop:
|
||||
|
||||
# Return to grandloop init...
|
||||
|
||||
StrCpy $9 1
|
||||
|
||||
IntCmp $R0 $R9 0 grandloop 0
|
||||
|
||||
StrCpy $R4 $R2
|
||||
|
||||
Goto +2
|
||||
|
||||
granddone:
|
||||
|
||||
# Return the result to user
|
||||
|
||||
StrCpy $R4 ""
|
||||
|
||||
Pop $6
|
||||
Pop $7
|
||||
Pop $8
|
||||
Pop $9
|
||||
Pop $R0
|
||||
Pop $R1
|
||||
Pop $R2
|
||||
Pop $R3
|
||||
Pop $R9
|
||||
Pop $R8
|
||||
Pop $R7
|
||||
Pop $R6
|
||||
Pop $R5
|
||||
Exch $R4
|
||||
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrStrAdv_Call ResultVar String StrToSearchFor SearchDirection ResultStrDirection DisplayStrToSearch Loops
|
||||
|
||||
!echo `$ {StrStrAdv} "${ResultVar}" "${String}" "${StrToSearchFor}" "${SearchDirection}" "${ResultStrDirection}" "${DisplayStrToSearch}" "${Loops}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
Push `${StrToSearchFor}`
|
||||
Push `${SearchDirection}`
|
||||
Push `${ResultStrDirection}`
|
||||
Push `${DisplayStrToSearch}`
|
||||
Push `${Loops}`
|
||||
|
||||
Call AdvancedStrStr
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrTok
|
||||
|
||||
!ifndef FUNCTION_STRING_StrTok
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nAdvanced Token String Function - © 2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrTok
|
||||
!undef StrTok
|
||||
!define StrTok "!insertmacro FUNCTION_STRING_StrTok_Call"
|
||||
|
||||
Function AdvancedStrTok
|
||||
Exch $9
|
||||
Exch
|
||||
Exch $R0
|
||||
Exch 2
|
||||
Exch $R1
|
||||
Exch 3
|
||||
Exch $R2
|
||||
Push $R3
|
||||
Push $R4
|
||||
Push $R5
|
||||
Push $R6
|
||||
Push $R7
|
||||
Push $R8
|
||||
Push $R9
|
||||
Push $0
|
||||
Push $1
|
||||
Push $2
|
||||
|
||||
StrCpy $R8 0
|
||||
StrCpy $R9 $R1
|
||||
|
||||
IntCmp $R0 0 0 0 +2
|
||||
StrCpy $R0 L
|
||||
|
||||
|
||||
StrCmp $R0 L 0 +5
|
||||
StrCpy $2 1
|
||||
StrCpy $R0 0
|
||||
StrCpy $1 ""
|
||||
StrCpy $9 1
|
||||
|
||||
PartLoop:
|
||||
|
||||
StrCpy $R4 0
|
||||
IntOp $R8 $R8 + 1
|
||||
StrCpy $0 0
|
||||
|
||||
loop:
|
||||
|
||||
StrCpy $R5 $R2 1 $R4
|
||||
StrCmp $R5 "" done
|
||||
|
||||
StrCpy $R6 -1
|
||||
StrCpy $R7 0
|
||||
loop2:
|
||||
|
||||
IntOp $R6 $R6 + 1
|
||||
IntOp $R7 $R6 + 1
|
||||
StrCpy $R3 $R1 $R7 $R6
|
||||
StrCmp $R3 "" 0 +3
|
||||
IntOp $0 $0 + 1
|
||||
Goto ContLoop2
|
||||
StrCmp $R5 $R3 0 Loop2
|
||||
StrCmp $9 1 0 done
|
||||
StrCmp $0 0 0 done
|
||||
StrCpy $R2 $R2 "" 1
|
||||
Goto Loop
|
||||
|
||||
ContLoop2:
|
||||
|
||||
IntOp $R4 $R4 + 1
|
||||
Goto loop
|
||||
|
||||
done:
|
||||
IntOp $R4 $R4 + $0
|
||||
StrCpy $R1 $R2 $0
|
||||
IntOp $0 $0 + 1
|
||||
StrCpy $R2 $R2 "" $0
|
||||
|
||||
StrCmp $2 1 0 +4
|
||||
StrCmp $R1 "" 0 +3
|
||||
StrCpy $R1 $1
|
||||
Goto End
|
||||
|
||||
StrCmp $R0 $R8 End
|
||||
StrCmp $2 1 0 +2
|
||||
StrCpy $1 $R1
|
||||
StrCpy $R1 $R9
|
||||
Goto PartLoop
|
||||
|
||||
End:
|
||||
|
||||
StrCpy $9 $R1
|
||||
|
||||
Pop $2
|
||||
Pop $1
|
||||
Pop $0
|
||||
Pop $R9
|
||||
Pop $R8
|
||||
Pop $R7
|
||||
Pop $R6
|
||||
Pop $R5
|
||||
Pop $R4
|
||||
Pop $R3
|
||||
Pop $R2
|
||||
Pop $R1
|
||||
Pop $R0
|
||||
Exch $9
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrTok_Call ResultVar StrToTokenizing Separators ResultPart SkipEmptyParts
|
||||
|
||||
!echo `$ {StrTok} "${ResultVar}" "${StrToTokenizing}" "${Separators}" "${ResultPart}" "${SkipEmptyParts}"$\r$\n`
|
||||
|
||||
Push `${StrToTokenizing}`
|
||||
Push `${Separators}`
|
||||
Push `${ResultPart}`
|
||||
Push `${SkipEmptyParts}`
|
||||
|
||||
Call AdvancedStrTok
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrClbSet
|
||||
|
||||
!ifndef FUNCTION_STRING_StrClbSet
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nCopy To Clipboard - 2003-2004 Nik Medved$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrClbSet
|
||||
!undef StrClbSet
|
||||
|
||||
!define StrClbSet "!insertmacro FUNCTION_STRING_StrClb_Set"
|
||||
|
||||
Function CopyToClipboard
|
||||
Exch $0 ;input string
|
||||
Push $1
|
||||
Push $2
|
||||
System::Call 'user32::OpenClipboard(i 0)'
|
||||
System::Call 'user32::EmptyClipboard()'
|
||||
StrLen $1 $0
|
||||
IntOp $1 $1 + 1
|
||||
System::Call 'kernel32::GlobalAlloc(i 2, i r1) i.r1'
|
||||
System::Call 'kernel32::GlobalLock(i r1) i.r2'
|
||||
System::Call 'kernel32::lstrcpyA(i r2, t r0)'
|
||||
System::Call 'kernel32::GlobalUnlock(i r1)'
|
||||
System::Call 'user32::SetClipboardData(i 1, i r1)'
|
||||
System::Call 'user32::CloseClipboard()'
|
||||
Pop $2
|
||||
Pop $1
|
||||
Pop $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrClbGet
|
||||
|
||||
!ifndef FUNCTION_STRING_StrClbGet
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nCopy From Clipboard Function - 2003-2004 Nik Medved - changed by Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrClbGet
|
||||
!undef StrClbGet
|
||||
|
||||
!define StrClbGet "!insertmacro FUNCTION_STRING_StrClb_Get"
|
||||
|
||||
Function CopyFromClipboard
|
||||
Push $0
|
||||
System::Call 'user32::OpenClipboard(i 0)'
|
||||
System::Call 'user32::GetClipboardData(i 1) t .r0'
|
||||
System::Call 'user32::CloseClipboard()'
|
||||
Exch $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrClb_Set String
|
||||
|
||||
!echo `$ {StrClbSet} "${String}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
|
||||
Call CopyToClipboard
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrClb_Get ResultVar
|
||||
|
||||
!echo `$ {StrClbGet} "${ResultVar}"$\r$\n`
|
||||
|
||||
Call CopyFromClipboard
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrUpperCase
|
||||
|
||||
!ifndef FUNCTION_STRING_StrUpperCase
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nUppercase String Function - 2002-2004 Dave Laundon $\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrUpperCase
|
||||
!undef StrUpperCase
|
||||
!define StrUpperCase "!insertmacro FUNCTION_STRING_StrUpperCase_Call"
|
||||
|
||||
Function StrUpper
|
||||
Exch $0 ; Original string
|
||||
Push $1 ; Final string
|
||||
Push $2 ; Current character
|
||||
Push $3
|
||||
Push $4
|
||||
StrCpy $1 ""
|
||||
Loop:
|
||||
StrCpy $2 $0 1 ; Get next character
|
||||
StrCmp $2 "" Done
|
||||
StrCpy $0 $0 "" 1
|
||||
StrCpy $3 65 ; 65 = ASCII code for A
|
||||
Loop2:
|
||||
IntFmt $4 %c $3 ; Get character from current ASCII code
|
||||
StrCmp $2 $4 Match
|
||||
IntOp $3 $3 + 1
|
||||
StrCmp $3 91 NoMatch Loop2 ; 91 = ASCII code one beyond Z
|
||||
Match:
|
||||
StrCpy $2 $4 ; It 'matches' (either case) so grab the uppercase version
|
||||
NoMatch:
|
||||
StrCpy $1 $1$2 ; Append to the final string
|
||||
Goto Loop
|
||||
Done:
|
||||
StrCpy $0 $1 ; Return the final string
|
||||
Pop $4
|
||||
Pop $3
|
||||
Pop $2
|
||||
Pop $1
|
||||
Exch $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrUpperCase_Call ResultVar String
|
||||
|
||||
!echo `$ {StrUpperCase} "${ResultVar}" "${String}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
|
||||
Call StrUpper
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrLowerCase
|
||||
|
||||
!ifndef FUNCTION_STRING_StrLowerCase
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nLowercase String Function - changed from Uppercase String Function 2002-2004 Dave Laundon$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrLowerCase
|
||||
!undef StrLowerCase
|
||||
!define StrLowerCase "!insertmacro FUNCTION_STRING_StrLowerCase_Call"
|
||||
|
||||
Function StrLower
|
||||
Exch $0 ; Original string
|
||||
Push $1 ; Final string
|
||||
Push $2 ; Current character
|
||||
Push $3
|
||||
Push $4
|
||||
StrCpy $1 ""
|
||||
Loop:
|
||||
StrCpy $2 $0 1 ; Get next character
|
||||
StrCmp $2 "" Done
|
||||
StrCpy $0 $0 "" 1
|
||||
StrCpy $3 122 ; 122 = ASCII code for z
|
||||
Loop2:
|
||||
IntFmt $4 %c $3 ; Get character from current ASCII code
|
||||
StrCmp $2 $4 Match
|
||||
IntOp $3 $3 - 1
|
||||
StrCmp $3 91 NoMatch Loop2 ; 90 = ASCII code one beyond Z
|
||||
Match:
|
||||
StrCpy $2 $4 ; It 'matches' (either case) so grab the lowercase version
|
||||
NoMatch:
|
||||
StrCpy $1 $1$2 ; Append to the final string
|
||||
Goto Loop
|
||||
Done:
|
||||
StrCpy $0 $1 ; Return the final string
|
||||
Pop $4
|
||||
Pop $3
|
||||
Pop $2
|
||||
Pop $1
|
||||
Exch $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrLowerCase_Call ResultVar String
|
||||
|
||||
!echo `$ {StrLowerCase} "${ResultVar}" "${String}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
|
||||
Call StrLower
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrRep
|
||||
|
||||
!ifndef FUNCTION_STRING_StrRep
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nReplace String Function - 2002-2004 Hendri Adriaens$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrRep
|
||||
!undef StrRep
|
||||
!define StrRep "!insertmacro FUNCTION_STRING_StrRep_Call"
|
||||
|
||||
Function StrReplace
|
||||
Exch $0 ;this will replace wrong characters
|
||||
Exch
|
||||
Exch $1 ;needs to be replaced
|
||||
Exch
|
||||
Exch 2
|
||||
Exch $2 ;the orginal string
|
||||
Push $3 ;counter
|
||||
Push $4 ;temp character
|
||||
Push $5 ;temp string
|
||||
Push $6 ;length of string that need to be replaced
|
||||
Push $7 ;length of string that will replace
|
||||
Push $R0 ;tempstring
|
||||
Push $R1 ;tempstring
|
||||
Push $R2 ;tempstring
|
||||
StrCpy $3 "-1"
|
||||
StrCpy $5 ""
|
||||
StrLen $6 $1
|
||||
StrLen $7 $0
|
||||
Loop:
|
||||
IntOp $3 $3 + 1
|
||||
StrCpy $4 $2 $6 $3
|
||||
StrCmp $4 "" ExitLoop
|
||||
StrCmp $4 $1 Replace
|
||||
Goto Loop
|
||||
Replace:
|
||||
StrCpy $R0 $2 $3
|
||||
IntOp $R2 $3 + $6
|
||||
StrCpy $R1 $2 "" $R2
|
||||
StrCpy $2 $R0$0$R1
|
||||
IntOp $3 $3 + $7
|
||||
Goto Loop
|
||||
ExitLoop:
|
||||
StrCpy $0 $2
|
||||
Pop $R2
|
||||
Pop $R1
|
||||
Pop $R0
|
||||
Pop $7
|
||||
Pop $6
|
||||
Pop $5
|
||||
Pop $4
|
||||
Pop $3
|
||||
Pop $2
|
||||
Pop $1
|
||||
Exch $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrRep_Call ResultVar String StringToReplaceFor StringToBeReplacedWith
|
||||
|
||||
!echo `$ {StrRep} "${ResultVar}" "${String}" "${StringToReplaceFor}" "${StringToBeReplacedWith}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
Push `${StringToReplaceFor}`
|
||||
Push `${StringToBeReplacedWith}`
|
||||
|
||||
Call StrReplace
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrTrimNewLines
|
||||
|
||||
!ifndef FUNCTION_STRING_StrTrimNewLines
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nTrim New Lines Function - 2003-2004 Ximon Eighteen$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrTrimNewLines
|
||||
!undef StrTrimNewLines
|
||||
!define StrTrimNewLines "!insertmacro FUNCTION_STRING_StrTrimNewLines_Call"
|
||||
|
||||
Function TrimNewlines
|
||||
Exch $R0
|
||||
Push $R1
|
||||
Push $R2
|
||||
StrCpy $R1 0
|
||||
|
||||
loop:
|
||||
IntOp $R1 $R1 - 1
|
||||
StrCpy $R2 $R0 1 $R1
|
||||
StrCmp $R2 "$\r" loop
|
||||
StrCmp $R2 "$\n" loop
|
||||
|
||||
IntOp $R1 $R1 + 1
|
||||
IntCmp $R1 0 no_trim_needed
|
||||
StrCpy $R0 $R0 $R1
|
||||
|
||||
no_trim_needed:
|
||||
Pop $R2
|
||||
Pop $R1
|
||||
Exch $R0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrTrimNewLines_Call ResultVar String
|
||||
|
||||
!echo `$ {StrTrimNewLines} "${ResultVar}" "${String}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
|
||||
Call TrimNewLines
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrNSISToIO
|
||||
|
||||
!ifndef FUNCTION_STRING_StrNSISToIO
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nNSIS -> Install Options String Convertion Function - 2003-2004 Amir Szekely, Joost Verburg and Dave Laundon$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrNSISToIO
|
||||
!undef StrNSISToIO
|
||||
!define StrNSISToIO "!insertmacro FUNCTION_STRING_StrNSISToIO_Call"
|
||||
|
||||
Function Nsis2Io
|
||||
Exch $0 ; The source
|
||||
Push $1 ; The output
|
||||
Push $2 ; Temporary char
|
||||
StrCpy $1 "" ; Initialise the output
|
||||
loop:
|
||||
StrCpy $2 $0 1 ; Get the next source char
|
||||
StrCmp $2 "" done ; Abort when none left
|
||||
StrCpy $0 $0 "" 1 ; Remove it from the source
|
||||
StrCmp $2 "\" "" +3 ; Back-slash?
|
||||
StrCpy $1 "$1\\"
|
||||
Goto loop
|
||||
StrCmp $2 "$\r" "" +3 ; Carriage return?
|
||||
StrCpy $1 "$1\r"
|
||||
Goto loop
|
||||
StrCmp $2 "$\n" "" +3 ; Line feed?
|
||||
StrCpy $1 "$1\n"
|
||||
Goto loop
|
||||
StrCmp $2 "$\t" "" +3 ; Tab?
|
||||
StrCpy $1 "$1\t"
|
||||
Goto loop
|
||||
StrCpy $1 "$1$2" ; Anything else
|
||||
Goto loop
|
||||
done:
|
||||
StrCpy $0 $1
|
||||
Pop $2
|
||||
Pop $1
|
||||
Exch $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrNSISToIO_Call ResultVar String
|
||||
|
||||
!echo `$ {StrNSISToIO} "${ResultVar}" "${String}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
|
||||
Call NSIS2IO
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrIOToNSIS
|
||||
|
||||
!ifndef FUNCTION_STRING_StrIOToNSIS
|
||||
|
||||
!echo "$\r$\n----------------------------------------------------------------------$\r$\nInstall Options -> NSIS String Convertion Function - 2003-2004 Amir Szekely, Joost Verburg and Dave Laundon$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
|
||||
|
||||
!define FUNCTION_STRING_StrIOToNSIS
|
||||
!undef StrIOToNSIS
|
||||
!define StrIOToNSIS "!insertmacro FUNCTION_STRING_StrIOToNSIS_Call"
|
||||
|
||||
Function Io2Nsis
|
||||
Exch $0 ; The source
|
||||
Push $1 ; The output
|
||||
Push $2 ; Temporary char
|
||||
StrCpy $1 "" ; Initialise the output
|
||||
loop:
|
||||
StrCpy $2 $0 1 ; Get the next source char
|
||||
StrCmp $2 "" done ; Abort when none left
|
||||
StrCpy $0 $0 "" 1 ; Remove it from the source
|
||||
StrCmp $2 "\" +3 ; Escape character?
|
||||
StrCpy $1 "$1$2" ; If not just output
|
||||
Goto loop
|
||||
StrCpy $2 $0 1 ; Get the next source char
|
||||
StrCpy $0 $0 "" 1 ; Remove it from the source
|
||||
StrCmp $2 "\" "" +3 ; Back-slash?
|
||||
StrCpy $1 "$1\"
|
||||
Goto loop
|
||||
StrCmp $2 "r" "" +3 ; Carriage return?
|
||||
StrCpy $1 "$1$\r"
|
||||
Goto loop
|
||||
StrCmp $2 "n" "" +3 ; Line feed?
|
||||
StrCpy $1 "$1$\n"
|
||||
Goto loop
|
||||
StrCmp $2 "t" "" +3 ; Tab?
|
||||
StrCpy $1 "$1$\t"
|
||||
Goto loop
|
||||
StrCpy $1 "$1$2" ; Anything else (should never get here)
|
||||
Goto loop
|
||||
done:
|
||||
StrCpy $0 $1
|
||||
Pop $2
|
||||
Pop $1
|
||||
Exch $0
|
||||
FunctionEnd
|
||||
|
||||
!endif
|
||||
|
||||
!macroend
|
||||
|
||||
!macro FUNCTION_STRING_StrIOToNSIS_Call ResultVar String
|
||||
|
||||
!echo `$ {StrIOToNSIS} "${ResultVar}" "${String}"$\r$\n`
|
||||
|
||||
Push `${String}`
|
||||
|
||||
Call IO2NSIS
|
||||
|
||||
Pop `${ResultVar}`
|
||||
|
||||
!macroend
|
||||
|
||||
!ifndef MUI_VERBOSE
|
||||
!define MUI_VERBOSE 4
|
||||
!endif
|
551
Include/StrFunc.txt
Normal file
551
Include/StrFunc.txt
Normal file
|
@ -0,0 +1,551 @@
|
|||
String Functions Header File Readme
|
||||
-----------------------------------
|
||||
|
||||
String Functions Header File contains a set of good string manipulation
|
||||
functions in a much simpler way to include and call in NSIS scripts.
|
||||
|
||||
How to use
|
||||
----------
|
||||
|
||||
Syntax
|
||||
|
||||
Parameters are specified in this format: required (option1 | option2)
|
||||
[optional]
|
||||
|
||||
The stars in commands title (*****) are the function usefullness in my
|
||||
opinion. 5 stars (*****) the function is much useful.
|
||||
|
||||
If you want a certain value (e.g. a text) to be language-specific, set a
|
||||
language string (using LangString) and define $(STRINGNAME) as value.
|
||||
|
||||
If you want to add ` to a string, you should always escape it using $\`
|
||||
because the header file macro functions use ` to separate parameters.
|
||||
|
||||
1. Include Header file
|
||||
----------------------
|
||||
|
||||
!include "StrFunc.nsh"
|
||||
|
||||
StrFunc.nsh have to be in the Include directory, so you don't have to
|
||||
specify a path.
|
||||
|
||||
You have to put this command before any command used in this header file.
|
||||
|
||||
2. Commands
|
||||
-----------
|
||||
|
||||
IMPORTANT: Every command in this header file have to be called first
|
||||
before, out of sections and functions and without parameters. Example:
|
||||
|
||||
!include "StrFunc.nsh"
|
||||
|
||||
${StrStr}
|
||||
|
||||
Section
|
||||
|
||||
${StrStr} $0 "OK! Now what?" "wh"
|
||||
|
||||
SectionEnd
|
||||
|
||||
=========================================================================
|
||||
***** ${StrStr} ResultVar String StrToSearchFor
|
||||
=========================================================================
|
||||
Searches for "StrToSearchFor" in "String".
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String where to search "StrToSearchFor".
|
||||
|
||||
StrToSearchFor
|
||||
String to search in "String".
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"StrToSearchFor" + the string after where it was found in "String".
|
||||
|
||||
Example:
|
||||
|
||||
${StrStr} $0 "This is just an example" "just"
|
||||
|
||||
$0 = "just an example"
|
||||
|
||||
=========================================================================
|
||||
** ${StrLoc} ResultVar String StrToSearchFor Direction
|
||||
=========================================================================
|
||||
Searches for "StrToSearchFor" in "String" and returns its location,
|
||||
according to "Direction"
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String where to search "StrToSearchFor".
|
||||
|
||||
StrToSearchFor
|
||||
String to search in "String".
|
||||
|
||||
Direction
|
||||
Direction where the counter goes to. (Anything except < = To Right,
|
||||
< = To Left).
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
Where "StrToSearchFor" is going to "direction".
|
||||
|
||||
Example:
|
||||
|
||||
${StrLoc} $0 "This is just an example" "just" "<"
|
||||
|
||||
$0 = "11"
|
||||
|
||||
=========================================================================
|
||||
***** ${StrStrAdv} ResultVar String StrToSearchFor SearchDirection(>|<)
|
||||
ResultStrDirection(>|<) DisplayStrToSearch(1|0) Loops
|
||||
=========================================================================
|
||||
Searches for "StrToSearchFor" in "String" in the direction specified by
|
||||
"SearchDirection" and looping "Loops" times.
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String where to search "StrToSearchFor".
|
||||
|
||||
StrToSearchFor
|
||||
String to search in "String".
|
||||
|
||||
SearchDirection (>|<)
|
||||
Where do you want to direct the search. Default is ">" (to right).
|
||||
(< = To left, > = To right)
|
||||
|
||||
ResultStrDirection (>|<)
|
||||
Where the result string will be based on in relation of "StrToSearchFor"
|
||||
position. Default is ">" (to right) (< = To left, > = To right)
|
||||
|
||||
DisplayStrToSearch (1|0)
|
||||
Display "StrToSearchFor" in the result. Default is "1" (True). (1 = True,
|
||||
0 = False)
|
||||
|
||||
Loops
|
||||
Number of times the code will search "StrToSearchFor" in "String" not
|
||||
including the original execution. Default is "0" (1 code execution).
|
||||
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"StrToSearchFor" if "DisplayStrToSearch" is 1 + the result string the
|
||||
direction "ResultStrDirection" of the "StrToSearchFor".
|
||||
|
||||
Result with Errors:
|
||||
|
||||
When "StrToSearchFor" was not found, will return an empty string.
|
||||
|
||||
When you put nothing in "StrToSearchFor", will return "String" and set
|
||||
error flag.
|
||||
|
||||
When you put nothing in "String", will return an empty string and set
|
||||
error flag.
|
||||
|
||||
Example:
|
||||
|
||||
${StrStrAdv} $0 "This is just an example" "is" "<" "<" "1" "1"
|
||||
|
||||
$0 = "This"
|
||||
|
||||
=========================================================================
|
||||
***** ${StrRep} ResultVar String StringToReplace ReplacementString
|
||||
=========================================================================
|
||||
Searches for all "StringToReplace" in "String" replacing those with
|
||||
"ReplacementString".
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String where to search "StringToReplaceIn".
|
||||
|
||||
StringToReplace
|
||||
String to search for in "String".
|
||||
|
||||
ReplacementString
|
||||
String to replace "StringToReplace" when it is found in "String".
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"String" with all occurences of "StringToReplace" replaced with
|
||||
"ReplacementString".
|
||||
|
||||
Example:
|
||||
|
||||
${StrRep} $0 "This is just an example" "an" "one"
|
||||
|
||||
$0 = "This is just one example"
|
||||
|
||||
|
||||
=========================================================================
|
||||
**** ${StrClbSet} String
|
||||
=========================================================================
|
||||
Copy "String" to the clipboard.
|
||||
|
||||
Parameters:
|
||||
|
||||
String
|
||||
String to put in the clipboard.
|
||||
|
||||
|
||||
=========================================================================
|
||||
**** ${StrClbGet} ResultVar
|
||||
=========================================================================
|
||||
Get a string from the clipboard and return it to "ResultVar".
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
The string found in clipboard.
|
||||
|
||||
|
||||
=========================================================================
|
||||
***** ${StrTok} ResultVar StrToTokenize Separators ResultPart
|
||||
SkipEmptyParts(1|0)
|
||||
=========================================================================
|
||||
Returns the part "ResultPart" between two "Separators" inside
|
||||
"StrToTokenize".
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
StrToTokenizing
|
||||
String where to search for "Separators".
|
||||
|
||||
Separators
|
||||
Characters to find in "StrToTokenizing".
|
||||
|
||||
ResultPart
|
||||
The part want to be found in "StrToTokenize" between two "Separators".
|
||||
Can be any number, starting at 1, and "L" that is the last part.
|
||||
Default is L.
|
||||
|
||||
SkipEmptyParts(1|0)
|
||||
Skips empty string parts between two "Separators". Default is 1 (True).
|
||||
(1 = True, 0 = False)
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"StrToTokenize" part "Part" between two "Separators".
|
||||
|
||||
Examples:
|
||||
|
||||
1) ${StrTok} $0 "This is, or is not, just an example" " ," "5" "1"
|
||||
|
||||
$0 = "not"
|
||||
|
||||
2) ${StrTok} $0 "This is, or is not, just an example" " ," "5" "0"
|
||||
|
||||
$0 = "is"
|
||||
|
||||
=========================================================================
|
||||
*** ${StrUpperCase} ResultVar String
|
||||
=========================================================================
|
||||
Converts "String" to upper case.
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String to convert to upper case.
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"String" in upper case.
|
||||
|
||||
Example:
|
||||
|
||||
${StrUpperCase} $0 "oh man!"
|
||||
|
||||
$0 = "OH MAN!"
|
||||
|
||||
=========================================================================
|
||||
*** ${StrLowerCase} ResultVar String
|
||||
=========================================================================
|
||||
|
||||
Converts "String" to lower case.
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String to convert to lower case.
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"String" in lower case.
|
||||
|
||||
Example:
|
||||
|
||||
${StrUpperCase} $0 "OH MAN!"
|
||||
|
||||
$0 = "oh man!"
|
||||
|
||||
=========================================================================
|
||||
* ${StrTrimNewLines} ResultVar String
|
||||
=========================================================================
|
||||
Deletes unnecessary new lines at end of "String".
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String where to search unnecessary new lines at end of "String".
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"String" with unnecessary end new lines removed.
|
||||
|
||||
Example:
|
||||
|
||||
${StrTrimNewLines} $0 "$\r$\nThis is just an example$\r$\n$\r$\n"
|
||||
|
||||
$0 = "$\r$\nThis is just an example"
|
||||
|
||||
=========================================================================
|
||||
***** ${StrNSISToIO} ResultVar String
|
||||
=========================================================================
|
||||
Convert "String" from NSIS to be supported by Install Options plugin.
|
||||
Escape, back-slash, carriage return, line feed and tab characters are
|
||||
converted.
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String to convert to be supportable for Install Options plugin.
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"String" supportable for Install Options plugin.
|
||||
|
||||
Example:
|
||||
|
||||
${StrNSISToIO} $0 "$\r$\n$\t\This is just an example\"
|
||||
|
||||
$0 = "\r\n\t\\This is just an example\\"
|
||||
|
||||
=========================================================================
|
||||
***** ${StrIOToNSIS} ResultVar String
|
||||
=========================================================================
|
||||
Convert "String" from Install Options plugin to be supported by NSIS.
|
||||
Escape, back-slash, carriage return, line feed and tab characters are
|
||||
converted.
|
||||
|
||||
Parameters:
|
||||
|
||||
ResultVar
|
||||
Destination where result is returned.
|
||||
|
||||
String
|
||||
String to convert to be supportable for NSIS.
|
||||
|
||||
Result Value -> ResultVar:
|
||||
|
||||
"String" supportable for NSIS.
|
||||
|
||||
Example:
|
||||
|
||||
${StrIOToNSIS} $0 "\r\n\t\\This is just an example\\"
|
||||
|
||||
$0 = "$\r$\n$\t\This is just an example\"
|
||||
|
||||
Comments about functions included and not included
|
||||
--------------------------------------------------
|
||||
|
||||
12 functions have been included
|
||||
7 were included was it was in Archive
|
||||
4 were not included in Archive
|
||||
AdvStrTok
|
||||
NSISToIO
|
||||
IOToNSIS
|
||||
StrLoc
|
||||
1 was been changed from original version
|
||||
StrClbGet
|
||||
|
||||
11 functions were not been included
|
||||
7 were not included because of better functions
|
||||
5 were not included because of AdvStrTok (called here as StrTok)
|
||||
First String Part Function
|
||||
Save on Variables Function
|
||||
Sort Strings (1, and 2) Functions
|
||||
StrTok Function
|
||||
1 was not included because of NSISToIO and IOToNSIS
|
||||
Convert / to // in Paths Function
|
||||
1 was not included because of original String Replace Function (called
|
||||
here as StrRep)
|
||||
Another String Replace Function
|
||||
2 were not included because isn't usefull anymore
|
||||
Slash <-> Backslash Converter Function
|
||||
Trim Function
|
||||
1 was not included because of bugs
|
||||
Number to String Converter Function
|
||||
1 removed by kichik
|
||||
StrSort
|
||||
|
||||
Comments
|
||||
------------------------------------------------------------
|
||||
|
||||
Advanced Token String Function
|
||||
|
||||
New function not published in Archive, much better than original StrTok,
|
||||
going to replace several functions with just one. The principal idea was
|
||||
based on "Save On Variables" by Afrow UK.
|
||||
|
||||
Another String Replace Function
|
||||
|
||||
Another doesn't mean better and simpler than the original version.
|
||||
(Don't confuse the original StrRep that is in this header file with this
|
||||
one)
|
||||
|
||||
Convert / to // in Paths Function
|
||||
|
||||
StrNSISToIO and StrIOToNSIS are better.
|
||||
|
||||
Copy from Clipboard Function
|
||||
|
||||
Changed just the function name to the correct "CopyFromClipboard".
|
||||
|
||||
|
||||
First String Part Function
|
||||
|
||||
AdvStrTok (called here as StrTok) is better.
|
||||
|
||||
|
||||
NSIS <-> Install Options String Convertor Functions
|
||||
|
||||
Included from Install Options Readme.
|
||||
|
||||
|
||||
Number to String Converter Function
|
||||
|
||||
Have a serious bug when input is 5 chars long. Need to be remade to a
|
||||
simpler one.
|
||||
|
||||
Save on Variables Function
|
||||
|
||||
AdvStrTok (called here as StrTok) is better.
|
||||
|
||||
|
||||
Slash <-> Backslash Converter Function
|
||||
|
||||
Will convert "http://www.site.com\" to "http:\\www.site.com/", not
|
||||
really useful for anyone.
|
||||
|
||||
|
||||
Split String Function
|
||||
|
||||
AdvStrTok (called here as StrTok) is better.
|
||||
|
||||
|
||||
StrTok Function
|
||||
|
||||
AdvStrTok (called here as StrTok) is better.
|
||||
|
||||
|
||||
Trim Function
|
||||
|
||||
The real purpose of this function was to remove spaces from directory
|
||||
paths, and now with the NSIS command GetFullPathName this is not useful
|
||||
anymore.
|
||||
|
||||
|
||||
Version History
|
||||
---------------
|
||||
|
||||
1.02 (kichik) - 02/07/2004
|
||||
|
||||
- Documentation fixes.
|
||||
- Fixed StrLoc.
|
||||
- Remove StrSort as it was giving too much trouble and it looks like it's
|
||||
built for a very specific, nongeneric purpose.
|
||||
|
||||
1.01 - 02/06/2004
|
||||
|
||||
- Fixed Documentation about StrSort and StrTok.
|
||||
- Fixed StrTok default value for the string part. Now it's "L".
|
||||
- Fixed StrStrAdv fixed wrong search when had a combination of same
|
||||
substrings one after another in a string.
|
||||
- Fixed StrLoc, when a string isn't found, don't return any value at all.
|
||||
|
||||
1.00 - 02/01/2004
|
||||
|
||||
- Added documentation.
|
||||
- Renamed header file to "StrFunc.nsh".
|
||||
- Added 1 function, StrLoc.
|
||||
- Modified StrStrAdv, removed some lines.
|
||||
- Fixed StrTok, 2 simple numbers made it loop everytime.
|
||||
- Fixed some small issues in the header file.
|
||||
|
||||
0.02 - 01/24/2004
|
||||
|
||||
- Completed StrFunc.nsh file. Need some tests and the readme.
|
||||
|
||||
0.01 - 01/22/2004
|
||||
|
||||
- First version to test ideas...
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
Made by Diego Pedroso (aka deguix).
|
||||
|
||||
Functions Credits
|
||||
-----------------
|
||||
|
||||
- Advanced Search in String, Advanced Token String, String Localizator
|
||||
made by Diego Pedroso.
|
||||
- Copy to/from clipboard made by Nik Medved.
|
||||
- Sort String 3 made by "Afrow UK".
|
||||
- StrUpper made by Dave Laundon.
|
||||
- StrReplace made by Hendri Adriaens.
|
||||
- Search in a string, Trim newlines made by Ximon Eighteen.
|
||||
- NSISToIO and IOToNSIS made by Amir Szekely, Joost Verburg and Dave Laundon.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
This header file is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this header file.
|
||||
|
||||
Permission is granted to anyone to use this header file for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this header file must not be misrepresented;
|
||||
you must not claim that you wrote the original header file.
|
||||
If you use this header file in a product, an acknowledgment in the
|
||||
product documentation would be appreciated but is not required.
|
||||
2. Altered versions must be plainly marked as such,
|
||||
and must not be misrepresented as being the original header file.
|
||||
3. This notice may not be removed or altered from any distribution.
|
Loading…
Add table
Add a link
Reference in a new issue