LazUtils: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: LazUtils
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Overview | |
| 2 | + | ||
| 3 | + | LazUtils is collection of units that provides non-visual utility functions/classes; it is part of the units supplied by Lazarus but not the LCL (Lazarus Component Library). LazUtils do not have a dependancy on LCL, so they are also suitable for use in command-line, non-GUI applications. | |
| 4 | + | ||
| 5 | + | ### TLookupStringList | |
| 6 | + | ||
| 7 | + | The standard TStringList has a serious limitation about duplicated items, Duplicates property only works for sorted lists. It is not possible to avoid duplication in a list which is not sorted or has a custom sort. | |
| 8 | + | ||
| 9 | + | TLookupStringList is an unsorted *TStringList* with a fast lookup feature. Internally it uses a string map container to store the string again. It is then used for *InsertItem*, *Contains*, *IndexOf* and *Find* methods. The extra container does not reserve excessive memory because the strings are reference-counted and not actually copied. | |
| 10 | + | ||
| 11 | + | *TLookupStringList* fully supports all Duplicates property values including *dupIgnore* and *dupError*. A normal unsorted *TStringList* lacks this support for some values of Duplicates. | |
| 12 | + | ||
| 13 | + | This class is particularly useful when you need to preserve the order of strings at the same time doing fast lookups (to check if a string is already there), or when you need to prevent addition of duplicate strings. | |
| 14 | + | ||
| 15 | + | For a simple dedupe task, just load the strings you want to dedupe and it is done. | |
| 16 | + | ||
| 17 | + | It is very memory efficient, because: | |
| 18 | + | ||
| 19 | + | - Internally it uses a balanced tree container (TStringMap) to store the strings again. A balanced tree is memory efficient compared to a hash map. | |
| 20 | + | - Strings have reference count and lazy copy semantics. It means only a reference to a string is copied to the other container. | |
| 21 | + | ||
| 22 | + | You can find an example for TLookupStringList in your Lazarus folder: {LazarusDir}\components\lazutils\examples. | |
| 23 | + | ||
| 24 | + | ### UTF8WrapText function | |
| 25 | + | ||
| 26 | + | It wraps UTF8 text provided as a string into a MaxCol length. It inserts LineEndings at every last space/tab/hyphen character before MaxCol value or just on it and returns the resulting string. | |
| 27 | + | ||
| 28 | + | ## See also | |
| 29 | + | ||
| 30 | + | - [[LazUtils Documentation Roadmap]] | |
| 31 | + | - [[LazFileUtils]] | |
| 32 | + | ||
| 33 | + | --- | |
| 34 | + | *From the Free Pascal wiki, page "LazUtils", as it stood on 2021-07-20 after a change by Alextpp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 35 | + | Category: LazUtils | |
| 36 | + | Category: Lazarus |
