StrFunc.nsh 45 KB

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