-
Notifications
You must be signed in to change notification settings - Fork 13
/
IndexOf.nsh
113 lines (94 loc) · 2 KB
/
IndexOf.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
!ifndef INDEX_OF_NSH
!define INDEX_OF_NSH
; IndexOf & RIndexOf: Find index of character in string
; -----------------------------------------------------
;
; These two functions find the index of a character in a string from left (IndexOf)
; or from the right (RIndexOf). For the default behaviour of StrCpy, IndexOf returns
; the character index as zero-based, whereas RIndexOf does not (starts at 1 from
; the end).
;
; Usage:
; ------
; ${IndexOf} $R0 "blah" "a" ; $R0 = 2
; ${RIndexOf} $R0 "blah" "b" ; $R0 = 4
;
; Written by Stu
!if 1 = 2 ;I don't need this function, the installer doesn't currently use it. 2007-01-20
Function IndexOf
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
StrCpy $R3 $R0
StrCpy $R0 -1
IntOp $R0 $R0 + 1
StrCpy $R2 $R3 1 $R0
StrCmp $R2 "" +2
StrCmp $R2 $R1 +2 -3
StrCpy $R0 -1
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!macro IndexOf Var Str Char
Push "${Char}"
Push "${Str}"
Call IndexOf
Pop "${Var}"
!macroend
!define IndexOf "!insertmacro IndexOf"
!endif
Function RIndexOf
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
StrCpy $R3 $R0
StrCpy $R0 0
IntOp $R0 $R0 + 1
StrCpy $R2 $R3 1 -$R0
StrCmp $R2 "" +2
StrCmp $R2 $R1 +2 -3
StrCpy $R0 -1
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!macro RIndexOf Var Str Char
Push "${Char}"
Push "${Str}"
Call RIndexOf
Pop "${Var}"
!macroend
!define RIndexOf "!insertmacro RIndexOf"
Function un.RIndexOf
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
StrCpy $R3 $R0
StrCpy $R0 0
IntOp $R0 $R0 + 1
StrCpy $R2 $R3 1 -$R0
StrCmp $R2 "" +2
StrCmp $R2 $R1 +2 -3
StrCpy $R0 -1
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!macro un.RIndexOf Var Str Char
Push "${Char}"
Push "${Str}"
Call un.RIndexOf
Pop "${Var}"
!macroend
!define un.RIndexOf "!insertmacro un.RIndexOf"
!endif