Package org.commonmark.node
Class SourceSpan
- java.lang.Object
-
- org.commonmark.node.SourceSpan
-
public class SourceSpan extends java.lang.ObjectA 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:
The> fooBlockQuotenode would have this source span: line 0, column 0, length 5.The
Paragraphnode 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
Fields Modifier and Type Field Description private intcolumnIndexprivate intinputIndexprivate intlengthprivate intlineIndex
-
Constructor Summary
Constructors Modifier Constructor Description privateSourceSpan(int lineIndex, int columnIndex, int inputIndex, int length)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object o)intgetColumnIndex()intgetInputIndex()intgetLength()intgetLineIndex()inthashCode()static SourceSpanof(int lineIndex, int columnIndex, int length)Deprecated.Use {of(int, int, int, int)} instead to also specify input index.static SourceSpanof(int line, int col, int input, int length)SourceSpansubSpan(int beginIndex)SourceSpansubSpan(int beginIndex, int endIndex)java.lang.StringtoString()
-
-
-
Method Detail
-
of
public static SourceSpan of(int line, int col, int input, int length)
-
of
@Deprecated public static SourceSpan of(int lineIndex, int columnIndex, int length)
Deprecated.Use {of(int, int, int, int)} instead to also specify input index. Using the deprecated one will setinputIndexto 0.
-
getLineIndex
public int getLineIndex()
- Returns:
- 0-based line index, e.g. 0 for first line, 1 for the second line, etc
-
getColumnIndex
public int getColumnIndex()
- Returns:
- 0-based index of column (character on line) in source, e.g. 0 for the first character of a line, 1 for the second character, etc
-
getInputIndex
public int getInputIndex()
- Returns:
- 0-based index in whole input
- Since:
- 0.24.0
-
getLength
public int getLength()
- Returns:
- length of the span in characters
-
subSpan
public SourceSpan subSpan(int beginIndex)
-
subSpan
public SourceSpan subSpan(int beginIndex, int endIndex)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-