Class Range

java.lang.Object
org.jsoup.nodes.Range

public class Range extends 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 with Parser.setTrackPosition(boolean).
Since:
1.15.2
See Also:
  • Field Details

    • start

      private final Range.Position start
    • end

      private final Range.Position end
    • RangeKey

      private static final String RangeKey
    • EndRangeKey

      private static final String EndRangeKey
    • UntrackedPos

      private static final Range.Position UntrackedPos
    • Untracked

      private static final Range Untracked
  • Constructor Details

    • 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 position
      end - the end position
  • Method Details

    • start

      public Range.Position start()
      Get the start position of this node.
      Returns:
      the start position
    • end

      public Range.Position end()
      Get the end position of this node.
      Returns:
      the end position
    • 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).
    • of

      static Range of(Node node, boolean start)
      Retrieves the source range for a given Node.
      Parameters:
      node - the node to retrieve the position for
      start - if this is the starting range. false for Element end tags.
      Returns:
      the Range, or the Untracked (-1) position if tracking is disabled.
    • track

      public void track(Node node, boolean start)
      Internal jsoup method, called by the TreeBuilder. Tracks a Range for a Node.
      Parameters:
      node - the node to associate this position to
      start - if this is the starting range. false for Element end tags.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Gets a String presentation of this Range, in the format line,column:pos-line,column:pos.
      Overrides:
      toString in class Object
      Returns:
      a String