Class AStringList

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AStringList = class(ALinkedList)

Description

This class represents a list of one or more strings. It extends ALinkedList to allow string values to be stored within the list. As with ALinkedList, AStringList may be accessed as though it was an indexed array or used like a stack.

Hierarchy

Overview

Methods

Protected procedure quickSort(Left, Right: ANode); virtual;
Public constructor withStrings(const strings: array of string); virtual;
Public constructor from(const thisList: string; const thisDelimiter: string = ''); virtual;
Public class function wrapString(const str: string; const breakCharacters: array of string; lineLength: longword = tosDefaultLineLength; const firstLineStartColumn: longword = 0; const remainingLineStartColumn: longword = 0; padCharacter: string = ''): AStringList; virtual;
Public function init: boolean; override;
Public function add(const thisString: string): TNodeAbsoluteIndex; virtual;
Public function addSeveral(const strings: array of string): TCensus; virtual;
Public function explode(thisList: string; delimiter: string = ''): TCensus; override;
Public procedure push(const thisString: string); virtual;
Public procedure pushSeveral(const strings: array of string); virtual;
Public function pop: string; virtual;
Public procedure insertAt(const index: TNodeRelativeIndex; const thisString: string); virtual;
Public function hasText(const thisString: string): boolean; virtual;
Public function indexOf(const thisString: string; const afterIndex: TNodeRelativeIndex = 0): TNodeRelativeIndex; virtual;
Public procedure sort(const reverse: boolean = false); virtual;
Public function item(const thisIndex: TNodeRelativeIndex): string; virtual;
Public function setItem(const thisIndex: TNodeRelativeIndex; const thisValue: string): string;

Description

Methods

Protected procedure quickSort(Left, Right: ANode); virtual;

Performs a quick sort

Public constructor withStrings(const strings: array of string); virtual;

Construct a new string list that contains the specified strings.

This method calls AStringList.pushSeveral to insert the strings in strings into the list after the new instance has been constructed and initialized. If strings is empty, then an empty list is created by this routine.

Public constructor from(const thisList: string; const thisDelimiter: string = ''); virtual;

Construct a new string list by expanding the values provided in thisList.

If thisDelimiter is provided by the caller, then it is used to split the values provided in thisList; otherwise, the delimiter specified by llstDefaultDelimiter is used. See AStringList.explode for more information.

If thisList is an empty string, then an empty list is created by this routine.

Public class function wrapString(const str: string; const breakCharacters: array of string; lineLength: longword = tosDefaultLineLength; const firstLineStartColumn: longword = 0; const remainingLineStartColumn: longword = 0; padCharacter: string = ''): AStringList; virtual;

Wrap the contents of a string that may span several lines so that it fits within the given line length.

This method splits str into one or more tokens by splitting str wherever a character in breakCharacters occurs. It then strings tokens together into one or more lines, ensuring that each line is no more than lineLength characters in length. If lineLength is zero (0), then the value specified by tosDefaultLineLength is used.

The first line is padded on the left by repeated padCharacters unless firstLineStartColumn is zero (0). Any subsequent lines are padded on the left by repeating padCharacters only if remainingLineStartColumn is greater than zero (0).

breakCharacters may specify UTF-8 or ASCII-encoded characters. Only the first UTF-8 or ASCII-encoded character in each string specified by breakCharacters is used to break str; any remaining characters are ignored. The default characters specified by tosWrapDefaultBreakCharacters may be used.

padCharacter may specify a UTF-8 or ASCII-encoded character. Only the first UTF-8 or ASCII-encoded character in padCharacter is used to pad each line; any remaining characters are ignored. If padCharacter is an empty string, the value of tosWrapDefaultPadCharacter is used.

Returns

A string list that contains one item for each line of str. The caller is responsible for freeing this list when it is no longer required. If str is an empty string, this function will return Nil.

Public function init: boolean; override;

Initializer

Public function add(const thisString: string): TNodeAbsoluteIndex; virtual;

Adds thisString to the end of the list.

This method constructs a new instance of AStringListItem and then calls ALinkedList.addItem to add the item to the list.

Returns

The index of the new item. This index is not guaranteed to remain the same for this item if other items are added or removed at locations PRIOR to the index returned.

Public function addSeveral(const strings: array of string): TCensus; virtual;

Add several items to the end of the list.

This method iterates through each item in strings and calls AStringList.add to add each item to the list.

Returns

The total number of items added to the list.

Public function explode(thisList: string; delimiter: string = ''): TCensus; override;

Add the items specified in thisList to the list.

This method assumes that thisList contains one or more values that are separated by a delimiter of some kind (e.g., a comma). It uses the value of delimiter to split the string into its component values; these values are then added as individual items to the list. If delimiter is not supplied, or if it is an empty string, then the value of llstDefaultDelimiter is used.

Returns

The total number of items added to the list.

Public procedure push(const thisString: string); virtual;

Pushes the specified string value onto the list, as the last item in the list. Calling AStringList.pop immediately after this routine will return thisString.

This method constructs a new instance of AStringListItem and then calls ALinkedList.pushItem to push the item onto the list.

Public procedure pushSeveral(const strings: array of string); virtual;

Push several items onto the list.

This method iterates through each item in strings and calls AStringList.push to push each string value onto the list.

Public function pop: string; virtual;

Pops the last item from the list. This will be the string most recently added to the list by a call to AStringList.add or AStringList.push.

If the list is empty, this routine returns an empty string.

Public procedure insertAt(const index: TNodeRelativeIndex; const thisString: string); virtual;

Inserts the specified string value at the given index. If an item already exists at that index, it is "bumped aside" in favor of the new item.

This method constructs a new instance of AStringListItem and then calls ALinkedList.insertItemAt to insert the item into the list.

The first item in the list is always at index zero (0). The last item in the list is always at index (ALinkedList.census -1). If index specifies a value that is greater than the number of items in the list, then thisString is inserted at the end of the list.

Public function hasText(const thisString: string): boolean; virtual;

Performs a recursive search to determine whether or not the specified string exists within the list. For very large lists, this search can be inefficient (and can cause stack overflows, due to the recursive nature of the search).

This method calls AStringListItem.find on the last item in the list, which causes the entire list to be searched recursively.

Returns

True if thisString is found in the list; False if not.

Public function indexOf(const thisString: string; const afterIndex: TNodeRelativeIndex = 0): TNodeRelativeIndex; virtual;

Performs a linear search to find the index of the specified string. The search will begin at afterIndex.

Because this method performs a linear search, it can be inefficient on very large lists.

Returns

The index of the specified string, if found; -1 otherwise. The index returned by this routine will always be an offset relative to the beginning of the list (i.e., a positive integer) if the string is found.

Public procedure sort(const reverse: boolean = false); virtual;

Sort the list based on the values of its items.

This method uses a QuickSort to rearrange the items in the list. If reverse is True, then the items in the list are sorted from the highest value to the lowest value; otherwise, they are sorted from lowest value to highest value.

In the default implementation, these items will be sorted alphabetically.

Public function item(const thisIndex: TNodeRelativeIndex): string; virtual;

Retrieve the value of the item at the specified index.

This method calls ALinkedList.itemAt to retrieve the AStringListItem instance at the specified index; it then returns the value of AStringListItem.text.

Index zero (0) represents the first node in the list, while index (ALinkedList.census - 1) represents the last node in the list. If index specifies a value that is greater than the number of nodes in the list, then this routine will remove the last item in the list.

If an invalid index is passed to this routine, it will return an empty string.

Public function setItem(const thisIndex: TNodeRelativeIndex; const thisValue: string): string;

Set the value of the item at the specified index.

This method calls ALinkedList.itemAt to retrieve the AStringListItem instance at the specified index; it then calls AStringListItem.setText on that instance.

Returns

The previous value of the string stored at the specified index, if any. An empty string will be returned if an invalid index is passed to this routine.


Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18