Difference between revisions of "LazUtils"

From Lazarus wiki
Jump to navigationJump to search
Line 12: Line 12:
 
''TDictionaryStringList'' fully supports all Duplicates property values including ''dupIgnore'' and ''dupError''. A normal unsorted ''TStringList'' lacks this support for some values of Duplicates.
 
''TDictionaryStringList'' fully supports all Duplicates property values including ''dupIgnore'' and ''dupError''. A normal unsorted ''TStringList'' lacks this support for some values of Duplicates.
  
This class is particularly useful when you need to preserve the order in which strings have been inserted into an unsorted list at the same time as needing the ability to do fast lookups (to check if a string is already listed), when you need to prevent addition of duplicate strings.
+
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.
  
 
For a simple dedupe task, just load the strings you want to dedupe and it is done.
 
For a simple dedupe task, just load the strings you want to dedupe and it is done.

Revision as of 12:18, 5 July 2015

Overview

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.

TDictionaryStringList

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.

TDictionaryStringList 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.

TDictionaryStringList fully supports all Duplicates property values including dupIgnore and dupError. A normal unsorted TStringList lacks this support for some values of Duplicates.

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.

For a simple dedupe task, just load the strings you want to dedupe and it is done.

You can find TDictionaryStringList on your Lazarus folder ({LazarusDir}\components\lazutils\examples).

UTF8WrapText function

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.