Package org.jsoup.nodes
Class Range
java.lang.Object
org.jsoup.nodes.Range
public class Range
extends Object
A Range tracks the source offsets where a Node starts or ends. Line and column coordinates are derived from the
line map retained during parsing. To track these positions, enable
Parser.setTrackPosition( boolean)
before parsing.- Since:
- 1.15.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classA Position describes a source offset and its line and column coordinates. -
Constructor Summary
ConstructorsConstructorDescriptionRange(Range.Position start, Range.Position end) Deprecated.Use parser position tracking instead. -
Method Summary
Modifier and TypeMethodDescriptionend()Get the end position of this range, with 1-based line and column coordinates.intendPos()Get the ending source offset of this range.booleanequals(Object o) inthashCode()booleanChecks if the range represents a node that was implicitly created / closed.booleanTest if this range has source offsets available.start()Get the start position of this range, with 1-based line and column coordinates.intstartPos()Get the starting source offset of this range.StringtoString()Gets a String representation of this Range, in the formatline,column:pos-line,column:pos.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Range
Deprecated.Use parser position tracking instead. Will be removed in jsoup 1.24.1.Deprecated parser-internal source range setup method, retained for source compatibility. The line and column values in the supplied Positions are not retained; they are derived from source offsets. If either supplied Position is untracked, this Range will also be untracked.- Parameters:
start- the start positionend- the end position
-
-
Method Details
-
start
Get the start position of this range, with 1-based line and column coordinates.- Returns:
- the start position.
-
startPos
public int startPos()Get the starting source offset of this range.- Returns:
- the 0-based start source offset.
- Since:
- 1.17.1
-
end
Get the end position of this range, with 1-based line and column coordinates.- Returns:
- the end position.
-
endPos
public int endPos()Get the ending source offset of this range.- Returns:
- the 0-based ending source offset.
- Since:
- 1.17.1
-
isTracked
public boolean isTracked()Test if this range has source offsets available.- Returns:
- true if this range has source offsets, 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, bothpelements will have an explicitNode.sourceRange(but an implicit) Element.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
-
equals
public boolean equals(Object o) - Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Overrides:
hashCodein classObject
-
toString
public String toString()Gets a String representation of this Range, in the formatline,column:pos-line,column:pos.- Overrides:
toStringin classObject- Returns:
- a String
-