Class TextWithTerminator
A text string with a terminator character, not present in the text.
Inheritance
Implements
Inherited Members
Namespace: MoreStructures
Assembly: MoreStructures.dll
Syntax
public class TextWithTerminator : IValueEnumerable<char>, IEquatable<TextWithTerminator>
Remarks
USECASES
- A terminator-terminated text is required by data structures like Suffix Tries, Trees or Arrays.
- This object provides type safety, as it allows to tell apart terminator-terminated strings from generic ones.
- Consistently using TextWithTerminator, rather than System.String, in all library
functionalities ensures that the invariant of a terminator-terminated string is always respected.
- Most string-related functionalities provided by TextWithTerminator, such as
Length and Item[Index], as well as
Constructors
| Improve this Doc View SourceTextWithTerminator(IEnumerable<Char>, Char, Boolean)
A text string with a terminator character, not present in the text.
Declaration
public TextWithTerminator(IEnumerable<char> Text, char Terminator = '$', bool ValidateInput = true)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.IEnumerable<System.Char> | Text | A sequence of chars, of any length (including the empty sequence). |
System.Char | Terminator | A terminator character, not present in |
System.Boolean | ValidateInput | Whether the input, and in particular Text should be validated, while this object is created. Validation takes O(n) time, where n = number of chars in Text and can be an heavy operation. |
Remarks
USECASES
- A terminator-terminated text is required by data structures like Suffix Tries, Trees or Arrays.
- This object provides type safety, as it allows to tell apart terminator-terminated strings from generic ones.
- Consistently using TextWithTerminator, rather than System.String, in all library
functionalities ensures that the invariant of a terminator-terminated string is always respected.
- Most string-related functionalities provided by TextWithTerminator, such as
Length and Item[Index], as well as
Fields
| Improve this Doc View SourceDefaultTerminator
The special character used as a default terminator for the text to build the Suffix Tree of, when no custom terminator is specified. Should not be present in the text.
Declaration
public const char DefaultTerminator = '$'
Field Value
Type | Description |
---|---|
System.Char | A single char. |
Properties
| Improve this Doc View SourceItem[Index]
Select a part of this text by the provided index (either w.r.t. the start or to the end of the text).
Declaration
public char this[Index index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Index | index | The index applied to the underlying string. |
Property Value
Type | Description |
---|---|
System.Char | A char containing the selected part. |
Item[TextWithTerminator.ISelector]
Select a part of this text by the provided selector.
Declaration
public string this[TextWithTerminator.ISelector selector] { get; }
Parameters
Type | Name | Description |
---|---|---|
TextWithTerminator.ISelector | selector | Any selector acting on a TextWithTerminator. |
Property Value
Type | Description |
---|---|
System.String | A string containing the selected part. |
Item[Range]
Select a part of this text by the provided range (start index included, end index excluded).
Declaration
public IEnumerable<char> this[Range range] { get; }
Parameters
Type | Name | Description |
---|---|---|
Range | range | The range applied to the underlying string. |
Property Value
Type | Description |
---|---|
System.Collections.IEnumerable<System.Char> | An |
Length
The total length of this text, including the terminator.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 | A positive integer (at least 1). |
Remarks
CACHING
Calculated just once, and cached for later use.
Immutability guarantees correctness.
COMPLEXITY
- If the text was built with a System.String as input, the operation is O(1) in time.
- If the text was built with a type optimized by
CountO1<TSource>(IEnumerable<TSource>), such as an System.Collections.IList
or
- Otherwise, the operation is O(n), where n is the length of Text.
Terminator
Declaration
public char Terminator { get; set; }
Property Value
Type | Description |
---|---|
System.Char | A single char. |
TerminatorIndex
Returns the index of Terminator in this MoreStructures.TextWithTerminator.TextAndTerminator.
Declaration
public int TerminatorIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 | A 0-based index. 0 when Text is empty, positive otherwise. |
Text
Declaration
public IEnumerable<char> Text { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.IEnumerable<System.Char> | A sequence of chars. |
Remarks
Wrapped into a IValueEnumerable<T> to preserve value equality.
ValidateInput
Declaration
public bool ValidateInput { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceEndsWith(IEnumerable<Char>)
Whether this text ends with the provided suffix.
Declaration
public bool EndsWith(IEnumerable<char> suffix)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.IEnumerable<System.Char> | suffix | A terminator-included |
Returns
Type | Description |
---|---|
System.Boolean | True if this text ends by the suffix. |
GetEnumerator()
Returns an enumerator that iterates through the collection of chars of the underlying Text string, including the Terminator char.
Declaration
public IEnumerator<char> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator<System.Char> |
StartsWith(IEnumerable<Char>)
Whether this text starts with the provided suffix.
Declaration
public bool StartsWith(IEnumerable<char> prefix)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.IEnumerable<System.Char> | prefix | A terminator-included |
Returns
Type | Description |
---|---|
System.Boolean | True if this text starts by the prefix. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Returns an enumerator that iterates through the collection of chars of the underlying Text string, including the Terminator char.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |