Struct TextPosition
- Namespace
- AngleSharp.Text
- Assembly
- AngleSharp.dll
The position in the source code.
public readonly struct TextPosition : IEquatable<TextPosition>, IComparable<TextPosition>
- Implements
- Inherited Members
- Extension Methods
Constructors
TextPosition(ushort, ushort, int)
Creates a new text position.
public TextPosition(ushort line, ushort column, int position)
Parameters
line
ushortThe line of the character.
column
ushortThe column of the character.
position
intThe index of the character.
Fields
Empty
An empty position (0, 0, 0).
public static readonly TextPosition Empty
Field Value
Properties
Column
Gets the column within the document. The column is 1-based, so the first column has value 1.
public int Column { get; }
Property Value
Index
Gets the index within the source. The index is 0-based, so the first character is at index 0.
public int Index { get; }
Property Value
Line
Gets the line within the document. The line is 1-based, so the first line has value 1.
public int Line { get; }
Property Value
Position
Gets the position within the source. The position is 1-based, so the first character is at position 1.
public int Position { get; }
Property Value
Methods
After(char)
Returns a new text position that is after the given character.
public TextPosition After(char chr)
Parameters
chr
charThe character to analyze.
Returns
- TextPosition
The new text position.
After(string)
Returns a new text position that is after the given string.
public TextPosition After(string str)
Parameters
str
stringThe string to analyze.
Returns
- TextPosition
The new text position.
CompareTo(TextPosition)
Compares the current position with another position.
public int CompareTo(TextPosition other)
Parameters
other
TextPositionThe position to compare to.
Returns
- int
A mathematical representation of the relation (1 = greater, -1 = less, 0 = equal).
Equals(TextPosition)
Indicates whether the current position is equal to the given position.
public bool Equals(TextPosition other)
Parameters
other
TextPositionAn object to compare with this object.
Returns
- bool
True if the given position has the same values, otherwise false.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current instance.
Returns
- bool
True if the given object is a text position with the same values, otherwise false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
An integer that is the hash code for this instance.
Shift(int)
Returns a new text position that includes the given offset.
public TextPosition Shift(int columns)
Parameters
columns
intThe number of columns to shift.
Returns
- TextPosition
The new text position.
ToString()
Returns a string representation of the position in the text.
public override string ToString()
Returns
- string
A string that contains the contained line and column.
Operators
operator >(TextPosition, TextPosition)
Compares the two positions by their absolute positions in the text source.
public static bool operator >(TextPosition a, TextPosition b)
Parameters
a
TextPositionThe first operand.
b
TextPositionThe second operand.
Returns
- bool
True if the position of the first operand is greater than the second operand.
operator <(TextPosition, TextPosition)
Compares the two positions by their absolute positions in the text source.
public static bool operator <(TextPosition a, TextPosition b)
Parameters
a
TextPositionThe first operand.
b
TextPositionThe second operand.
Returns
- bool
True if the position of the first operand is less than the second operand.