KTextEditor::LineRange

Search for usage in LXR

#include <KTextEditor/LineRange>

Public Member Functions

constexpr LineRange () noexcept=default
 
constexpr LineRange (int start, int end) noexcept
 
constexpr LineRange encompass (LineRange range) const noexcept
 
constexpr LineRange intersect (LineRange range) const noexcept
 
constexpr bool isValid () const noexcept
 
QString toString () const
 
Position

The following functions provide access to, and manipulation of, the range's position.

constexpr int start () const noexcept
 
constexpr int end () const noexcept
 
void setRange (LineRange range) noexcept
 
void setRange (int start, int end) noexcept
 
void setBothLines (int line) noexcept
 
void setStart (int start) noexcept
 
void setEnd (int end) noexcept
 
bool expandToRange (LineRange range) noexcept
 
bool confineToRange (LineRange range) noexcept
 
constexpr bool onSingleLine () const noexcept
 
constexpr int numberOfLines () const noexcept
 
Comparison

The following functions perform checks against this range in comparison to other lines and ranges.

constexpr bool contains (LineRange range) const noexcept
 
constexpr bool containsLine (int line) const noexcept
 
constexpr bool overlaps (LineRange range) const noexcept
 
constexpr bool overlapsLine (int line) const noexcept
 

Static Public Member Functions

static LineRange fromString (QStringView str) noexcept
 
static constexpr LineRange invalid () noexcept
 

Detailed Description

An object representing lines from a start line to an end line.

A LineRange is a basic class which represents a range of lines, from a start() line to an end() line.

For simplicity and convenience, ranges always maintain their start() line to be before or equal to their end() line. Attempting to set either the start or end of the range beyond the respective end or start will result in both values being set to the specified line. In the constructor, the start and end will be swapped if necessary.

See also
Range
Since
5.79
Author
Dominik Haumann <dhaum.nosp@m.ann@.nosp@m.kde.o.nosp@m.rg>

Definition at line 40 of file linerange.h.

Constructor & Destructor Documentation

◆ LineRange() [1/2]

KTextEditor::LineRange::LineRange ( )
constexprdefaultnoexcept

Default constructor.

Creates a valid line range with both start and end line set to 0.

◆ LineRange() [2/2]

KTextEditor::LineRange::LineRange ( int start,
int end )
inlineconstexprnoexcept

Constructor which creates a range from start to end.

If start is after end, they will be swapped.

Parameters
startstart line
endend line

Definition at line 56 of file linerange.h.

Member Function Documentation

◆ confineToRange()

bool KTextEditor::LineRange::confineToRange ( LineRange range)
inlinenoexcept

Confine this range if necessary to fit within range.

Parameters
rangerange which should contain this range
Returns
true if confinement occurred, false otherwise

Definition at line 221 of file linerange.h.

◆ contains()

bool KTextEditor::LineRange::contains ( LineRange range) const
inlineconstexprnoexcept

Check whether the this range wholly encompasses range.

Parameters
rangerange to check
Returns
true, if this range contains range, otherwise false

Definition at line 276 of file linerange.h.

◆ containsLine()

bool KTextEditor::LineRange::containsLine ( int line) const
inlineconstexprnoexcept

Returns true if this range wholly encompasses line.

Parameters
lineline to check
Returns
true if the line is wholly encompassed by this range, otherwise false.

Definition at line 288 of file linerange.h.

◆ encompass()

LineRange KTextEditor::LineRange::encompass ( LineRange range) const
inlineconstexprnoexcept

Returns the smallest range which encompasses this line range and the supplied range.

Parameters
rangeother range to encompass
Returns
the smallest range which contains this range and the supplied range.

Definition at line 341 of file linerange.h.

◆ end()

int KTextEditor::LineRange::end ( ) const
inlineconstexprnoexcept

Get the end line of this line range.

This will always be >= start().

Returns
the end line of this line range.

Definition at line 115 of file linerange.h.

◆ expandToRange()

bool KTextEditor::LineRange::expandToRange ( LineRange range)
inlinenoexcept

Expand this line range if necessary to contain range.

Parameters
rangerange which this range should contain
Returns
true if expansion occurred, false otherwise

Definition at line 197 of file linerange.h.

◆ fromString()

LineRange LineRange::fromString ( QStringView str)
staticnoexcept

Returns a LineRange created from the string str containing the format "[start line, end line]".

In case the string cannot be parsed, an LineRange::invalid() is returned.

See also
toString()

Definition at line 94 of file utils/range.cpp.

◆ intersect()

LineRange KTextEditor::LineRange::intersect ( LineRange range) const
inlineconstexprnoexcept

Intersects this line range with another, returning the shared lines of the two line ranges.

Parameters
rangeother line range to intersect with this
Returns
the intersection of this range and the supplied range.

Definition at line 327 of file linerange.h.

◆ invalid()

static constexpr LineRange KTextEditor::LineRange::invalid ( )
inlinestaticconstexprnoexcept

Returns an invalid line range.

Definition at line 73 of file linerange.h.

◆ isValid()

bool KTextEditor::LineRange::isValid ( ) const
inlineconstexprnoexcept

Validity check.

In the base class, returns true unless the line range starts before (0,0).

Definition at line 65 of file linerange.h.

◆ numberOfLines()

int KTextEditor::LineRange::numberOfLines ( ) const
inlineconstexprnoexcept

Returns the number of lines separating the start() and end() line.

Returns
the number of lines separating the start() and end() line; 0 if the start and end lines are the same.

Definition at line 254 of file linerange.h.

◆ onSingleLine()

bool KTextEditor::LineRange::onSingleLine ( ) const
inlineconstexprnoexcept

Check whether this line range is on one line.

Returns
true if both the start and end line are equal, otherwise false

Definition at line 243 of file linerange.h.

◆ overlaps()

bool KTextEditor::LineRange::overlaps ( LineRange range) const
inlineconstexprnoexcept

Check whether the this range overlaps with range.

Parameters
rangerange to check against
Returns
true, if this range overlaps with range, otherwise false

Definition at line 300 of file linerange.h.

◆ overlapsLine()

bool KTextEditor::LineRange::overlapsLine ( int line) const
inlineconstexprnoexcept

Check whether the range overlaps at least part of line.

Parameters
lineline to check
Returns
true, if the range overlaps at least part of line, otherwise false

Definition at line 312 of file linerange.h.

◆ setBothLines()

void KTextEditor::LineRange::setBothLines ( int line)
inlinenoexcept

Convenience function.

Set the start and end lines to line.

Parameters
linethe line number to assign to start() and end()

Definition at line 152 of file linerange.h.

◆ setEnd()

void KTextEditor::LineRange::setEnd ( int end)
inlinenoexcept

Set the end line to end.

Note
If end is in front of current start, start and end will be set to new end value.
Parameters
endnew end line

Definition at line 181 of file linerange.h.

◆ setRange() [1/2]

void KTextEditor::LineRange::setRange ( int start,
int end )
inlinenoexcept

Set the start and end lines to start and end respectively.

Note
If start is after end, they will be reversed.
Parameters
startstart line
endend line

Definition at line 141 of file linerange.h.

◆ setRange() [2/2]

void KTextEditor::LineRange::setRange ( LineRange range)
inlinenoexcept

Set the start and end lines to start and end respectively.

Note
If start is after end, they will be reversed.
Parameters
startstart line
endend line

Definition at line 128 of file linerange.h.

◆ setStart()

void KTextEditor::LineRange::setStart ( int start)
inlinenoexcept

Set the start line to start.

Note
If start is after current end, start and end will be set to new start value.
Parameters
startnew start line

Definition at line 165 of file linerange.h.

◆ start()

int KTextEditor::LineRange::start ( ) const
inlineconstexprnoexcept

Get the start line of this line range.

This will always be <= end().

Returns
the start line of this line range.

Definition at line 105 of file linerange.h.

◆ toString()

QString LineRange::toString ( ) const

Returns the line range as string in the format "[start line, end line]".

See also
fromString()

Definition at line 145 of file utils/range.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.