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