KTextEditor::LineRange

Search for usage in LXR

#include <KTextEditor/LineRange>

Public Member Functions

constexpr LineRange () Q_DECL_NOEXCEPT
 
constexpr LineRange (int start, int end) Q_DECL_NOEXCEPT
 
constexpr LineRange encompass (const LineRange &range) const Q_DECL_NOEXCEPT
 
constexpr LineRange intersect (const LineRange &range) const Q_DECL_NOEXCEPT
 
constexpr bool isValid () const Q_DECL_NOEXCEPT
 
QString toString () const
 
Position

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

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

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

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

Static Public Member Functions

static LineRange fromString (QStringView str) Q_DECL_NOEXCEPT
 
constexpr static LineRange invalid () Q_DECL_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[email protected][email protected][email protected]kde.o[email protected]rg>

Definition at line 37 of file linerange.h.

Constructor & Destructor Documentation

◆ LineRange() [1/2]

constexpr KTextEditor::LineRange::LineRange ( )
inlineconstexpr

Default constructor.

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

Definition at line 44 of file linerange.h.

◆ LineRange() [2/2]

constexpr KTextEditor::LineRange::LineRange ( int  start,
int  end 
)
inlineconstexpr

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 55 of file linerange.h.

Member Function Documentation

◆ confineToRange()

bool KTextEditor::LineRange::confineToRange ( const LineRange range)
inline

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()

constexpr bool KTextEditor::LineRange::contains ( const LineRange range) const
inlineconstexpr

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()

constexpr bool KTextEditor::LineRange::containsLine ( int  line) const
inlineconstexpr

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()

constexpr LineRange KTextEditor::LineRange::encompass ( const LineRange range) const
inlineconstexpr

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()

constexpr int KTextEditor::LineRange::end ( ) const
inlineconstexpr

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 ( const LineRange range)
inline

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)
static

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 96 of file utils/range.cpp.

◆ intersect()

constexpr LineRange KTextEditor::LineRange::intersect ( const LineRange range) const
inlineconstexpr

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()

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

Returns an invalid line range.

Definition at line 70 of file linerange.h.

◆ isValid()

constexpr bool KTextEditor::LineRange::isValid ( ) const
inlineconstexpr

Validity check.

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

Definition at line 62 of file linerange.h.

◆ numberOfLines()

constexpr int KTextEditor::LineRange::numberOfLines ( ) const
inlineconstexpr

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()

constexpr bool KTextEditor::LineRange::onSingleLine ( ) const
inlineconstexpr

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()

constexpr bool KTextEditor::LineRange::overlaps ( const LineRange range) const
inlineconstexpr

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()

constexpr bool KTextEditor::LineRange::overlapsLine ( int  line) const
inlineconstexpr

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)
inline

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)
inline

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 ( const LineRange range)
inline

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.

◆ setRange() [2/2]

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

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.

◆ setStart()

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

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()

constexpr int KTextEditor::LineRange::start ( ) const
inlineconstexpr

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 KTextEditor::LineRange::toString ( ) const
inline

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

See also
fromString()

Definition at line 80 of file linerange.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:50:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.