Package org.commonmark.node
Class SourceSpan
java.lang.Object
org.commonmark.node.SourceSpan
A source span references a snippet of text from the source input.
It has a starting position (line and column index) and a length of how many characters it spans.
For example, this CommonMark source text:
> foo
The BlockQuote
node would have this source span: line 0, column 0, length 5.
The Paragraph
node inside it would have: line 0, column 2, length 3.
If a block has multiple lines, it will have a source span for each line.
Note that the column index and length are measured in Java characters (UTF-16 code units). If you're outputting them to be consumed by another programming language, e.g. one that uses UTF-8 strings, you will need to translate them, otherwise characters such as emojis will result in incorrect positions.
- Since:
- 0.16.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
private final int
private final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
int
int
int
hashCode()
static SourceSpan
of
(int lineIndex, int columnIndex, int length) toString()
-
Field Details
-
lineIndex
private final int lineIndex -
columnIndex
private final int columnIndex -
length
private final int length
-
-
Constructor Details
-
SourceSpan
private SourceSpan(int lineIndex, int columnIndex, int length)
-
-
Method Details
-
of
-
getLineIndex
public int getLineIndex()- Returns:
- 0-based index of line in source
-
getColumnIndex
public int getColumnIndex()- Returns:
- 0-based index of column (character on line) in source
-
getLength
public int getLength()- Returns:
- length of the span in characters
-
equals
-
hashCode
public int hashCode() -
toString
-