StrFunc.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. String Functions Header File Readme
  2. -----------------------------------
  3. String Functions Header File contains a set of good string manipulation
  4. functions in a much simpler way to include and call in NSIS scripts.
  5. How to use
  6. ----------
  7. Basic Syntax
  8. ------------
  9. Parameters are specified in this format:
  10. required (required) (option1 | option2) [optional or add. options]
  11. [option1 | option2]
  12. The stars in command titles (*****) are the function usefulness in my
  13. opinion. The more starts, the more useful it is. 5 stars (*****) is the
  14. most useful.
  15. Any time when is mentioned "Default is" means that you can use the value
  16. mentioned or keep it blank, the result is the same.
  17. If you want a certain value (e.g. a text) to be language-specific, set a
  18. language string (using LangString) and define $(STRINGNAME) as value.
  19. If you want to add ` to a string, you should always escape it using $\`
  20. because the header file macro functions use ` to separate parameters.
  21. 1. Include Header file
  22. ----------------------
  23. !include "StrFunc.nsh"
  24. StrFunc.nsh has to be inside Include directory, so you don't have to
  25. specify a path.
  26. You have to put this command before any command used in this header file.
  27. 2. Defines
  28. ----------
  29. This header file contains defines that automate the life of some who
  30. fear a lot of changes sometimes imposed in this header file, or who have
  31. applications that put it to work at maximum capacity. Before you try
  32. these, take a look at the information below:
  33. - Every item on a define value is separated by a "|", and every subitem
  34. (items in an item) is separated by " ".
  35. - Use ${StrTok} $var "${DefineName}" "|" "$counter" "0" to get every
  36. item inside the define. For subitems, use ${StrTok} $var2 "$var" " "
  37. "$counter2" "0" after getting the value for a desired item.
  38. - ${StrFunc_List} is automatically made by the header file. The rest
  39. is manually added to the header.
  40. 2.1 Defines List:
  41. -----------------
  42. StrFunc_List - Lists all function names currently available on StrFunc
  43. header file.
  44. *_List - Lists all parameter names currently available for "*"
  45. function. (* = function name - i.e. StrTok_List).
  46. *_TypeList - Lists the types of all parameters on "*" function.
  47. (* = function name - i.e. StrTok_List). Possible types
  48. for each parameter:
  49. - Output - Needs a variable to output a function result.
  50. - Text - Needs text or number to be input.
  51. - Mixed - Needs text, number or option to be inputed.
  52. Each subitem following the "Mixed" word is an
  53. option. The first option is ever the default
  54. one. Two following spaces " " means that
  55. that subitem is empty.
  56. - Option - Needs an option to be inputed. Each subitem
  57. following the "Option" word is an option.
  58. The first option is ever the default one. Two
  59. following spaces " " means that that subitem
  60. is empty.
  61. 3. Commands
  62. -----------
  63. Some commands have special specifications to work. Consult command's
  64. documentation on "3.3 Commands" section.
  65. 3.1 How To Use Commands In Install Sections and Functions
  66. ---------------------------------------------------------
  67. Every command used in install sections and functions have to be called
  68. first before and out of any sections and functions, and without
  69. parameters.
  70. Example:
  71. --------
  72. ${StrStr}
  73. 3.2 How To Use Commands In Uninstall Sections and Functions
  74. -----------------------------------------------------------
  75. Commands with Uninstall Sections and Functions support have "Un" before
  76. the words inside curly brackets "{}".
  77. Example:
  78. --------
  79. ${UnStrStr}
  80. A complete example with both Install and Uninstall Commands:
  81. ------------------------------------------------------------
  82. !include "StrFunc.nsh"
  83. ${StrStr} # Supportable for Install Sections and Functions
  84. ${UnStrStr} # Supportable for Uninstall Sections and Functions
  85. Section
  86. ${StrStr} $0 "OK! Now what?" "wh"
  87. SectionEnd
  88. Section Uninstall
  89. ${UnStrStr} $0 "OK! Now what?" "wh"
  90. SectionEnd
  91. 3.3 Commands
  92. ------------
  93. =========================================================================
  94. ** ${StrCase}
  95. -------------------------------------------------------------------------
  96. ResultVar String Type(|L|U|T|S|<>)
  97. =========================================================================
  98. Converts "String" to "Type" Case. Uses LogicLib.
  99. Parameters:
  100. ResultVar
  101. Destination where result is returned.
  102. String
  103. String to convert to "Type" case.
  104. Type
  105. Type of string case to convert to:
  106. - "" = Original Case (same as "String")
  107. - L = Lower Case (this is just an example. a very simple one.)
  108. - U = Upper Case (THIS IS JUST AN EXAMPLE. A VERY SIMPLE ONE.)
  109. - T = Title Case (This Is Just An Example. A Very Simple One.)
  110. - S = Sentence Case (This is just an example. A very simple one.)
  111. - <> = Switch Case (This is just an example. A very simple one.)
  112. Default value is "" (Original Case).
  113. Result Value -> ResultVar:
  114. "String" in "Type" case.
  115. Example:
  116. ${StrCase} $0 '"Você" is "You" in English.' "U"
  117. [__(_)__()___()__()__(____)_]
  118. $0 = '"VOCÊ" IS "YOU" IN ENGLISH.'
  119. =========================================================================
  120. * ${StrClb}
  121. -------------------------------------------------------------------------
  122. ResultVar String Action(|>|<|<>)
  123. =========================================================================
  124. Makes an action with the clipboard depending on value of parameter
  125. "Action". Uses LogicLib.
  126. Parameters:
  127. String
  128. If "Action" = ">" or "<>" - String to put on the clipboard.
  129. Action
  130. Can be one of the following values:
  131. - "" = Cleans the clipboard.
  132. - ">" = Set string to clipboard.
  133. - "<" = Get string from clipboard.
  134. - "<>" = Swap string with clipboard's.
  135. Result Value -> ResultVar:
  136. If "Action" = "<" or "<>" - String found on the clipboard.
  137. =========================================================================
  138. *** ${StrIOToNSIS}
  139. -------------------------------------------------------------------------
  140. ResultVar String
  141. =========================================================================
  142. Convert "String" from Install Options plugin to be supported by NSIS.
  143. Escape, back-slash, carriage return, line feed and tab characters are
  144. converted.
  145. Parameters:
  146. ResultVar
  147. Destination where result is returned.
  148. String
  149. String to convert to be supportable for NSIS.
  150. Result Value -> ResultVar:
  151. "String" supportable for NSIS.
  152. Example:
  153. ${StrIOToNSIS} $0 "\r\n\t\\This is just an example\\"
  154. [()()()()_______________________()]
  155. $0 = "$\r$\n$\t\This is just an example\"
  156. =========================================================================
  157. * ${StrLoc}
  158. -------------------------------------------------------------------------
  159. ResultVar String StrToSearchFor CounterDirection(>|<)
  160. =========================================================================
  161. Searches for "StrToSearchFor" in "String" and returns its location,
  162. according to "CounterDirection".
  163. Parameters:
  164. ResultVar
  165. Destination where result is returned.
  166. String
  167. String where to search "StrToSearchFor".
  168. StrToSearchFor
  169. String to search in "String".
  170. CounterDirection(>|<)
  171. Direction where the counter increases to. Default is ">".
  172. (> = increases from left to right, < = increases from right to left)
  173. Result Value -> ResultVar:
  174. Where "StrToSearchFor" is, according to "OffsetDirection".
  175. Example:
  176. ${StrLoc} $0 "This is just an example" "just" "<"
  177. (__)<<<<<<<<<<<
  178. $0 = "11"
  179. =========================================================================
  180. *** ${StrNSISToIO}
  181. -------------------------------------------------------------------------
  182. ResultVar String
  183. =========================================================================
  184. Converts "String" from NSIS to be supported by Install Options plugin.
  185. Escape, back-slash, carriage return, line feed and tab characters are
  186. converted.
  187. Parameters:
  188. ResultVar
  189. Destination where result is returned.
  190. String
  191. String to convert to be supportable for Install Options plugin.
  192. Result Value -> ResultVar:
  193. "String" supportable for Install Options plugin.
  194. Example:
  195. ${StrNSISToIO} $0 "$\r$\n$\t\This is just an example\"
  196. [(_)(_)(_)^_______________________^]
  197. $0 = "\r\n\t\\This is just an example\\"
  198. =========================================================================
  199. ***** ${StrRep}
  200. -------------------------------------------------------------------------
  201. ResultVar String StrToReplace ReplacementString
  202. =========================================================================
  203. Searches for all "StrToReplace" in "String" replacing those with
  204. "ReplacementString".
  205. Parameters:
  206. ResultVar
  207. Destination where result is returned.
  208. String
  209. String where to search "StrToReplace".
  210. StrToReplaceFor
  211. String to search in "String".
  212. StringToBeReplacedWith
  213. String to replace "StringToReplace" when it is found in "String".
  214. Result Value -> ResultVar:
  215. "String" with all occurrences of "StringToReplace" replaced with
  216. "ReplacementString".
  217. Example:
  218. ${StrRep} $0 "This is just an example" "an" "one"
  219. [____________()_______]
  220. $0 = "This is just one example"
  221. =========================================================================
  222. *** ${StrSort}
  223. -------------------------------------------------------------------------
  224. ResultVar String LeftStr CenterStr RightStr IncludeLeftStr(1|0)
  225. IncludeCenterStr(1|0) IncludeRightStr(1|0)
  226. =========================================================================
  227. Searches for "CenterStr" in "String", and returns only the value
  228. between "LeftStr" and "RightStr", including or not the "CenterStr" using
  229. "IncludeCenterStr" and/or the "LeftStr" using "IncludeLeftStr" and
  230. "RightStr" using "IncludeRightStr".
  231. Parameters:
  232. ResultVar
  233. Destination where result is returned.
  234. String
  235. String where to search "CenterStr".
  236. LeftStr
  237. The first occurrence of "LeftStr" on the left of "CenterStr".
  238. If it is an empty value, or was not found, will return
  239. everything on the left of "CenterStr".
  240. CenterStr
  241. String to search in "String".
  242. RightStr
  243. The first occurrence of "RightStr" on the right of "CenterStr".
  244. If it is an empty value, or was not found, will return
  245. everything on the right of "CenterStr".
  246. IncludeLeftStr(1|0)
  247. Include or not the "LeftStr" in the result value. Default is 1
  248. (True). (1 = True, 0 = False)
  249. IncludeCenterStr(1|0)
  250. Include or not the "CenterStr" in the result value. Default is 1
  251. (True). (1 = True, 0 = False)
  252. IncludeRightStr(1|0)
  253. Include or not the "RightStr" in the result value. Default is 1
  254. (True). (1 = True, 0 = False)
  255. Result Value -> ResultVar:
  256. String between "LeftStr" and "RightStr" of a found "CenterStr"
  257. including or not the "LeftStr" and "RightStr" if
  258. "IncludeLeftRightStr" is 1 and/or the "CenterStr" if
  259. "IncludeCenterStr" is 1.
  260. Example:
  261. ${StrSort} $0 "This is just an example" " just" "" "ple" "0" "0" "0"
  262. [_______(___)_______]( )
  263. C R
  264. $0 = "This is an exam"
  265. =========================================================================
  266. ***** ${StrStr}
  267. -------------------------------------------------------------------------
  268. ResultVar String StrToSearchFor
  269. =========================================================================
  270. Searches for "StrToSearchFor" in "String".
  271. Parameters:
  272. ResultVar
  273. Destination where result is returned.
  274. String
  275. String where to search "StrToSearchFor".
  276. StrToSearchFor
  277. String to search in "String".
  278. Result Value -> ResultVar:
  279. "StrToSearchFor" + the string after where "StrToSearchFor" was found in
  280. "String".
  281. Example:
  282. ${StrStr} $0 "This is just an example" "just"
  283. >>>>>>>>>{_)____________]
  284. $0 = "just an example"
  285. =========================================================================
  286. ***** ${StrStrAdv}
  287. -------------------------------------------------------------------------
  288. ResultVar String StrToSearchFor SearchDirection(>|<)
  289. ResultStrDirection(>|<) DisplayStrToSearch(1|0) Loops CaseSensitive(0|1)
  290. =========================================================================
  291. Searches for "StrToSearchFor" in "String" in the direction specified by
  292. "SearchDirection" and looping "Loops" times.
  293. Parameters:
  294. ResultVar
  295. Destination where result is returned.
  296. String
  297. String where to search "StrToSearchFor".
  298. StrToSearchFor
  299. String to search in "String".
  300. SearchDirection (>|<)
  301. Where do you want to direct the search. Default is ">" (to right).
  302. (< = To left, > = To right)
  303. ResultStrDirection (>|<)
  304. Where the result string will be based on in relation of
  305. "StrToSearchFor"
  306. position. Default is ">" (to right). (< = To left, > = To right)
  307. DisplayStrToSearch (1|0)
  308. Display "StrToSearchFor" in the result. Default is "1" (True).
  309. (1 = True, 0 = False)
  310. Loops
  311. Number of times the code will search "StrToSearchFor" in "String" not
  312. including the original execution. Default is "0" (1 code execution).
  313. CaseSensitive(0|1)
  314. If "1" the search will be case-sensitive (differentiates between cases).
  315. If "0" it is case-insensitive (does not differentiate between cases).
  316. Default is "0" (Case-Insensitive).
  317. Result Value -> ResultVar:
  318. "StrToSearchFor" if "DisplayStrToSearch" is 1 + the result string after
  319. or before "StrToSearchFor", depending on "ResultStrDirection".
  320. Result with Errors:
  321. When "StrToSearchFor" was not found, will return an empty string.
  322. When you put nothing in "StrToSearchFor", will return "String" and set
  323. error flag.
  324. When you put nothing in "String", will return an empty string and set
  325. error flag.
  326. Example:
  327. ${StrStrAdv} $0 "This IS really just an example" "IS " ">" ">" "0" "0" "1"
  328. >>>>>( )[____________________]
  329. $0 = "really just an example"
  330. =========================================================================
  331. **** ${StrTok}
  332. -------------------------------------------------------------------------
  333. ResultVar String Separators ResultPart[L] SkipEmptyParts(1|0)
  334. =========================================================================
  335. Returns the part "ResultPart" between two "Separators" inside
  336. "String".
  337. Parameters:
  338. ResultVar
  339. Destination where result is returned.
  340. String
  341. String where to search for "Separators".
  342. Separators
  343. Characters to find on "String".
  344. ResultPart[L]
  345. The part want to be found on "StrToTokenize" between two "Separators".
  346. Can be any number, starting at 0, and "L" that is the last part.
  347. Default is L (Last part).
  348. SkipEmptyParts(1|0)
  349. Skips empty string parts between two "Separators". Default is 1 (True).
  350. (1 = True, 0 = False)
  351. Result Value -> ResultVar:
  352. "String" part number "Part" between two "Separators".
  353. Examples:
  354. 1) ${StrTok} $0 "This is, or is not, just an example" " ," "4" "1"
  355. ( ) () () () [_] ( ) () ( )
  356. 0 1 2 3 4 5 6 7
  357. $0 = "not"
  358. 2) ${StrTok} $0 "This is, or is not, just an example" " ," "4" "0"
  359. ( ) () ^() [] ( ) ^( ) () ( )
  360. 0 1 23 4 5 67 8 9
  361. $0 = "is"
  362. =========================================================================
  363. * ${StrTrimNewLines}
  364. -------------------------------------------------------------------------
  365. ResultVar String
  366. =========================================================================
  367. Deletes unnecessary new lines at end of "String".
  368. Parameters:
  369. ResultVar
  370. Destination where result is returned.
  371. String
  372. String where to search unnecessary new lines at end of "String".
  373. Result Value -> ResultVar:
  374. "String" with unnecessary end new lines removed.
  375. Example:
  376. ${StrTrimNewLines} $0 "$\r$\nThis is just an example$\r$\n$\r$\n"
  377. [_____________________________(_)(_)(_)(_)]
  378. $0 = "$\r$\nThis is just an example"
  379. Functions included and not included
  380. --------------------------------------------------
  381. 11 functions have been included
  382. They are not available on Archive
  383. They are on LogicLib format
  384. 15 functions have not been included
  385. 12 were not included because of better functions
  386. 6 were not included because of AdvStrTok (called here as StrTok)
  387. First String Part Function
  388. Save on Variables Function
  389. Sort Strings (1, 2 and 3) Functions
  390. StrTok Function
  391. 2 were not included because of StrCase
  392. StrLower Function
  393. StrUpper Function
  394. 2 were not included because of StrClb
  395. StrClbSet Function
  396. StrClbGet Function
  397. 1 was not included because of NSISToIO and IOToNSIS
  398. Convert / to // in Paths Function
  399. 1 was not included because of original String Replace Function (called
  400. here as StrRep)
  401. Another String Replace Function
  402. 2 were not included because they aren't useful anymore
  403. Slash <-> Backslash Converter Function
  404. Trim Function
  405. 1 was not included because of bugs
  406. Number to String Converter Function
  407. Version History
  408. ---------------
  409. 1.09 - 10/22/2004
  410. - Fixed stack problems involving: StrCase, StrRep, StrSort, StrTok.
  411. - Fixed StrClb: When "Action" = "<>", handle was wrongly outputed as
  412. text.
  413. - Fixed StrSort, StrStrAdv documentation examples.
  414. - Fixed StrIOToNSIS, StrLoc, StrNSISToIO, StrRep, StrStr: sometimes
  415. didn't find "StrToSearch" at all.
  416. 1.08 - 10/12/2004
  417. - Converted all the functions to LogicLib.
  418. - StrSort: Totally remade and it can break old scripts. See
  419. documentation for details.
  420. - StrTok: "ResultPart" has to start from 0 and it can break old scripts.
  421. See documentation for details.
  422. - Added defines: StrFunc_List, *_List and *_TypeList.
  423. - Fixed StrStrAdv: Variables $R0-$R3 couldn't be used on scripts before
  424. calling.
  425. - StrRep: Cut down some variables.
  426. - Arranged correctly the order of StrSort on the documentation.
  427. 1.07 - 09/21/2004
  428. - Removed ${UnStrFunc} command. Now you can just include uninstall
  429. functions commands like ${UnStrStr} to be supported by uninstall functions
  430. and sections.
  431. - Added case-sensitive comparation option for StrStrAdv.
  432. - StrCase now uses System.dll which makes case conversions effective with
  433. all latin letters (i.e. ê).
  434. - Added switch case and original case for StrCase.
  435. - StrClbSet and StrClbGet removed, added StrClb.
  436. - Made compact the most usual operations inside the header file. File size
  437. reduced.
  438. 1.06 - 03/26/2004
  439. - StrNumToStr removed due to complex number handling on some languages.
  440. - Fixed the bug where the old string was attached to string returned by
  441. StrCase when $R5 variable was used.
  442. 1.05 - 03/17/2004
  443. - Fixed a bug with StrCase, Title Case wasn't working as should be.
  444. - Fixed a bug with StrStrAdv, previous fix created another bug, string not
  445. returned correctly when using backwards search with "DisplayStrToSearch" as
  446. "0".
  447. 1.04 - 03/07/2004
  448. - Added new StrCase, removed StrLower and StrUpper.
  449. - Organized by name commands inside header and readme files.
  450. 1.03 - 02/12/2004
  451. - Added commands support for uninstall sections and functions.
  452. - Fixed variables switch in "StrLoc" and "StrTok" after using these.
  453. 1.02 - 02/07/2004
  454. - Fixed StrLoc.
  455. - Fixed Documentation about StrLoc. "Direction" is really "OffsetDirection".
  456. - Added my new AdvStrSort, and removed the old one.
  457. 1.01 - 02/05/2004
  458. - Fixed Documentation about StrSort and StrTok.
  459. - Fixed StrTok default value for the string part. Now it's "L".
  460. - Fixed StrStrAdv fixed wrong search when had a combination of same
  461. substrings one after another in a string.
  462. - Fixed StrLoc: when a string isn't found, don't return any value at all.
  463. 1.00 - 02/01/2004
  464. - Added documentation.
  465. - Renamed header file to "StrFunc.nsh".
  466. - Added 1 function, StrLoc.
  467. - Modified StrStrAdv, removed some lines.
  468. - Fixed StrTok, 2 simple numbers made it loop everytime.
  469. - Fixed some small issues on the header file.
  470. 0.02 - 01/24/2004
  471. - Completed StrFunc.nsh file. Need some tests and the readme.
  472. 0.01 - 01/22/2004
  473. - First version to test ideas...
  474. Credits
  475. -------
  476. Made by Diego Pedroso (aka deguix).
  477. Functions Credits
  478. -----------------
  479. - All functions are made by Diego Pedroso on LogicLib format. They
  480. are based on functions by Amir Szekely, Dave Laundon, Hendri
  481. Adriaens, Nik Medved, Joost Verburg, Stuart Welch, Ximon Eighteen,
  482. "bigmac666" and "bluenet". "bluenet"'s version of StrIOToNSIS and
  483. StrNSISToIO on LogicLib format were included.
  484. License
  485. -------
  486. This header file is provided 'as-is', without any express or implied
  487. warranty. In no event will the author be held liable for any damages
  488. arising from the use of this header file.
  489. Permission is granted to anyone to use this header file for any purpose,
  490. including commercial applications, and to alter it and redistribute
  491. it freely, subject to the following restrictions:
  492. 1. The origin of this header file must not be misrepresented;
  493. you must not claim that you wrote the original header file.
  494. If you use this header file in a product, an acknowledgment in the
  495. product documentation would be appreciated but is not required.
  496. 2. Altered versions must be plainly marked as such,
  497. and must not be misrepresented as being the original header file.
  498. 3. This notice may not be removed or altered from any distribution.