Package org.jsoup.nodes
Class Range
- java.lang.Object
-
- org.jsoup.nodes.Range
-
public class Range extends java.lang.Object
A Range object tracks the character positions in the original input source where a Node starts or ends. If you want to track these positions, tracking must be enabled in the Parser withParser.setTrackPosition(boolean)
.- Since:
- 1.15.2
- See Also:
Node.sourceRange()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Range.AttributeRange
static class
Range.Position
A Position object tracks the character position in the original input source where a Node starts or ends.
-
Field Summary
Fields Modifier and Type Field Description private Range.Position
end
private Range.Position
start
(package private) static Range
Untracked
An untracked source range.private static Range.Position
UntrackedPos
-
Constructor Summary
Constructors Constructor Description Range(Range.Position start, Range.Position end)
Creates a new Range with start and end Positions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Range.Position
end()
Get the end position of this node.int
endPos()
Get the ending cursor position of this range.boolean
equals(java.lang.Object o)
int
hashCode()
boolean
isImplicit()
Checks if the range represents a node that was implicitly created / closed.boolean
isTracked()
Test if this source range was tracked during parsing.(package private) static Range
of(Node node, boolean start)
Retrieves the source range for a given Node.Range.Position
start()
Get the start position of this node.int
startPos()
Get the starting cursor position of this range.java.lang.String
toString()
Gets a String presentation of this Range, in the formatline,column:pos-line,column:pos
.
-
-
-
Field Detail
-
UntrackedPos
private static final Range.Position UntrackedPos
-
start
private final Range.Position start
-
end
private final Range.Position end
-
Untracked
static final Range Untracked
An untracked source range.
-
-
Constructor Detail
-
Range
public Range(Range.Position start, Range.Position end)
Creates a new Range with start and end Positions. Called by TreeBuilder when position tracking is on.- Parameters:
start
- the start positionend
- the end position
-
-
Method Detail
-
start
public Range.Position start()
Get the start position of this node.- Returns:
- the start position
-
startPos
public int startPos()
Get the starting cursor position of this range.- Returns:
- the 0-based start cursor position.
- Since:
- 1.17.1
-
end
public Range.Position end()
Get the end position of this node.- Returns:
- the end position
-
endPos
public int endPos()
Get the ending cursor position of this range.- Returns:
- the 0-based ending cursor position.
- Since:
- 1.17.1
-
isTracked
public boolean isTracked()
Test if this source range was tracked during parsing.- Returns:
- true if this was tracked during parsing, false otherwise (and all fields will be
-1
).
-
isImplicit
public boolean isImplicit()
Checks if the range represents a node that was implicitly created / closed.For example, with HTML of
<p>One<p>Two
, bothp
elements will have an explicitNode.sourceRange()
but an implicitElement.endSourceRange()
marking the end position, as neither have closing</p>
tags. The TextNodes will have explicit sourceRanges.A range is considered implicit if its start and end positions are the same.
- Returns:
- true if the range is tracked and its start and end positions are the same, false otherwise.
- Since:
- 1.17.1
-
of
static Range of(Node node, boolean start)
Retrieves the source range for a given Node.- Parameters:
node
- the node to retrieve the position forstart
- if this is the starting range.false
for Element end tags.- Returns:
- the Range, or the Untracked (-1) position if tracking is disabled.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Gets a String presentation of this Range, in the formatline,column:pos-line,column:pos
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String
-
-