Debian Codegraph @

Include/StrFunc.nsh

raw
1 /*
2 o-----------------------------------------------------------------------------o
3 |String Functions Header File 1.10 |
4 (-----------------------------------------------------------------------------)
5 | By deguix / A Header file for NSIS 2.01 |
6 | <[email protected]> -------------------------------|
7 | |
8 | This header file contains NSIS functions for string manipulation. |
9 | ---------|
10 | !include "StrFunc.nsh" / Example |
11 | ${Using:StrFunc} StrRep -----------|
12 | |
13 | Section |
14 | ${StrRep} $0 "Hello world!" "world" "everyone" |
15 | MessageBox mb_ok $0 |
16 | SectionEnd |
17 | |
18 o-----------------------------------------------------------------------------o
19 */
20
21 !verbose push 3
22 !define /IfNDef STRFUNC_VERBOSITY 3
23 !define /IfNDef _STRFUNC_VERBOSITY ${STRFUNC_VERBOSITY}
24 !define /IfNDef _STRFUNC_CREDITVERBOSITY ${STRFUNC_VERBOSITY}
25 !undef STRFUNC_VERBOSITY
26 !verbose ${_STRFUNC_VERBOSITY}
27
28 !include LogicLib.nsh
29
30 !ifndef STRFUNC
31
32 !define /IfNDef FALSE 0
33 !define /IfNDef TRUE 1
34
35 ;Header File Identification
36
37 !define STRFUNC `String Functions Header File`
38 ;define STRFUNC_SHORT `StrFunc`
39 !define STRFUNC_CREDITS `2004 Diego Pedroso`
40
41 ;Header File Version
42
43 !define STRFUNC_VERMAJ 1
44 !define STRFUNC_VERMED 10
45 ;!define STRFUNC_VERMIN 0
46 ;!define STRFUNC_VERBLD 0
47
48 !define STRFUNC_VER `${STRFUNC_VERMAJ}.${STRFUNC_VERMED}`
49
50 ;Header File Init Message Prefix and Postfix
51
52 !define STRFUNC_INITMSGPRE `----------------------------------------------------------------------$\r$\n`
53 !define STRFUNC_INITMSGPOST `$\r$\n----------------------------------------------------------------------$\r$\n`
54
55 ;Header File Init Message
56
57 !verbose push ${_STRFUNC_CREDITVERBOSITY}
58 !echo `${STRFUNC_INITMSGPRE}NSIS ${STRFUNC} ${STRFUNC_VER} - Copyright ${STRFUNC_CREDITS}${STRFUNC_INITMSGPOST}`
59 !verbose pop
60
61 ;Header File Function Macros
62
63 !ifdef STRFUNC_USECALLARTIFICIALFUNCTION
64 !include Util.nsh
65 !endif
66
67 !define "Using:StrFunc" `!insertmacro STRFUNC_USING `
68 !macro STRFUNC_USING Name
69 !if "${STRFUNC_VERBOSITY}" > 4
70 !verbose push 4
71 !endif
72 !ifndef ${Name}_INCLUDED
73 !ifndef STRFUNC_USECALLARTIFICIALFUNCTION
74 ${${Name}} ; Invoke !insertmacro STRFUNC_MAKEFUNC
75 !endif
76 !endif
77 !if "${STRFUNC_VERBOSITY}" > 4
78 !verbose pop
79 !endif
80 !macroend
81
82 !macro STRFUNC_FUNCLIST_INSERT Name
83 !ifdef StrFunc_List
84 !define /ReDef StrFunc_List `${StrFunc_List}|${Name}`
85 !else
86 !define StrFunc_List `${Name}`
87 !endif
88 !macroend
89
90 !macro STRFUNC_DEFFUNC Name List TypeList
91 !insertmacro STRFUNC_FUNCLIST_INSERT ${Name}
92 !define `${Name}_List` `${List}`
93 !define `${Name}_TypeList` `${TypeList}`
94 !ifdef STRFUNC_USECALLARTIFICIALFUNCTION
95 !define `${Name}` `!insertmacro STRFUNC_CALL_${Name} "" `
96 !define `Un${Name}` `!insertmacro STRFUNC_CALL_${Name} Un `
97 !else
98 !define `${Name}` `!insertmacro STRFUNC_MAKEFUNC ${Name} "" #`
99 !define `Un${Name}` `!insertmacro STRFUNC_MAKEFUNC ${Name} Un #`
100 !endif
101 !macroend
102
103 !macro STRFUNC_MAKEFUNC basename un
104 !ifndef __GLOBAL__
105 !error "You forgot ${U+24}{Using:StrFunc} ${un}${basename}"
106 !endif
107 !insertmacro STRFUNC_MAKEFUNC_${basename}
108 !macroend
109
110 !macro STRFUNC_BEGINFUNC basename un credits
111 !verbose push ${_STRFUNC_CREDITVERBOSITY}
112 !echo `${U+24}{${un}${basename}} - Copyright ${credits}`
113 !verbose pop
114 !define /IfNDef ${un}${basename}_INCLUDED
115 !ifndef STRFUNC_USECALLARTIFICIALFUNCTION
116 !define /ReDef ${un}${basename} `!insertmacro STRFUNC_CALL_${basename} "${un}" `
117 !if "${un}" != ""
118 Function un.${basename}
119 !else
120 Function ${basename}
121 !endif
122 !endif
123 !macroend
124 !macro STRFUNC_ENDFUNC
125 !ifndef STRFUNC_USECALLARTIFICIALFUNCTION
126 FunctionEnd
127 !endif
128 !macroend
129
130 !macro STRFUNC_CALL basename un
131 !ifdef STRFUNC_USECALLARTIFICIALFUNCTION
132 ${CallArtificialFunction} STRFUNC_MAKEFUNC_${basename}
133 !else
134 !if "${un}" != ""
135 Call un.${basename}
136 !else
137 Call ${basename}
138 !endif
139 !endif
140 !macroend
141
142
143 ############################################################################
144 # StrCase
145 !insertmacro STRFUNC_DEFFUNC StrCase `ResultVar|String|Type` `Output|Text|Option U L T S <>`
146
147 !macro STRFUNC_CALL_StrCase un ResultVar String Type
148 !verbose push ${STRFUNC_VERBOSITY}
149 !echo `${U+24}{${un}StrCase} "${ResultVar}" "${String}" "${Type}"`
150 !verbose 2
151 Push `${String}`
152 Push `${Type}`
153 !insertmacro STRFUNC_CALL StrCase "${un}"
154 Pop ${ResultVar}
155 !verbose pop
156 !macroend
157
158 !macro STRFUNC_MAKEFUNC_StrCase
159 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Dave Laundon`
160 /*After this point:
161 ------------------------------------------
162 $0 = String (input)
163 $1 = Type (input)
164 $2 = StrLength (temp)
165 $3 = StartChar (temp)
166 $4 = EndChar (temp)
167 $5 = ResultStr (temp)
168 $6 = CurrentChar (temp)
169 $7 = LastChar (temp)
170 $8 = Temp (temp)*/
171
172 ;Get input from user
173 Exch $1
174 Exch
175 Exch $0
176 Exch
177 Push $2
178 Push $3
179 Push $4
180 Push $5
181 Push $6
182 Push $7
183 Push $8
184
185 ;Initialize variables
186 StrCpy $2 ""
187 StrCpy $3 ""
188 StrCpy $4 ""
189 StrCpy $5 ""
190 StrCpy $6 ""
191 StrCpy $7 ""
192 StrCpy $8 ""
193
194 ;Upper and lower cases are simple to use
195 ${If} $1 == "U"
196
197 ;Upper Case System:
198 ;------------------
199 ; Convert all characters to upper case.
200
201 System::Call "User32::CharUpper(t r0 r5)i"
202 Goto StrCase_End
203 ${ElseIf} $1 == "L"
204
205 ;Lower Case System:
206 ;------------------
207 ; Convert all characters to lower case.
208
209 System::Call "User32::CharLower(t r0 r5)i"
210 Goto StrCase_End
211 ${EndIf}
212
213 ;For the rest of cases:
214 ;Get "String" length
215 StrLen $2 $0
216
217 ;Make a loop until the end of "String"
218 ${For} $3 0 $2
219 ;Add 1 to "EndChar" counter also
220 IntOp $4 $3 + 1
221
222 # Step 1: Detect one character at a time
223
224 ;Remove characters before "StartChar" except when
225 ;"StartChar" is the first character of "String"
226 ${If} $3 <> 0
227 StrCpy $6 $0 `` $3
228 ${EndIf}
229
230 ;Remove characters after "EndChar" except when
231 ;"EndChar" is the last character of "String"
232 ${If} $4 <> $2
233 ${If} $3 = 0
234 StrCpy $6 $0 1
235 ${Else}
236 StrCpy $6 $6 1
237 ${EndIf}
238 ${EndIf}
239
240 # Step 2: Convert to the advanced case user chose:
241
242 ${If} $1 == "T"
243
244 ;Title Case System:
245 ;------------------
246 ; Convert all characters after a non-alphabetic character to upper case.
247 ; Else convert to lower case.
248
249 ;Use "IsCharAlpha" for the job
250 System::Call "*(&t1 r7) p .r8"
251 System::Call "*$8(&i1 .r7)"
252 System::Free $8
253 System::Call "user32::IsCharAlpha(i r7) i .r8"
254
255 ;Verify "IsCharAlpha" result and convert the character
256 ${If} $8 = 0
257 System::Call "User32::CharUpper(t r6 r6)i"
258 ${Else}
259 System::Call "User32::CharLower(t r6 r6)i"
260 ${EndIf}
261 ${ElseIf} $1 == "S"
262
263 ;Sentence Case System:
264 ;------------------
265 ; Convert all characters after a ".", "!" or "?" character to upper case.
266 ; Else convert to lower case. Spaces or tabs after these marks are ignored.
267
268 ;Detect current characters and ignore if necessary
269 ${If} $6 == " "
270 ${OrIf} $6 == "$\t"
271 Goto IgnoreLetter
272 ${EndIf}
273
274 ;Detect last characters and convert
275 ${If} $7 == "."
276 ${OrIf} $7 == "!"
277 ${OrIf} $7 == "?"
278 ${OrIf} $7 == ""
279 System::Call "User32::CharUpper(t r6 r6)i"
280 ${Else}
281 System::Call "User32::CharLower(t r6 r6)i"
282 ${EndIf}
283 ${ElseIf} $1 == "<>"
284
285 ;Switch Case System:
286 ;------------------
287 ; Switch all characters cases to their inverse case.
288
289 ;Use "IsCharUpper" for the job
290 System::Call "*(&t1 r6) p .r8"
291 System::Call "*$8(&i1 .r7)"
292 System::Free $8
293 System::Call "user32::IsCharUpper(i r7) i .r8"
294
295 ;Verify "IsCharUpper" result and convert the character
296 ${If} $8 = 0
297 System::Call "User32::CharUpper(t r6 r6)i"
298 ${Else}
299 System::Call "User32::CharLower(t r6 r6)i"
300 ${EndIf}
301 ${EndIf}
302
303 ;Write the character to "LastChar"
304 StrCpy $7 $6
305
306 IgnoreLetter:
307 ;Add this character to "ResultStr"
308 StrCpy $5 `$5$6`
309 ${Next}
310
311 StrCase_End:
312
313 /*After this point:
314 ------------------------------------------
315 $0 = OutVar (output)*/
316
317 ; Copy "ResultStr" to "OutVar"
318 StrCpy $0 $5
319
320 ;Return output to user
321 Pop $8
322 Pop $7
323 Pop $6
324 Pop $5
325 Pop $4
326 Pop $3
327 Pop $2
328 Pop $1
329 Exch $0
330 !insertmacro STRFUNC_ENDFUNC
331
332 !macroend
333
334 ############################################################################
335 # StrClb
336 !insertmacro STRFUNC_DEFFUNC StrClb `ResultVar|String|Action` `Output|Text|Option > < <>`
337
338 !macro STRFUNC_CALL_StrClb un ResultVar String Action
339 !verbose push ${STRFUNC_VERBOSITY}
340 !echo `${U+24}{${un}StrClb} "${ResultVar}" "${String}" "${Action}"`
341 !verbose 2
342 Push `${String}`
343 Push `${Action}`
344 !insertmacro STRFUNC_CALL StrClb "${un}"
345 Pop ${ResultVar}
346 !verbose pop
347 !macroend
348
349 !macro STRFUNC_MAKEFUNC_StrClb
350 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Nik Medved`
351
352 /*After this point:
353 ------------------------------------------
354 $0 = String (input)
355 $1 = Action (input)
356 $2 = Lock/Unlock (temp)
357 $3 = Temp (temp)
358 $4 = Temp2 (temp)*/
359
360 ;Get input from user
361
362 Exch $1
363 Exch
364 Exch $0
365 Exch
366 Push $2
367 Push $3
368 Push $4
369
370 StrCpy $2 ""
371 StrCpy $3 ""
372 StrCpy $4 ""
373
374 ;Open the clipboard to do the operations the user chose (kichik's fix)
375 System::Call 'user32::OpenClipboard(p $HWNDPARENT)'
376
377 ${If} $1 == ">" ;Set
378
379 ;Step 1: Clear the clipboard
380 System::Call 'user32::EmptyClipboard()'
381
382 ;Step 2: Allocate global heap
383 StrLen $2 $0
384 IntOp $2 $2 + 1
385 !if "${NSIS_CHAR_SIZE}" > 1
386 IntOp $2 $2 * ${NSIS_CHAR_SIZE}
387 !endif
388 System::Call 'kernel32::GlobalAlloc(i 2, i r2) p.r2'
389
390 ;Step 3: Lock the handle
391 System::Call 'kernel32::GlobalLock(p r2) i.r3'
392
393 ;Step 4: Copy the text to locked clipboard buffer
394 System::Call 'kernel32::lstrcpy(p r3, t r0)'
395
396 ;Step 5: Unlock the handle again
397 System::Call 'kernel32::GlobalUnlock(p r2)'
398
399 ;Step 6: Set the information to the clipboard
400 !if "${NSIS_CHAR_SIZE}" > 1
401 System::Call 'user32::SetClipboardData(i 13, p r2)'
402 !else
403 System::Call 'user32::SetClipboardData(i 1, p r2)'
404 !endif
405
406 StrCpy $0 ""
407
408 ${ElseIf} $1 == "<" ;Get
409
410 ;Step 1: Get clipboard data
411 !if "${NSIS_CHAR_SIZE}" > 1
412 System::Call 'user32::GetClipboardData(i 13)p.r2'
413 !else
414 System::Call 'user32::GetClipboardData(i 1)p.r2'
415 !endif
416
417 ;Step 2: Lock and copy data (kichik's fix)
418 System::Call 'kernel32::GlobalLock(p r2) t .r0'
419
420 ;Step 3: Unlock (kichik's fix)
421 System::Call 'kernel32::GlobalUnlock(p r2)'
422
423 ${ElseIf} $1 == "<>" ;Swap
424
425 ;Step 1: Get clipboard data
426 !if "${NSIS_CHAR_SIZE}" > 1
427 System::Call 'user32::GetClipboardData(i 13)p.r2'
428 !else
429 System::Call 'user32::GetClipboardData(i 1)p.r2'
430 !endif
431
432 ;Step 2: Lock and copy data (kichik's fix)
433 System::Call 'kernel32::GlobalLock(p r2) t .r4'
434
435 ;Step 3: Unlock (kichik's fix)
436 System::Call 'kernel32::GlobalUnlock(p r2)'
437
438 ;Step 4: Clear the clipboard
439 System::Call 'user32::EmptyClipboard()'
440
441 ;Step 5: Allocate global heap
442 StrLen $2 $0
443 IntOp $2 $2 + 1
444 !if "${NSIS_CHAR_SIZE}" > 1
445 IntOp $2 $2 * ${NSIS_CHAR_SIZE}
446 !endif
447 System::Call 'kernel32::GlobalAlloc(i 2, i r2) p.r2'
448
449 ;Step 6: Lock the handle
450 System::Call 'kernel32::GlobalLock(p r2) i.r3'
451
452 ;Step 7: Copy the text to locked clipboard buffer
453 System::Call 'kernel32::lstrcpy(p r3, t r0)'
454
455 ;Step 8: Unlock the handle again
456 System::Call 'kernel32::GlobalUnlock(p r2)'
457
458 ;Step 9: Set the information to the clipboard
459 !if "${NSIS_CHAR_SIZE}" > 1
460 System::Call 'user32::SetClipboardData(i 13, p r2)'
461 !else
462 System::Call 'user32::SetClipboardData(i 1, p r2)'
463 !endif
464
465 StrCpy $0 $4
466 ${Else} ;Clear
467
468 ;Step 1: Clear the clipboard
469 System::Call 'user32::EmptyClipboard()'
470
471 StrCpy $0 ""
472 ${EndIf}
473
474 ;Close the clipboard
475 System::Call 'user32::CloseClipboard()'
476
477 /*After this point:
478 ------------------------------------------
479 $0 = OutVar (output)*/
480
481 ;Return result to user
482 Pop $4
483 Pop $3
484 Pop $2
485 Pop $1
486 Exch $0
487 !insertmacro STRFUNC_ENDFUNC
488
489 !macroend
490
491 ############################################################################
492 # StrIOToNSIS
493 !insertmacro STRFUNC_DEFFUNC StrIOToNSIS `ResultVar|String` `Output|Text`
494
495 !macro STRFUNC_CALL_StrIOToNSIS un ResultVar String
496 !verbose push ${STRFUNC_VERBOSITY}
497 !echo `${U+24}{${un}StrIOToNSIS} "${ResultVar}" "${String}"`
498 !verbose 2
499 Push `${String}`
500 !insertmacro STRFUNC_CALL StrIOToNSIS "${un}"
501 Pop ${ResultVar}
502 !verbose pop
503 !macroend
504
505 !macro STRFUNC_MAKEFUNC_StrIOToNSIS
506 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 "bluenet" - Based on functions by Amir Szekely, Joost Verburg, Dave Laundon and Diego Pedroso`
507
508 /*After this point:
509 ------------------------------------------
510 $R0 = String (input/output)
511 $R1 = StartCharPos (temp)
512 $R2 = StrLen (temp)
513 $R3 = TempStr (temp)
514 $R4 = TempRepStr (temp)*/
515
516 ;Get input from user
517 Exch $R0
518 Push $R1
519 Push $R2
520 Push $R3
521 Push $R4
522
523 ;Get "String" length
524 StrLen $R2 $R0
525
526 ;Loop until "String" end is reached
527 ${For} $R1 0 $R2
528 ;Get the next "String" characters
529 StrCpy $R3 $R0 2 $R1
530
531 ;Detect if current character is:
532 ${If} $R3 == "\\" ;Back-slash
533 StrCpy $R4 "\"
534 ${ElseIf} $R3 == "\r" ;Carriage return
535 StrCpy $R4 "$\r"
536 ${ElseIf} $R3 == "\n" ;Line feed
537 StrCpy $R4 "$\n"
538 ${ElseIf} $R3 == "\t" ;Tab
539 StrCpy $R4 "$\t"
540 ${Else} ;Anything else
541 StrCpy $R4 ""
542 ${EndIf}
543
544 ;Detect if "TempRepStr" is not empty
545 ${If} $R4 != ""
546 ;Replace the old characters with the new one
547 StrCpy $R3 $R0 $R1
548 IntOp $R1 $R1 + 2
549 StrCpy $R0 $R0 "" $R1
550 StrCpy $R0 "$R3$R4$R0"
551 IntOp $R2 $R2 - 1 ;Decrease "StrLen"
552 IntOp $R1 $R1 - 2 ;Go back to the next character
553 ${EndIf}
554 ${Next}
555 Pop $R4
556 Pop $R3
557 Pop $R2
558 Pop $R1
559 Exch $R0
560 !insertmacro STRFUNC_ENDFUNC
561 !macroend
562
563 ############################################################################
564 # StrLoc
565 !insertmacro STRFUNC_DEFFUNC StrLoc `ResultVar|String|StrToSearchFor|CounterDirection` `Output|Text|Text|Option > <`
566
567 !macro STRFUNC_CALL_StrLoc un ResultVar String StrToSearchFor OffsetDirection
568 !verbose push ${STRFUNC_VERBOSITY}
569 !echo `${U+24}{${un}StrLoc} "${ResultVar}" "${String}" "${StrToSearchFor}" "${OffsetDirection}"`
570 !verbose 2
571 Push `${String}`
572 Push `${StrToSearchFor}`
573 Push `${OffsetDirection}`
574 !insertmacro STRFUNC_CALL StrLoc "${un}"
575 Pop ${ResultVar}
576 !verbose pop
577 !macroend
578
579 !macro STRFUNC_MAKEFUNC_StrLoc
580 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Ximon Eighteen`
581
582 /*After this point:
583 ------------------------------------------
584 $R0 = OffsetDirection (input)
585 $R1 = StrToSearch (input)
586 $R2 = String (input)
587 $R3 = StrToSearchLen (temp)
588 $R4 = StrLen (temp)
589 $R5 = StartCharPos (temp)
590 $R6 = TempStr (temp)*/
591
592 ;Get input from user
593 Exch $R0
594 Exch
595 Exch $R1
596 Exch 2
597 Exch $R2
598 Push $R3
599 Push $R4
600 Push $R5
601 Push $R6
602
603 ;Get "String" and "StrToSearch" length
604 StrLen $R3 $R1
605 StrLen $R4 $R2
606 ;Start "StartCharPos" counter
607 StrCpy $R5 0
608
609 ;Loop until "StrToSearch" is found or "String" reaches its end
610 ${Do}
611 ;Remove everything before and after the searched part ("TempStr")
612 StrCpy $R6 $R2 $R3 $R5
613
614 ;Compare "TempStr" with "StrToSearch"
615 ${If} $R6 == $R1
616 ${If} $R0 == `<`
617 IntOp $R6 $R3 + $R5
618 IntOp $R0 $R4 - $R6
619 ${Else}
620 StrCpy $R0 $R5
621 ${EndIf}
622 ${ExitDo}
623 ${EndIf}
624 ;If not "StrToSearch", this could be "String" end
625 ${If} $R5 >= $R4
626 StrCpy $R0 ``
627 ${ExitDo}
628 ${EndIf}
629 ;If not, continue the loop
630 IntOp $R5 $R5 + 1
631 ${Loop}
632
633 ;Return output to user
634 Pop $R6
635 Pop $R5
636 Pop $R4
637 Pop $R3
638 Pop $R2
639 Exch
640 Pop $R1
641 Exch $R0
642 !insertmacro STRFUNC_ENDFUNC
643
644 !macroend
645
646 ############################################################################
647 # StrNSISToIO
648 !insertmacro STRFUNC_DEFFUNC StrNSISToIO `ResultVar|String` `Output|Text`
649
650 !macro STRFUNC_CALL_StrNSISToIO un ResultVar String
651 !verbose push ${STRFUNC_VERBOSITY}
652 !echo `${U+24}{${un}StrNSISToIO} "${ResultVar}" "${String}"`
653 !verbose 2
654 Push `${String}`
655 !insertmacro STRFUNC_CALL StrNSISToIO "${un}"
656 Pop ${ResultVar}
657 !verbose pop
658 !macroend
659
660 !macro STRFUNC_MAKEFUNC_StrNSISToIO
661 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 "bluenet" - Based on functions by Amir Szekely, Joost Verburg, Dave Laundon and Diego Pedroso`
662
663 /*After this point:
664 ------------------------------------------
665 $R0 = String (input/output)
666 $R1 = StartCharPos (temp)
667 $R2 = StrLen (temp)
668 $R3 = TempStr (temp)
669 $R4 = TempRepStr (temp)*/
670
671 ;Get input from user
672 Exch $R0
673 Push $R1
674 Push $R2
675 Push $R3
676 Push $R4
677
678 ;Get "String" length
679 StrLen $R2 $R0
680
681 ;Loop until "String" end is reached
682 ${For} $R1 0 $R2
683 ;Get the next "String" character
684 StrCpy $R3 $R0 1 $R1
685
686 ;Detect if current character is:
687 ${If} $R3 == "$\r" ;Back-slash
688 StrCpy $R4 "\r"
689 ${ElseIf} $R3 == "$\n" ;Carriage return
690 StrCpy $R4 "\n"
691 ${ElseIf} $R3 == "$\t" ;Line feed
692 StrCpy $R4 "\t"
693 ${ElseIf} $R3 == "\" ;Tab
694 StrCpy $R4 "\\"
695 ${Else} ;Anything else
696 StrCpy $R4 ""
697 ${EndIf}
698
699 ;Detect if "TempRepStr" is not empty
700 ${If} $R4 != ""
701 ;Replace the old character with the new ones
702 StrCpy $R3 $R0 $R1
703 IntOp $R1 $R1 + 1
704 StrCpy $R0 $R0 "" $R1
705 StrCpy $R0 "$R3$R4$R0"
706 IntOp $R2 $R2 + 1 ;Increase "StrLen"
707 ${EndIf}
708 ${Next}
709
710 ;Return output to user
711 Pop $R4
712 Pop $R3
713 Pop $R2
714 Pop $R1
715 Exch $R0
716 !insertmacro STRFUNC_ENDFUNC
717 !macroend
718
719 ############################################################################
720 # StrRep
721 !insertmacro STRFUNC_DEFFUNC StrRep `ResultVar|String|StrToReplace|ReplacementString` `Output|Text|Text|Text`
722
723 !macro STRFUNC_CALL_StrRep un ResultVar String StringToReplace ReplacementString
724 !verbose push ${STRFUNC_VERBOSITY}
725 !echo `${U+24}{${un}StrRep} "${ResultVar}" "${String}" "${StringToReplace}" "${ReplacementString}"`
726 !verbose 2
727 Push `${String}`
728 Push `${StringToReplace}`
729 Push `${ReplacementString}`
730 !insertmacro STRFUNC_CALL StrRep "${un}"
731 Pop ${ResultVar}
732 !verbose pop
733 !macroend
734
735 !macro STRFUNC_MAKEFUNC_StrRep
736 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Hendri Adriaens`
737
738 /*After this point:
739 ------------------------------------------
740 $R0 = ReplacementString (input)
741 $R1 = StrToSearch (input)
742 $R2 = String (input)
743 $R3 = RepStrLen (temp)
744 $R4 = StrToSearchLen (temp)
745 $R5 = StrLen (temp)
746 $R6 = StartCharPos (temp)
747 $R7 = TempStrL (temp)
748 $R8 = TempStrR (temp)*/
749
750 ;Get input from user
751 Exch $R0
752 Exch
753 Exch $R1
754 Exch
755 Exch 2
756 Exch $R2
757 Push $R3
758 Push $R4
759 Push $R5
760 Push $R6
761 Push $R7
762 Push $R8
763
764 ;Return "String" if "StrToSearch" is ""
765 ${IfThen} $R1 == "" ${|} Goto Done ${|}
766
767 ;Get "ReplacementString", "String" and "StrToSearch" length
768 StrLen $R3 $R0
769 StrLen $R4 $R1
770 StrLen $R5 $R2
771 ;Start "StartCharPos" counter
772 StrCpy $R6 0
773
774 ;Loop until "StrToSearch" is found or "String" reaches its end
775 ${Do}
776 ;Remove everything before and after the searched part ("TempStrL")
777 StrCpy $R7 $R2 $R4 $R6
778
779 ;Compare "TempStrL" with "StrToSearch"
780 ${If} $R7 == $R1
781 ;Split "String" to replace the string wanted
782 StrCpy $R7 $R2 $R6 ;TempStrL
783
784 ;Calc: "StartCharPos" + "StrToSearchLen" = EndCharPos
785 IntOp $R8 $R6 + $R4
786
787 StrCpy $R8 $R2 "" $R8 ;TempStrR
788
789 ;Insert the new string between the two separated parts of "String"
790 StrCpy $R2 $R7$R0$R8
791 ;Now calculate the new "StrLen" and "StartCharPos"
792 StrLen $R5 $R2
793 IntOp $R6 $R6 + $R3
794 ${Continue}
795 ${EndIf}
796
797 ;If not "StrToSearch", this could be "String" end
798 ${IfThen} $R6 >= $R5 ${|} ${ExitDo} ${|}
799 ;If not, continue the loop
800 IntOp $R6 $R6 + 1
801 ${Loop}
802
803 Done:
804
805 /*After this point:
806 ------------------------------------------
807 $R0 = OutVar (output)*/
808
809 ;Return output to user
810 StrCpy $R0 $R2
811 Pop $R8
812 Pop $R7
813 Pop $R6
814 Pop $R5
815 Pop $R4
816 Pop $R3
817 Pop $R2
818 Pop $R1
819 Exch $R0
820 !insertmacro STRFUNC_ENDFUNC
821
822 !macroend
823
824 ############################################################################
825 # StrSort
826 !insertmacro STRFUNC_DEFFUNC StrSort `ResultVar|String|CenterStr|LeftStr|RightStr|IncludeLeftStr|IncludeCenterStr|IncludeRightStr` `Output|Text|Text|Text|Text|Option 1 0|Option 1 0|Option 1 0`
827
828 !macro STRFUNC_CALL_StrSort un ResultVar String CenterStr LeftStr RightStr IncludeCenterStr IncludeLeftStr IncludeRightStr
829 !verbose push ${STRFUNC_VERBOSITY}
830 !echo `${U+24}{${un}StrSort} "${ResultVar}" "${String}" "${CenterStr}" "${LeftStr}" "${RightStr}" "${IncludeCenterStr}" "${IncludeLeftStr}" "${IncludeRightStr}"`
831 !verbose 2
832 Push `${String}`
833 Push `${CenterStr}`
834 Push `${LeftStr}`
835 Push `${RightStr}`
836 Push `${IncludeCenterStr}`
837 Push `${IncludeLeftStr}`
838 Push `${IncludeRightStr}`
839 !insertmacro STRFUNC_CALL StrSort "${un}"
840 Pop ${ResultVar}
841 !verbose pop
842 !macroend
843
844 !macro STRFUNC_MAKEFUNC_StrSort
845 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Stuart Welch`
846
847 /*After this point:
848 ------------------------------------------
849 $R0 = String (input)
850 $R1 = LeftStr (input)
851 $R2 = CenterStr (input)
852 $R3 = RightStr (input)
853 $R4 = IncludeLeftStr (input)
854 $R5 = IncludeCenterStr (input)
855 $R6 = IncludeRightStr (input)
856
857 $0 = StrLen (temp)
858 $1 = LeftStrLen (temp)
859 $2 = CenterStrLen (temp)
860 $3 = RightStrLen (temp)
861 $4 = StartPos (temp)
862 $5 = EndPos (temp)
863 $6 = StartCharPos (temp)
864 $7 = EndCharPos (temp)
865 $8 = TempStr (temp)*/
866
867 ;Get input from user
868 Exch $R6
869 Exch
870 Exch $R5
871 Exch
872 Exch 2
873 Exch $R4
874 Exch 2
875 Exch 3
876 Exch $R3
877 Exch 3
878 Exch 4
879 Exch $R2
880 Exch 4
881 Exch 5
882 Exch $R1
883 Exch 5
884 Exch 6
885 Exch $R0
886 Exch 6
887 Push $0
888 Push $1
889 Push $2
890 Push $3
891 Push $4
892 Push $5
893 Push $6
894 Push $7
895 Push $8
896
897 ;Parameter defaults
898 ${IfThen} $R4 == `` ${|} StrCpy $R4 `1` ${|}
899 ${IfThen} $R5 == `` ${|} StrCpy $R5 `1` ${|}
900 ${IfThen} $R6 == `` ${|} StrCpy $R6 `1` ${|}
901
902 ;Get "String", "CenterStr", "LeftStr" and "RightStr" length
903 StrLen $0 $R0
904 StrLen $1 $R1
905 StrLen $2 $R2
906 StrLen $3 $R3
907 ;Start "StartCharPos" counter
908 StrCpy $6 0
909 ;Start "EndCharPos" counter based on "CenterStr" length
910 IntOp $7 $6 + $2
911
912 ;Loop until "CenterStr" is found or "String" reaches its end
913 ${Do}
914 ;Remove everything before and after the searched part ("TempStr")
915 StrCpy $8 $R0 $2 $6
916
917 ;Compare "TempStr" with "CenterStr"
918 ${IfThen} $8 == $R2 ${|} ${ExitDo} ${|}
919 ;If not, this could be "String" end
920 ${IfThen} $7 >= $0 ${|} Goto Done ${|}
921 ;If not, continue the loop
922 IntOp $6 $6 + 1
923 IntOp $7 $7 + 1
924 ${Loop}
925
926 # "CenterStr" was found
927
928 ;Remove "CenterStr" from "String" if the user wants
929 ${If} $R5 = ${FALSE}
930 StrCpy $8 $R0 $6
931 StrCpy $R0 $R0 `` $7
932 StrCpy $R0 $8$R0
933 ${EndIf}
934
935 ;"StartPos" and "EndPos" will record "CenterStr" coordinates for now
936 StrCpy $4 $6
937 StrCpy $5 $7
938 ;"StartCharPos" and "EndCharPos" should be before "CenterStr"
939 IntOp $6 $6 - $1
940 IntOp $7 $6 + $1
941
942 ;Loop until "LeftStr" is found or "String" reaches its start
943 ${Do}
944 ;Remove everything before and after the searched part ("TempStr")
945 StrCpy $8 $R0 $1 $6
946
947 ;If "LeftStr" is empty
948 ${If} $R1 == ``
949 StrCpy $6 0
950 StrCpy $7 0
951 ${ExitDo}
952 ${EndIf}
953
954 ;Compare "TempStr" with "LeftStr"
955 ${IfThen} $8 == $R1 ${|} ${ExitDo} ${|}
956 ;If not, this could be "String" start
957 ${IfThen} $6 <= 0 ${|} ${ExitDo} ${|}
958 ;If not, continue the loop
959 IntOp $6 $6 - 1
960 IntOp $7 $7 - 1
961 ${Loop}
962
963 # "LeftStr" is found or "String" start was reached
964
965 ;Remove "LeftStr" from "String" if the user wants
966 ${If} $R4 = ${FALSE}
967 IntOp $6 $6 + $1
968 ${EndIf}
969
970 ;Record "LeftStr" first character position on "TempStr" (temporarily)
971 StrCpy $8 $6
972
973 ;"StartCharPos" and "EndCharPos" should be after "CenterStr"
974 ${If} $R5 = ${FALSE}
975 StrCpy $6 $4
976 ${Else}
977 IntOp $6 $4 + $2
978 ${EndIf}
979 IntOp $7 $6 + $3
980
981 ;Record "LeftStr" first character position on "StartPos"
982 StrCpy $4 $8
983
984 ;Loop until "RightStr" is found or "String" reaches its end
985 ${Do}
986 ;Remove everything before and after the searched part ("TempStr")
987 StrCpy $8 $R0 $3 $6
988
989 ;If "RightStr" is empty
990 ${If} $R3 == ``
991 StrCpy $6 $0
992 StrCpy $7 $0
993 ${ExitDo}
994 ${EndIf}
995
996 ;Compare "TempStr" with "RightStr"
997 ${IfThen} $8 == $R3 ${|} ${ExitDo} ${|}
998 ;If not, this could be "String" end
999 ${IfThen} $7 >= $0 ${|} ${ExitDo} ${|}
1000 ;If not, continue the loop
1001 IntOp $6 $6 + 1
1002 IntOp $7 $7 + 1
1003 ${Loop}
1004
1005 ;Remove "RightStr" from "String" if the user wants
1006 ${If} $R6 = ${FALSE}
1007 IntOp $7 $7 - $3
1008 ${EndIf}
1009
1010 ;Record "RightStr" last character position on "StartPos"
1011 StrCpy $5 $7
1012
1013 ;As the positionment is relative...
1014 IntOp $5 $5 - $4
1015
1016 ;Write the string and finish the job
1017 StrCpy $R0 $R0 $5 $4
1018 Goto +2
1019
1020 Done:
1021 StrCpy $R0 ``
1022
1023 /*After this point:
1024 ------------------------------------------
1025 $R0 = OutVar (output)*/
1026
1027 ;Return output to user
1028 Pop $8
1029 Pop $7
1030 Pop $6
1031 Pop $5
1032 Pop $4
1033 Pop $3
1034 Pop $2
1035 Pop $1
1036 Pop $0
1037 Pop $R6
1038 Pop $R5
1039 Pop $R4
1040 Pop $R3
1041 Pop $R2
1042 Pop $R1
1043 Exch $R0
1044 !insertmacro STRFUNC_ENDFUNC
1045
1046 !macroend
1047
1048 ############################################################################
1049 # StrStr
1050 !insertmacro STRFUNC_DEFFUNC StrStr `ResultVar|String|StrToSearchFor` `Output|Text|Text`
1051
1052 !macro STRFUNC_CALL_StrStr un ResultVar String StrToSearchFor
1053 !verbose push ${STRFUNC_VERBOSITY}
1054 !echo `${U+24}{${un}StrStr} "${ResultVar}" "${String}" "${StrToSearchFor}"`
1055 !verbose 2
1056 Push `${String}`
1057 Push `${StrToSearchFor}`
1058 !insertmacro STRFUNC_CALL StrStr "${un}"
1059 Pop ${ResultVar}
1060 !verbose pop
1061 !macroend
1062
1063 !macro STRFUNC_MAKEFUNC_StrStr
1064 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Ximon Eighteen`
1065
1066 /*After this point:
1067 ------------------------------------------
1068 $R0 = StrToSearch (input)
1069 $R1 = String (input)
1070 $R2 = StrToSearchLen (temp)
1071 $R3 = StrLen (temp)
1072 $R4 = StartCharPos (temp)
1073 $R5 = TempStr (temp)*/
1074
1075 ;Get input from user
1076 Exch $R0
1077 Exch
1078 Exch $R1
1079 Push $R2
1080 Push $R3
1081 Push $R4
1082 Push $R5
1083
1084 ;Get "String" and "StrToSearch" length
1085 StrLen $R2 $R0
1086 StrLen $R3 $R1
1087 ;Start "StartCharPos" counter
1088 StrCpy $R4 0
1089
1090 ;Loop until "StrToSearch" is found or "String" reaches its end
1091 ${Do}
1092 ;Remove everything before and after the searched part ("TempStr")
1093 StrCpy $R5 $R1 $R2 $R4
1094
1095 ;Compare "TempStr" with "StrToSearch"
1096 ${IfThen} $R5 == $R0 ${|} ${ExitDo} ${|}
1097 ;If not "StrToSearch", this could be "String" end
1098 ${IfThen} $R4 >= $R3 ${|} ${ExitDo} ${|}
1099 ;If not, continue the loop
1100 IntOp $R4 $R4 + 1
1101 ${Loop}
1102
1103 /*After this point:
1104 ------------------------------------------
1105 $R0 = OutVar (output)*/
1106
1107 ;Remove part before "StrToSearch" on "String" (if there has one)
1108 StrCpy $R0 $R1 `` $R4
1109
1110 ;Return output to user
1111 Pop $R5
1112 Pop $R4
1113 Pop $R3
1114 Pop $R2
1115 Pop $R1
1116 Exch $R0
1117 !insertmacro STRFUNC_ENDFUNC
1118
1119 !macroend
1120
1121 ############################################################################
1122 # StrStrAdv
1123 !insertmacro STRFUNC_DEFFUNC StrStrAdv `ResultVar|String|StrToSearchFor|SearchDirection|ResultStrDirection|DisplayStrToSearch|Loops|CaseSensitive` `Output|Text|Text|Option > <|Option > <|Option 1 0|Text|Option 0 1`
1124
1125 !macro STRFUNC_CALL_StrStrAdv un ResultVar String StrToSearchFor SearchDirection ResultStrDirection DisplayStrToSearch Loops CaseSensitive
1126 !verbose push ${STRFUNC_VERBOSITY}
1127 !echo `${U+24}{${un}StrStrAdv} "${ResultVar}" "${String}" "${StrToSearchFor}" "${SearchDirection}" "${ResultStrDirection}" "${DisplayStrToSearch}" "${Loops}" "${CaseSensitive}"`
1128 !verbose 2
1129 Push `${String}`
1130 Push `${StrToSearchFor}`
1131 Push `${SearchDirection}`
1132 Push `${ResultStrDirection}`
1133 Push `${DisplayStrToSearch}`
1134 Push `${Loops}`
1135 Push `${CaseSensitive}`
1136 !insertmacro STRFUNC_CALL StrStrAdv "${un}"
1137 Pop ${ResultVar}
1138 !verbose pop
1139 !macroend
1140
1141 !macro STRFUNC_MAKEFUNC_StrStrAdv
1142 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2003-2004 Diego Pedroso`
1143
1144 /*After this point:
1145 ------------------------------------------
1146 $0 = String (input)
1147 $1 = StringToSearch (input)
1148 $2 = DirectionOfSearch (input)
1149 $3 = DirectionOfReturn (input)
1150 $4 = ShowStrToSearch (input)
1151 $5 = NumLoops (input)
1152 $6 = CaseSensitive (input)
1153 $7 = StringLength (temp)
1154 $8 = StrToSearchLength (temp)
1155 $9 = CurrentLoop (temp)
1156 $R0 = EndCharPos (temp)
1157 $R1 = StartCharPos (temp)
1158 $R2 = OutVar (output)
1159 $R3 = Temp (temp)*/
1160
1161 ;Get input from user
1162
1163 Exch $6
1164 Exch
1165 Exch $5
1166 Exch
1167 Exch 2
1168 Exch $4
1169 Exch 2
1170 Exch 3
1171 Exch $3
1172 Exch 3
1173 Exch 4
1174 Exch $2
1175 Exch 4
1176 Exch 5
1177 Exch $1
1178 Exch 5
1179 Exch 6
1180 Exch $0
1181 Exch 6
1182 Push $7
1183 Push $8
1184 Push $9
1185 Push $R3
1186 Push $R2
1187 Push $R1
1188 Push $R0
1189
1190 ; Clean $R0-$R3 variables
1191 StrCpy $R0 ""
1192 StrCpy $R1 ""
1193 StrCpy $R2 ""
1194 StrCpy $R3 ""
1195
1196 ; Verify if we have the correct values on the variables
1197 ${If} $0 == ``
1198 SetErrors ;AdvStrStr_StrToSearch not found
1199 Goto AdvStrStr_End
1200 ${EndIf}
1201
1202 ${If} $1 == ``
1203 SetErrors ;No text to search
1204 Goto AdvStrStr_End
1205 ${EndIf}
1206
1207 ${If} $2 != <
1208 StrCpy $2 >
1209 ${EndIf}
1210
1211 ${If} $3 != <
1212 StrCpy $3 >
1213 ${EndIf}
1214
1215 ${If} $4 <> 0
1216 StrCpy $4 1
1217 ${EndIf}
1218
1219 ${If} $5 <= 0
1220 StrCpy $5 0
1221 ${EndIf}
1222
1223 ${If} $6 <> 1
1224 StrCpy $6 0
1225 ${EndIf}
1226
1227 ; Find "AdvStrStr_String" length
1228 StrLen $7 $0
1229
1230 ; Then find "AdvStrStr_StrToSearch" length
1231 StrLen $8 $1
1232
1233 ; Now set up basic variables
1234
1235 ${If} $2 == <
1236 IntOp $R1 $7 - $8
1237 StrCpy $R2 $7
1238 ${Else}
1239 StrCpy $R1 0
1240 StrCpy $R2 $8
1241 ${EndIf}
1242
1243 StrCpy $9 0 ; First loop
1244
1245 ;Let's begin the search
1246
1247 ${Do}
1248 ; Step 1: If the starting or ending numbers are negative
1249 ; or more than AdvStrStr_StringLen, we return
1250 ; error
1251
1252 ${If} $R1 < 0
1253 StrCpy $R1 ``
1254 StrCpy $R2 ``
1255 StrCpy $R3 ``
1256 SetErrors ;AdvStrStr_StrToSearch not found
1257 Goto AdvStrStr_End
1258 ${ElseIf} $R2 > $7
1259 StrCpy $R1 ``
1260 StrCpy $R2 ``
1261 StrCpy $R3 ``
1262 SetErrors ;AdvStrStr_StrToSearch not found
1263 Goto AdvStrStr_End
1264 ${EndIf}
1265
1266 ; Step 2: Start the search depending on
1267 ; AdvStrStr_DirectionOfSearch. Chop down not needed
1268 ; characters.
1269
1270 ${If} $R1 <> 0
1271 StrCpy $R3 $0 `` $R1
1272 ${EndIf}
1273
1274 ${If} $R2 <> $7
1275 ${If} $R1 = 0
1276 StrCpy $R3 $0 $8
1277 ${Else}
1278 StrCpy $R3 $R3 $8
1279 ${EndIf}
1280 ${EndIf}
1281
1282 ; Step 3: Make sure that's the string we want
1283
1284 ; Case-Sensitive Support <- Use "AdvStrStr_Temp"
1285 ; variable because it won't be used anymore
1286
1287 ${If} $6 == 1
1288 System::Call `kernel32::lstrcmp(ts, ts) i.s` `$R3` `$1`
1289 Pop $R3
1290 ${If} $R3 = 0
1291 StrCpy $R3 1 ; Continue
1292 ${Else}
1293 StrCpy $R3 0 ; Break
1294 ${EndIf}
1295 ${Else}
1296 ${If} $R3 == $1
1297 StrCpy $R3 1 ; Continue
1298 ${Else}
1299 StrCpy $R3 0 ; Break
1300 ${EndIf}
1301 ${EndIf}
1302
1303 ; After the comparison, confirm that it is the
1304 ; value we want.
1305
1306 ${If} $R3 = 1
1307
1308 ;We found it, return except if the user has set up to
1309 ;search for another one:
1310 ${If} $9 >= $5
1311
1312 ;Now, let's see if the user wants
1313 ;AdvStrStr_StrToSearch to appear:
1314 ${If} $4 == 0
1315 ;Return depends on AdvStrStr_DirectionOfReturn
1316 ${If} $3 == <
1317 ; RTL
1318 StrCpy $R0 $0 $R1
1319 ${Else}
1320 ; LTR
1321 StrCpy $R0 $0 `` $R2
1322 ${EndIf}
1323 ${Break}
1324 ${Else}
1325 ;Return depends on AdvStrStr_DirectionOfReturn
1326 ${If} $3 == <
1327 ; RTL
1328 StrCpy $R0 $0 $R2
1329 ${Else}
1330 ; LTR
1331 StrCpy $R0 $0 `` $R1
1332 ${EndIf}
1333 ${Break}
1334 ${EndIf}
1335 ${Else}
1336 ;If the user wants to have more loops, let's do it so!
1337 IntOp $9 $9 + 1
1338
1339 ${If} $2 == <
1340 IntOp $R1 $R1 - 1
1341 IntOp $R2 $R2 - 1
1342 ${Else}
1343 IntOp $R1 $R1 + 1
1344 IntOp $R2 $R2 + 1
1345 ${EndIf}
1346 ${EndIf}
1347 ${Else}
1348 ; Step 4: We didn't find it, so do steps 1 thru 3 again
1349
1350 ${If} $2 == <
1351 IntOp $R1 $R1 - 1
1352 IntOp $R2 $R2 - 1
1353 ${Else}
1354 IntOp $R1 $R1 + 1
1355 IntOp $R2 $R2 + 1
1356 ${EndIf}
1357 ${EndIf}
1358 ${Loop}
1359
1360 AdvStrStr_End:
1361
1362 ;Add 1 to AdvStrStr_EndCharPos to be supportable
1363 ;by "StrCpy"
1364
1365 IntOp $R2 $R2 - 1
1366
1367 ;Return output to user
1368
1369 Exch $R0
1370 Exch
1371 Pop $R1
1372 Exch
1373 Pop $R2
1374 Exch
1375 Pop $R3
1376 Exch
1377 Pop $9
1378 Exch
1379 Pop $8
1380 Exch
1381 Pop $7
1382 Exch
1383 Pop $6
1384 Exch
1385 Pop $5
1386 Exch
1387 Pop $4
1388 Exch
1389 Pop $3
1390 Exch
1391 Pop $2
1392 Exch
1393 Pop $1
1394 Exch
1395 Pop $0
1396
1397 !insertmacro STRFUNC_ENDFUNC
1398
1399 !macroend
1400
1401 ############################################################################
1402 # StrTok
1403 !insertmacro STRFUNC_DEFFUNC StrTok `ResultVar|String|Separators|ResultPart|SkipEmptyParts` `Output|Text|Text|Mixed L|Option 1 0`
1404
1405 !macro STRFUNC_CALL_StrTok un ResultVar String Separators ResultPart SkipEmptyParts
1406 !verbose push ${STRFUNC_VERBOSITY}
1407 !echo `${U+24}{${un}StrTok} "${ResultVar}" "${String}" "${Separators}" "${ResultPart}" "${SkipEmptyParts}"`
1408 !verbose 2
1409 Push `${String}`
1410 Push `${Separators}`
1411 Push `${ResultPart}`
1412 Push `${SkipEmptyParts}`
1413 !insertmacro STRFUNC_CALL StrTok "${un}"
1414 Pop ${ResultVar}
1415 !verbose pop
1416 !macroend
1417
1418 !macro STRFUNC_MAKEFUNC_StrTok
1419 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by "bigmac666"`
1420 /*After this point:
1421 ------------------------------------------
1422 $0 = SkipEmptyParts (input)
1423 $1 = ResultPart (input)
1424 $2 = Separators (input)
1425 $3 = String (input)
1426 $4 = StrToSearchLen (temp)
1427 $5 = StrLen (temp)
1428 $6 = StartCharPos (temp)
1429 $7 = TempStr (temp)
1430 $8 = CurrentLoop
1431 $9 = CurrentSepChar
1432 $R0 = CurrentSepCharNum
1433 */
1434
1435 ;Get input from user
1436 Exch $0
1437 Exch
1438 Exch $1
1439 Exch
1440 Exch 2
1441 Exch $2
1442 Exch 2
1443 Exch 3
1444 Exch $3
1445 Exch 3
1446 Push $4
1447 Push $5
1448 Push $6
1449 Push $7
1450 Push $8
1451 Push $9
1452 Push $R0
1453
1454 ;Parameter defaults
1455 ${IfThen} $2 == `` ${|} StrCpy $2 `|` ${|}
1456 ${IfThen} $1 == `` ${|} StrCpy $1 `L` ${|}
1457 ${IfThen} $0 == `` ${|} StrCpy $0 `0` ${|}
1458
1459 ;Get "String" and "StrToSearch" length
1460 StrLen $4 $2
1461 StrLen $5 $3
1462 ;Start "StartCharPos" and "ResultPart" counters
1463 StrCpy $6 0
1464 StrCpy $8 -1
1465
1466 ;Loop until "ResultPart" is met, "StrToSearch" is found or
1467 ;"String" reaches its end
1468 ResultPartLoop: ;"CurrentLoop" Loop
1469
1470 ;Increase "CurrentLoop" counter
1471 IntOp $8 $8 + 1
1472
1473 StrSearchLoop:
1474 ${Do} ;"String" Loop
1475 ;Remove everything before and after the searched part ("TempStr")
1476 StrCpy $7 $3 1 $6
1477
1478 ;Verify if it's the "String" end
1479 ${If} $6 >= $5
1480 ;If "CurrentLoop" is what the user wants, remove the part
1481 ;after "TempStr" and itself and get out of here
1482 ${If} $8 == $1
1483 ${OrIf} $1 == `L`
1484 StrCpy $3 $3 $6
1485 ${Else} ;If not, empty "String" and get out of here
1486 StrCpy $3 ``
1487 ${EndIf}
1488 StrCpy $R0 `End`
1489 ${ExitDo}
1490 ${EndIf}
1491
1492 ;Start "CurrentSepCharNum" counter (for "Separators" Loop)
1493 StrCpy $R0 0
1494
1495 ${Do} ;"Separators" Loop
1496 ;Use one "Separators" character at a time
1497 ${If} $R0 <> 0
1498 StrCpy $9 $2 1 $R0
1499 ${Else}
1500 StrCpy $9 $2 1
1501 ${EndIf}
1502
1503 ;Go to the next "String" char if it's "Separators" end
1504 ${IfThen} $R0 >= $4 ${|} ${ExitDo} ${|}
1505
1506 ;Or, if "TempStr" equals "CurrentSepChar", then...
1507 ${If} $7 == $9
1508 StrCpy $7 $3 $6
1509
1510 ;If "String" is empty because this result part doesn't
1511 ;contain data, verify if "SkipEmptyParts" is activated,
1512 ;so we don't return the output to user yet
1513
1514 ${If} $7 == ``
1515 ${AndIf} $0 = ${TRUE}
1516 IntOp $6 $6 + 1
1517 StrCpy $3 $3 `` $6
1518 StrCpy $6 0
1519 Goto StrSearchLoop
1520 ${ElseIf} $8 == $1
1521 StrCpy $3 $3 $6
1522 StrCpy $R0 "End"
1523 ${ExitDo}
1524 ${EndIf} ;If not, go to the next result part
1525 IntOp $6 $6 + 1
1526 StrCpy $3 $3 `` $6
1527 StrCpy $6 0
1528 Goto ResultPartLoop
1529 ${EndIf}
1530
1531 ;Increase "CurrentSepCharNum" counter
1532 IntOp $R0 $R0 + 1
1533 ${Loop}
1534 ${IfThen} $R0 == "End" ${|} ${ExitDo} ${|}
1535
1536 ;Increase "StartCharPos" counter
1537 IntOp $6 $6 + 1
1538 ${Loop}
1539
1540 /*After this point:
1541 ------------------------------------------
1542 $3 = OutVar (output)*/
1543
1544 ;Return output to user
1545
1546 Pop $R0
1547 Pop $9
1548 Pop $8
1549 Pop $7
1550 Pop $6
1551 Pop $5
1552 Pop $4
1553 Pop $0
1554 Pop $1
1555 Pop $2
1556 Exch $3
1557 !insertmacro STRFUNC_ENDFUNC
1558
1559 !macroend
1560
1561 ############################################################################
1562 # StrTrimNewLines
1563 !insertmacro STRFUNC_DEFFUNC StrTrimNewLines `ResultVar|String` `Output|Text`
1564
1565 !macro STRFUNC_CALL_StrTrimNewLines un ResultVar String
1566 !verbose push ${STRFUNC_VERBOSITY}
1567 !echo `${U+24}{${un}StrTrimNewLines} "${ResultVar}" "${String}"`
1568 !verbose 2
1569 Push `${String}`
1570 !insertmacro STRFUNC_CALL StrTrimNewLines "${un}"
1571 Pop ${ResultVar}
1572 !verbose pop
1573 !macroend
1574
1575 !macro STRFUNC_MAKEFUNC_StrTrimNewLines
1576 !insertmacro STRFUNC_BEGINFUNC ${basename} `${un}` `2004 Diego Pedroso - Based on functions by Ximon Eighteen`
1577
1578 /*After this point:
1579 ------------------------------------------
1580 $R0 = String (input)
1581 $R1 = TrimCounter (temp)
1582 $R2 = Temp (temp)*/
1583
1584 ;Get input from user
1585 Exch $R0
1586 Push $R1
1587 Push $R2
1588
1589 ;Initialize trim counter
1590 StrCpy $R1 0
1591
1592 loop:
1593 ;Subtract to get "String"'s last characters
1594 IntOp $R1 $R1 - 1
1595
1596 ;Verify if they are either $\r or $\n
1597 StrCpy $R2 $R0 1 $R1
1598 ${If} $R2 == `$\r`
1599 ${OrIf} $R2 == `$\n`
1600 Goto loop
1601 ${EndIf}
1602
1603 ;Trim characters (if needed)
1604 IntOp $R1 $R1 + 1
1605 ${If} $R1 < 0
1606 StrCpy $R0 $R0 $R1
1607 ${EndIf}
1608
1609 /*After this point:
1610 ------------------------------------------
1611 $R0 = OutVar (output)*/
1612
1613 ;Return output to user
1614 Pop $R2
1615 Pop $R1
1616 Exch $R0
1617 !insertmacro STRFUNC_ENDFUNC
1618
1619 !macroend
1620
1621 ############################################################################
1622
1623 !endif
1624 !verbose 3
1625 !define STRFUNC_VERBOSITY ${_STRFUNC_VERBOSITY}
1626 !undef _STRFUNC_VERBOSITY
1627 !verbose pop