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 Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static class 
    A Position describes a source offset and its line and column coordinates.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Use parser position tracking instead.
  • Method Summary

    Modifier and Type
    Method
    Description
    end()
    Get the end position of this range, with 1-based line and column coordinates.
    int
    Get the ending source offset of this range.
    boolean
    equals(Object o)
     
    int
     
    boolean
    Checks if the range represents a node that was implicitly created / closed.
    boolean
    Test if this range has source offsets available.
    Get the start position of this range, with 1-based line and column coordinates.
    int
    Get the starting source offset of this range.
    String
    Gets a String representation of this Range, in the format line,column:pos-line,column:pos.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Range

      @Deprecated public Range(Range.Position start, Range.Position end)
      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 position
      end - the end position
  • Method Details

    • start

      public Range.Position 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

      public Range.Position 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, both p elements will have an explicit Node.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:
      equals in class Object
    • hashCode

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

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