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
 
static constexpr LineRange invalid () Q_DECL_NOEXCEPT
 

Friends

constexpr friend bool operator!= (const LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
constexpr friend LineRange operator& (const LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
LineRangeoperator&= (LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
constexpr friend LineRange operator+ (const LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
LineRangeoperator+= (LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
constexpr friend LineRange operator- (const LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
LineRangeoperator-= (LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
constexpr friend bool operator< (const LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
QDebug operator<< (QDebug s, const LineRange &range)
 
constexpr friend bool operator== (const LineRange &r1, const LineRange &r2) Q_DECL_NOEXCEPT
 
constexpr friend bool operator> (const LineRange &r1, const LineRange &r2) 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

constexpr KTextEditor::LineRange::LineRange ( )
inline

Default constructor.

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

Definition at line 44 of file linerange.h.

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

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

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.

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

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.

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

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.

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

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.

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

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.

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.

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

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

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.

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

Returns an invalid line range.

Definition at line 70 of file linerange.h.

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

Validity check.

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

Definition at line 62 of file linerange.h.

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

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.

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

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.

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

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.

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

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.

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.

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.

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.

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.

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.

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

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.

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.

Friends And Related Function Documentation

constexpr friend bool operator!= ( const LineRange r1,
const LineRange r2 
)
friend

Inequality operator.

Parameters
r1first range to compare
r2second range to compare
Returns
true if r1 and r2 do not equal, otherwise false

Definition at line 450 of file linerange.h.

constexpr friend LineRange operator& ( const LineRange r1,
const LineRange r2 
)
friend

Intersects r1 and r2.

Parameters
r1the first range
r2the second range
Returns
the intersected range, invalid() if there is no overlap

Definition at line 410 of file linerange.h.

LineRange& operator&= ( LineRange r1,
const LineRange r2 
)
friend

Intersects r1 with r2 and assigns the result to r1.

Parameters
r1the range to assign the intersection to
r2the range to intersect r1 with
Returns
a reference to this range, after the intersection has taken place

Definition at line 423 of file linerange.h.

constexpr friend LineRange operator+ ( const LineRange r1,
const LineRange r2 
)
friend

Addition operator.

Takes two ranges and returns their summation.

Parameters
r1the first range
r2the second range
Returns
a the summation of the two input ranges

Definition at line 355 of file linerange.h.

LineRange& operator+= ( LineRange r1,
const LineRange r2 
)
friend

Addition assignment operator.

Adds r2 to this range.

Parameters
r1the first range
r2the second range
Returns
a reference to the line range which has just been added to

Definition at line 368 of file linerange.h.

constexpr friend LineRange operator- ( const LineRange r1,
const LineRange r2 
)
friend

Subtraction operator.

Takes two ranges and returns the subtraction of r2 from r1.

Parameters
r1the first range
r2the second range
Returns
a range representing the subtraction of r2 from r1

Definition at line 383 of file linerange.h.

LineRange& operator-= ( LineRange r1,
const LineRange r2 
)
friend

Subtraction assignment operator.

Subtracts r2 from r1.

Parameters
r1the first range
r2the second range
Returns
a reference to the range which has just been subtracted from

Definition at line 396 of file linerange.h.

constexpr friend bool operator< ( const LineRange r1,
const LineRange r2 
)
friend

Less than operator.

Looks only at the lines of the two ranges, does not consider their size.

Parameters
r1first range to compare
r2second range to compare
Returns
true if r1 ends before r2 begins, otherwise false

Definition at line 478 of file linerange.h.

QDebug operator<< ( QDebug  s,
const LineRange range 
)
friend

qDebug() stream operator.

Writes this range to the debug output in a nicely formatted way.

Definition at line 486 of file linerange.h.

constexpr friend bool operator== ( const LineRange r1,
const LineRange r2 
)
friend

Equality operator.

Parameters
r1first range to compare
r2second range to compare
Returns
true if r1 and r2 equal, otherwise false

Definition at line 437 of file linerange.h.

constexpr friend bool operator> ( const LineRange r1,
const LineRange r2 
)
friend

Greater than operator.

Looks only at the lines of the two ranges, does not consider their size.

Parameters
r1first range to compare
r2second range to compare
Returns
true if r1 starts after where r2 ends, otherwise false

Definition at line 464 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-2021 The KDE developers.
Generated on Tue Jul 27 2021 22:58:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.