KTextEditor::Range

Search for usage in LXR

#include <KTextEditor/Range>

Public Member Functions

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

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

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

Static Public Member Functions

static Range fromString (QStringView str) noexcept
 
static constexpr Range invalid () 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.nosp@m.@kde.nosp@m..org>

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

Constructor & Destructor Documentation

◆ Range() [1/5]

KTextEditor::Range::Range ( )
constexprdefaultnoexcept

Default constructor.

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

◆ Range() [2/5]

KTextEditor::Range::Range ( Cursor start,
Cursor end )
inlineconstexprnoexcept

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 64 of file include/ktexteditor/range.h.

◆ Range() [3/5]

KTextEditor::Range::Range ( Cursor start,
int width )
inlineconstexprnoexcept

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 77 of file include/ktexteditor/range.h.

◆ Range() [4/5]

KTextEditor::Range::Range ( Cursor start,
int endLine,
int endColumn )
inlineconstexprnoexcept

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

Parameters
startstart position
endLineend line
endColumnend column

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

◆ Range() [5/5]

KTextEditor::Range::Range ( int startLine,
int startColumn,
int endLine,
int endColumn )
inlineconstexprnoexcept

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

Parameters
startLinestart line
startColumnstart column
endLineend line
endColumnend column

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

Member Function Documentation

◆ boundaryAtCursor()

bool KTextEditor::Range::boundaryAtCursor ( Cursor cursor) const
inlineconstexprnoexcept

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 412 of file include/ktexteditor/range.h.

◆ columnWidth()

int KTextEditor::Range::columnWidth ( ) const
inlineconstexprnoexcept

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 290 of file include/ktexteditor/range.h.

◆ confineToRange()

bool Range::confineToRange ( Range range)
noexcept

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.

◆ contains() [1/2]

bool KTextEditor::Range::contains ( Cursor cursor) const
inlineconstexprnoexcept

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 335 of file include/ktexteditor/range.h.

◆ contains() [2/2]

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

◆ containsColumn()

bool KTextEditor::Range::containsColumn ( int column) const
inlineconstexprnoexcept

Check whether the range contains column.

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

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

◆ containsLine()

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

◆ encompass()

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

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 440 of file include/ktexteditor/range.h.

◆ end()

Cursor KTextEditor::Range::end ( ) const
inlineconstexprnoexcept

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 163 of file include/ktexteditor/range.h.

◆ expandToRange()

bool Range::expandToRange ( Range range)
noexcept

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.

◆ fromString()

Range Range::fromString ( QStringView str)
staticnoexcept

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

◆ intersect()

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

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 427 of file include/ktexteditor/range.h.

◆ invalid()

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

Returns an invalid range.

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

◆ isEmpty()

bool KTextEditor::Range::isEmpty ( ) const
inlineconstexprnoexcept

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 301 of file include/ktexteditor/range.h.

◆ isValid()

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

Validity check.

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

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

◆ numberOfLines()

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

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 279 of file include/ktexteditor/range.h.

◆ onSingleLine()

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

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 268 of file include/ktexteditor/range.h.

◆ overlaps()

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

◆ overlapsColumn()

bool KTextEditor::Range::overlapsColumn ( int column) const
inlineconstexprnoexcept

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 398 of file include/ktexteditor/range.h.

◆ overlapsLine()

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

◆ setBothColumns()

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

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.

◆ setBothLines()

void Range::setBothLines ( int line)
noexcept

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.

◆ setEnd()

void KTextEditor::Range::setEnd ( Cursor end)
inlinenoexcept

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 234 of file include/ktexteditor/range.h.

◆ setRange() [1/2]

void Range::setRange ( Cursor start,
Cursor end )
noexcept

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

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

◆ setRange() [2/2]

void Range::setRange ( Range range)
noexcept

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

Parameters
rangerange to assign to this range

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

◆ setStart()

void KTextEditor::Range::setStart ( Cursor start)
inlinenoexcept

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 218 of file include/ktexteditor/range.h.

◆ start()

Cursor KTextEditor::Range::start ( ) const
inlineconstexprnoexcept

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 153 of file include/ktexteditor/range.h.

◆ toLineRange()

LineRange KTextEditor::Range::toLineRange ( ) const
inlineconstexprnoexcept

Convert this Range to a LineRange.

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

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

◆ toString()

QString Range::toString ( ) const

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

See also
fromString()

Definition at line 140 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 Mon Nov 18 2024 12:11:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.