]> git.evergreen-ils.org Git - working/Hatch.git/blob - installer/windows/StrRep.nsh
LP#1733692 Bumping Hatch versions to 0.1.3
[working/Hatch.git] / installer / windows / StrRep.nsh
1 ;-------------------------------------
2 ;   Supplemental Function
3 ;   StrRep - String Replace v4.0
4 ;   http://nsis.sourceforge.net/StrRep
5
6 !define StrRep "!insertmacro StrRep"
7 !macro StrRep output string old new
8     Push `${string}`
9     Push `${old}`
10     Push `${new}`
11     !ifdef __UNINSTALL__
12         Call un.StrRep
13     !else
14         Call StrRep
15     !endif
16     Pop ${output}
17 !macroend
18  
19 !macro Func_StrRep un
20     Function ${un}StrRep
21         Exch $R2 ;new
22         Exch 1
23         Exch $R1 ;old
24         Exch 2
25         Exch $R0 ;string
26         Push $R3
27         Push $R4
28         Push $R5
29         Push $R6
30         Push $R7
31         Push $R8
32         Push $R9
33  
34         StrCpy $R3 0
35         StrLen $R4 $R1
36         StrLen $R6 $R0
37         StrLen $R9 $R2
38         loop:
39             StrCpy $R5 $R0 $R4 $R3
40             StrCmp $R5 $R1 found
41             StrCmp $R3 $R6 done
42             IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character
43             Goto loop
44         found:
45             StrCpy $R5 $R0 $R3
46             IntOp $R8 $R3 + $R4
47             StrCpy $R7 $R0 "" $R8
48             StrCpy $R0 $R5$R2$R7
49             StrLen $R6 $R0
50             IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string
51             Goto loop
52         done:
53  
54         Pop $R9
55         Pop $R8
56         Pop $R7
57         Pop $R6
58         Pop $R5
59         Pop $R4
60         Pop $R3
61         Push $R0
62         Push $R1
63         Pop $R0
64         Pop $R1
65         Pop $R0
66         Pop $R2
67         Exch $R1
68     FunctionEnd
69 !macroend
70 !insertmacro Func_StrRep ""