Libraries.Containers.MultipleLineText Documentation

The MultipleLineText class is used to distribute text across multiple lines. This is done for both efficiency and to make certain kinds of operations easier. For example, inserting or deleting characters into very large strings of text will be much more efficient in a MultipleLineText than in the base text type.

Example Code

use Libraries.Containers.MultipleLineText

MultipleLineText multiLineText
multiLineText:Initialize("Hello world! ")

text extraText = "This is extra text."
multiLineText = multiLineText:Concatenate(extraText)

extraText = multiLineText:GetLineSeparator() + "This text is on a second line."
multiLineText = multiLineText:Concatenate(extraText)

output multiLineText:GetText()
output "The text contains " + multiLineText:GetLineCount() + " lines."

Inherits from: Libraries.Language.Object

Actions Documentation

Balance()

This action will create a new MultipleLineText containing the balanced contents of this tree. This is typically handled automatically by the tree itself during other operations which return new MultipleLineTexts.

Return

Libraries.Containers.MultipleLineText: A new MultipleLineText which is balanced and contains the same text as this MultipleLineText. use Libraries.Containers.MultipleLineText MultipleLineText tree tree:Initialize("Hello world!") boolean shouldRebalance = tree:NeedsBalancing() output "shouldRebalance is " + shouldRebalance if shouldRebalance tree:Balance() end

CharacterIndexFromLineIndex(integer index)

This action gets the index of the first character in the line at the given line index.

Parameters

  • integer index

Return

integer:

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Concatenate(text value)

The Concatenate action creates a new MultipleLineText where the provided text is appended to the end of this tree's text. This tree will not change as a result of this action.

Parameters

  • text value: The text to append onto the end of this tree's text.

Return

Libraries.Containers.MultipleLineText: A new MultipleLineText which contains the concatenation of this tree's text and the parameter text.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello ")

MultipleLineText result = tree:Concatenate("world!")
output result:GetText()

Concatenate(Libraries.Containers.MultipleLineText textTree)

The Concatenate action creates a new MultipleLineText where the provided tree is appended to the end of this tree. All text in the parameter tree will appear after the text from this tree inside the returned value. This tree will not change as a result of this action.

Parameters

Return

Libraries.Containers.MultipleLineText: A new MultipleLineText which contains the concatenation of the two trees.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree1
tree1:Initialize("Hello ")

MultipleLineText tree2
tree2:Initialize("world!")

MultipleLineText result = tree1:Concatenate(tree2)
output result:GetText()

Delete(integer startIndex, integer endIndex)

The Delete action creates a new MultipleLineText which is a copy of this tree, then deletes all characters between the two given indices. The first index is inclusive (the character at the first index will be deleted) and the second index is exclusive (the character at the second index is not deleted). This action creates a new MultipleLineText, and has no effect on this tree.

Parameters

  • integer startIndex: The beginning of the range of characters to delete. The character at this index is deleted.
  • integer endIndex: The end of the range of characters to delete. A character at this index is not deleted.

Return

Libraries.Containers.MultipleLineText: A new MultipleLineText containing this tree's text, minus the deleted portion.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")

MultipleLineText deleteTree = tree:Delete(5, tree:GetSize() - 1)
output deleteTree:GetText()

DisableTextWrapping()

This action returns how many characters can be stored in each leaf of the MultipleLineText.

Return

Libraries.Containers.MultipleLineText: How many characters can be stored in each leaf.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

MultipleLineText newTree
newTree:SetLeafSize(10)
newTree:Initialize("Hello world! What a lovely day!")
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetCharacter(integer index)

This action retrieves a character at the given index from the tree.

Parameters

  • integer index: The index to retrieve a character from.

Return

text: A single character located at the given index.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")
text character = tree:GetCharacter(1)
output "The character at index 1 is '" + character + "'."

GetDefaultLineSeparator()

The GetDefaultLineSeparator action returns the default character(s) used by the MultipleLineText to signify the end of a line of text. This is the same line separating characters that are used by the running operating system.

Return

text: The default characters used to indicate the end of a line of text.

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetLeafSize()

This action returns how many characters can be stored in each leaf of the MultipleLineText.

Return

number: How many characters can be stored in each leaf.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

MultipleLineText newTree
newTree:SetLeafSize(10)
newTree:Initialize("Hello world! What a lovely day!")
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

GetLine(integer index)

Parameters

  • integer index

Return

Libraries.Containers.MultipleLineText:

GetLineCount()

Return

integer:

GetLineSeparator()

The GetLineSeparator action returns the text which is used to designate the end of a line in the MultipleLineText. By default, this is the same as the value used by the operating system.

Return

text: The character(s) used to designate the end of a line.

GetLines()

GetLines(Libraries.Containers.Array<Libraries.Containers.MultipleLineText> array)

GetSize()

This action returns the length of the text stored in the MultipleLineText.

Return

integer: The length of text in this MultipleLineText.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")
output "The length of the text in the tree is " + tree:GetSize()

GetText(integer startIndex, integer endIndex)

This action returns the text between the two indices. The first index is inclusive (the character at the first index is part of the returned text) and the second index is exclusive (the character at the second index is not part of the returned text).

Parameters

  • integer startIndex: The beginning of the range of characters to return. This index is included in the returned value.
  • integer endIndex: The end of the range of characters to return. This index is not included in the returned value.

Return

text: The text between the two indices.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")
output tree:GetText(1, 10)

GetText()

This action returns all of the text stored in the MultipleLineText.

Return

text: The text stored in this MultipleLineText.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")
output tree:GetText()

GetWidth()

Return

number:

Initialize(text value, number leafSize)

The Initialize action constructs the MultipleLineText from a starting text value. The MultipleLineText will store the given value, which may be retrieved or modified using the MultipleLineText's other actions. The provided integer parameter will be used to set the maximum size of each leaf, in characters.

Parameters

  • text value: The value to be stored in this MultipleLineText.
  • number leafSize: How many characters should be stored in each leaf of the tree.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

MultipleLineText newTree
newTree:Initialize("Hello world! What a lovely day!", 10)
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

Initialize(text value)

The Initialize action constructs the MultipleLineText from a starting text value. The MultipleLineText will store the given value, which may be retrieved or modified using the MultipleLineText's other actions.

Parameters

  • text value: The value to be stored in this MultipleLineText.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world! What a lovely day!")
output tree:GetText()

Insert(integer index, text value)

The Insert action creates a new MultipleLineText and inserts the given text value into the tree at the provided index. The character that was previously located at that index will be positioned behind the newly inserted text. This action creates a new MultipleLineText, and has no effect on this tree.

Parameters

  • integer index: The index to begin inserting text at in the new tree.
  • text value: The text to be inserted into the new tree.

Return

Libraries.Containers.MultipleLineText: A new MultipleLineText containing the inserted text.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")

MultipleLineText insertTree = tree:Insert(11, " of tomorrow")
output insertTree:GetText()

LineIndexFromCharacterIndex(integer index)

This action gets the index of the line which contains the character at the given character index position in the text.

Parameters

  • integer index

Return

integer:

NeedsBalancing()

This action returns true is the tree is imbalanced, or false if it is considered balanced. This is typically handled automatically by the tree itself.

Return

boolean: Whether or not the tree is currently imbalanced.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")
boolean shouldRebalance = tree:NeedsBalancing()
output "shouldRebalance is " + shouldRebalance

if shouldRebalance
    tree:Balance()
end

SetLeafSize(integer size)

This action sets how many characters should be stored in each leaf of the MultipleLineText.

Parameters

  • integer size: How many characters to store in each leaf.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

MultipleLineText newTree
newTree:SetLeafSize(10)
newTree:Initialize("Hello world! What a lovely day!")
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

SetLine(integer index, text value)

The Insert action creates a new MultipleLineText and inserts the given text value into the tree at the provided index. The character that was previously located at that index will be positioned behind the newly inserted text. This action creates a new MultipleLineText, and has no effect on this tree.

Parameters

  • integer index: The index to begin inserting text at in the new tree.
  • text value: The text to be inserted into the new tree.

Return

Libraries.Containers.MultipleLineText: A new MultipleLineText containing the inserted text.

Example

use Libraries.Containers.MultipleLineText

MultipleLineText tree
tree:Initialize("Hello world!")

MultipleLineText insertTree = tree:Insert(11, " of tomorrow")
output insertTree:GetText()

SetLineSeparator(text separator)

The SetLineSeparator action sets which character(s) should be used to signify the end of a line.

Parameters

  • text separator: The character(s) to be used to mark the end of a line of text.