KTextEditor::Range

Search for usage in LXR

#include <KTextEditor/Range>

Public Member Functions

constexpr Range () Q_DECL_NOEXCEPT
 
constexpr Range (const Cursor &start, const Cursor &end) Q_DECL_NOEXCEPT
 
constexpr Range (const Cursor &start, int width) Q_DECL_NOEXCEPT
 
constexpr Range (const Cursor &start, int endLine, int endColumn) Q_DECL_NOEXCEPT
 
constexpr Range (int startLine, int startColumn, int endLine, int endColumn) Q_DECL_NOEXCEPT
 
constexpr Range encompass (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr Range intersect (const Range &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 Cursor start () const Q_DECL_NOEXCEPT
 
constexpr Cursor end () const Q_DECL_NOEXCEPT
 
constexpr LineRange toLineRange () const Q_DECL_NOEXCEPT
 
void setBothLines (int line) Q_DECL_NOEXCEPT
 
void setBothColumns (int column) Q_DECL_NOEXCEPT
 
void setRange (const Range &range) Q_DECL_NOEXCEPT
 
void setRange (const Cursor &start, const Cursor &end) Q_DECL_NOEXCEPT
 
void setStart (const Cursor &start) Q_DECL_NOEXCEPT
 
void setEnd (const Cursor &end) Q_DECL_NOEXCEPT
 
bool expandToRange (const Range &range) Q_DECL_NOEXCEPT
 
bool confineToRange (const Range &range) Q_DECL_NOEXCEPT
 
constexpr bool onSingleLine () const Q_DECL_NOEXCEPT
 
constexpr int numberOfLines () const Q_DECL_NOEXCEPT
 
constexpr int columnWidth () const Q_DECL_NOEXCEPT
 
constexpr bool isEmpty () const Q_DECL_NOEXCEPT
 
Comparison

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

constexpr bool contains (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr bool contains (const Cursor &cursor) const Q_DECL_NOEXCEPT
 
constexpr bool containsLine (int line) const Q_DECL_NOEXCEPT
 
constexpr bool containsColumn (int column) const Q_DECL_NOEXCEPT
 
constexpr bool overlaps (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr bool overlapsLine (int line) const Q_DECL_NOEXCEPT
 
constexpr bool overlapsColumn (int column) const Q_DECL_NOEXCEPT
 
constexpr bool boundaryAtCursor (const Cursor &cursor) const Q_DECL_NOEXCEPT
 

Static Public Member Functions

static Range fromString (const QString &str) Q_DECL_NOEXCEPT
 
static Range fromString (const QStringRef &str) Q_DECL_NOEXCEPT
 
static Range fromString (QStringView str) Q_DECL_NOEXCEPT
 
static constexpr Range invalid () Q_DECL_NOEXCEPT
 

Friends

constexpr friend bool operator!= (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
constexpr friend Range operator& (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
Rangeoperator&= (Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
constexpr friend Range operator+ (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
Rangeoperator+= (Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
constexpr friend Range operator- (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
Rangeoperator-= (Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
constexpr friend bool operator< (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
QDebug operator<< (QDebug s, const Range &range)
 
constexpr friend bool operator== (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 
constexpr friend bool operator> (const Range &r1, const Range &r2) Q_DECL_NOEXCEPT
 

Detailed Description

An object representing a section of text, from one Cursor to another.

A Range is a basic class which represents a range of text with two Cursors, from a start() position to an end() position.

For simplicity and convenience, ranges always maintain their start position to be before or equal to their end position. 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 position. In the constructor, the start and end will be swapped if necessary.

If you want additional functionality such as the ability to maintain position in a document, see MovingRange.

See also
MovingRange
Author
Hamish Rodda <rodda[email protected]@kde[email protected].org>

Definition at line 44 of file include/ktexteditor/range.h.

Constructor & Destructor Documentation

constexpr KTextEditor::Range::Range ( )
inline

Default constructor.

Creates a valid range from position (0, 0) to position (0, 0).

Definition at line 51 of file include/ktexteditor/range.h.

constexpr KTextEditor::Range::Range ( const Cursor start,
const Cursor end 
)
inline

Constructor which creates a range from start to end.

If start is after end, they will be swapped.

Parameters
startstart position
endend position

Definition at line 62 of file include/ktexteditor/range.h.

constexpr KTextEditor::Range::Range ( const Cursor start,
int  width 
)
inline

Constructor which creates a single-line range from start, extending width characters along the same line.

Parameters
startstart position
widthwidth of this range in columns along the same line

Definition at line 73 of file include/ktexteditor/range.h.

constexpr KTextEditor::Range::Range ( const Cursor start,
int  endLine,
int  endColumn 
)
inline

Constructor which creates a range from start, to endLine, endColumn.

Parameters
startstart position
endLineend line
endColumnend column

Definition at line 85 of file include/ktexteditor/range.h.

constexpr KTextEditor::Range::Range ( int  startLine,
int  startColumn,
int  endLine,
int  endColumn 
)
inline

Constructor which creates a range from startLine, startColumn to endLine, endColumn.

Parameters
startLinestart line
startColumnstart column
endLineend line
endColumnend column

Definition at line 98 of file include/ktexteditor/range.h.

Member Function Documentation

constexpr bool KTextEditor::Range::boundaryAtCursor ( const Cursor cursor) const
inline

Check whether cursor is located at either of the start() or end() boundaries.

Parameters
cursorcursor to check
Returns
true if the cursor is equal to start() or end(), otherwise false.

Definition at line 430 of file include/ktexteditor/range.h.

constexpr int KTextEditor::Range::columnWidth ( ) const
inline

Returns the number of columns separating the start() and end() positions.

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

Definition at line 308 of file include/ktexteditor/range.h.

bool Range::confineToRange ( const Range range)

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

constexpr bool KTextEditor::Range::contains ( const Range 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 341 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::contains ( const Cursor cursor) const
inline

Check to see if cursor is contained within this range, ie >= start() and < end().

Parameters
cursorthe position to test for containment
Returns
true if the cursor is contained within this range, otherwise false.

Definition at line 353 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::containsColumn ( int  column) const
inline

Check whether the range contains column.

Parameters
columncolumn to check
Returns
true if the range contains column, otherwise false

Definition at line 377 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::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 365 of file include/ktexteditor/range.h.

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

Returns the smallest range which encompasses this 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 458 of file include/ktexteditor/range.h.

constexpr Cursor KTextEditor::Range::end ( ) const
inline

Get the end position of this range.

This will always be >= start().

Returns
const reference to the end position of this range.

Definition at line 181 of file include/ktexteditor/range.h.

bool Range::expandToRange ( const Range range)

Expand this range if necessary to contain range.

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

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

static Range KTextEditor::Range::fromString ( const QString str)
inlinestatic

Returns a Range created from the string str containing the format "[(start-line, start-column), (endl-line:end-column)]".

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

See also
toString()

Definition at line 137 of file include/ktexteditor/range.h.

static Range KTextEditor::Range::fromString ( const QStringRef str)
static

Returns a Range created from the string str containing the format "[(start-line, start-column), (endl-line:end-column)]".

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

See also
toString()
static Range KTextEditor::Range::fromString ( QStringView  str)
static

Returns a Range created from the string str containing the format "[(start-line, start-column), (endl-line:end-column)]".

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

See also
toString()
constexpr Range KTextEditor::Range::intersect ( const Range range) const
inline

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

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

Definition at line 445 of file include/ktexteditor/range.h.

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

Returns an invalid range.

Definition at line 115 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::isEmpty ( ) const
inline

Returns true if this range contains no characters, ie.

the start() and end() positions are the same.

Returns
true if the range contains no characters, otherwise false

Definition at line 319 of file include/ktexteditor/range.h.

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

Validity check.

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

Definition at line 107 of file include/ktexteditor/range.h.

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

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

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

Definition at line 297 of file include/ktexteditor/range.h.

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

Check whether this range is wholly contained within one line, ie.

if the start() and end() positions are on the same line.

Returns
true if both the start and end positions are on the same line, otherwise false

Definition at line 286 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::overlaps ( const Range 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 389 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::overlapsColumn ( int  column) const
inline

Check to see if this range overlaps column; that is, if column is between start().column() and end().column().

This function is most likely to be useful in relation to block text editing.

Parameters
columnthe column to test
Returns
true if the column is between the range's starting and ending columns, otherwise false.

Definition at line 416 of file include/ktexteditor/range.h.

constexpr bool KTextEditor::Range::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 401 of file include/ktexteditor/range.h.

void KTextEditor::Range::setBothColumns ( int  column)

Convenience function.

Set the start and end columns to column.

Parameters
columnthe column number to assign to start() and end()

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

void Range::setBothLines ( int  line)

Convenience function.

Set the start and end lines to line.

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

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

void KTextEditor::Range::setEnd ( const Cursor end)
inline

Set the end cursor to end.

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

Definition at line 252 of file include/ktexteditor/range.h.

void KTextEditor::Range::setRange ( const Range range)

Set the start and end cursors to range.start() and range.end() respectively.

Parameters
rangerange to assign to this range
void KTextEditor::Range::setRange ( const Cursor start,
const Cursor end 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Note
If start is after end, they will be reversed.
Parameters
startstart cursor
endend cursor
void KTextEditor::Range::setStart ( const Cursor start)
inline

Set the start cursor to start.

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

Definition at line 236 of file include/ktexteditor/range.h.

constexpr Cursor KTextEditor::Range::start ( ) const
inline

Get the start position of this range.

This will always be <= end().

Returns
const reference to the start position of this range.

Definition at line 171 of file include/ktexteditor/range.h.

constexpr LineRange KTextEditor::Range::toLineRange ( ) const
inline

Convert this Range to a LineRange.

Returns
LineRange from the start line to the end line of this range.

Definition at line 191 of file include/ktexteditor/range.h.

QString KTextEditor::Range::toString ( ) const
inline

Returns the cursor position as string in the format "start-line:start-column,endl-line:end-column".

See also
fromString()

Definition at line 125 of file include/ktexteditor/range.h.

Friends And Related Function Documentation

constexpr friend bool operator!= ( const Range r1,
const Range 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 567 of file include/ktexteditor/range.h.

constexpr friend Range operator& ( const Range r1,
const Range 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 527 of file include/ktexteditor/range.h.

Range& operator&= ( Range r1,
const Range 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 540 of file include/ktexteditor/range.h.

constexpr friend Range operator+ ( const Range r1,
const Range 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 472 of file include/ktexteditor/range.h.

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

Addition assignment operator.

Adds r2 to this range.

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

Definition at line 485 of file include/ktexteditor/range.h.

constexpr friend Range operator- ( const Range r1,
const Range 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 500 of file include/ktexteditor/range.h.

Range& operator-= ( Range r1,
const Range 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 513 of file include/ktexteditor/range.h.

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

Less than operator.

Looks only at the position 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 595 of file include/ktexteditor/range.h.

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

qDebug() stream operator.

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

Definition at line 603 of file include/ktexteditor/range.h.

constexpr friend bool operator== ( const Range r1,
const Range 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 554 of file include/ktexteditor/range.h.

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

Greater than operator.

Looks only at the position 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 581 of file include/ktexteditor/range.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 Sat Oct 23 2021 22:57:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.