Skip to content

Text Slice

Source code in pbi_parsers/base/tokens.py
@dataclass
class TextSlice:
    full_text: str = ""
    start: int = -1
    end: int = -1

    def __eq__(self, other: object) -> bool:
        """Checks equality based on the text slice."""
        if not isinstance(other, TextSlice):
            return NotImplemented
        return self.full_text == other.full_text and self.start == other.start and self.end == other.end

    def __hash__(self) -> int:
        """Returns a hash based on the text slice."""
        return hash((self.full_text, self.start, self.end))

    def __repr__(self) -> str:
        """Returns a string representation of the TextSlice."""
        return f"TextSlice(text='{self.get_text()}', start={self.start}, end={self.end})"

    def get_text(self) -> str:
        """Returns the text slice."""
        return self.full_text[self.start : self.end]

__eq__

__eq__(other: object) -> bool

Checks equality based on the text slice.

Source code in pbi_parsers/base/tokens.py
def __eq__(self, other: object) -> bool:
    """Checks equality based on the text slice."""
    if not isinstance(other, TextSlice):
        return NotImplemented
    return self.full_text == other.full_text and self.start == other.start and self.end == other.end

__hash__

__hash__() -> int

Returns a hash based on the text slice.

Source code in pbi_parsers/base/tokens.py
def __hash__(self) -> int:
    """Returns a hash based on the text slice."""
    return hash((self.full_text, self.start, self.end))

__repr__

__repr__() -> str

Returns a string representation of the TextSlice.

Source code in pbi_parsers/base/tokens.py
def __repr__(self) -> str:
    """Returns a string representation of the TextSlice."""
    return f"TextSlice(text='{self.get_text()}', start={self.start}, end={self.end})"

get_text

get_text() -> str

Returns the text slice.

Source code in pbi_parsers/base/tokens.py
def get_text(self) -> str:
    """Returns the text slice."""
    return self.full_text[self.start : self.end]