diff options
author | Neil <nyamatongwe@gmail.com> | 2023-10-26 13:44:13 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-10-26 13:44:13 +1100 |
commit | 8f42bb51d6445602027d8c68d6c6f225f6536c68 (patch) | |
tree | 076c344e247f686086090738356df63b60f0056d /src/CellBuffer.cxx | |
parent | fdbb5c9273a8f25f86f4113b837926f883083b23 (diff) | |
download | scintilla-mirror-8f42bb51d6445602027d8c68d6c6f225f6536c68.tar.gz |
Implement LineEnd method in CellBuffer as it is a basic function and only uses
CellBuffer fields.
Declare LineEnd noexcept as it should never throw and that allows methods
calling it to also be noexcept.
Call LineEndPosition to simplify Editor::LineSelectionRange.
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r-- | src/CellBuffer.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index ba11f1391..4b061db40 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -848,6 +848,33 @@ Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept { return plv->LineStart(line); } +Sci::Position CellBuffer::LineEnd(Sci::Line line) const noexcept { + if (line >= Lines() - 1) { + return LineStart(line + 1); + } else { + Sci::Position position = LineStart(line + 1); + if (LineEndType::Unicode == GetLineEndTypes()) { + const unsigned char bytes[] = { + UCharAt(position - 3), + UCharAt(position - 2), + UCharAt(position - 1), + }; + if (UTF8IsSeparator(bytes)) { + return position - UTF8SeparatorLength; + } + if (UTF8IsNEL(bytes + 1)) { + return position - UTF8NELLength; + } + } + position--; // Back over CR or LF + // When line terminator is CR+LF, may need to go back one more + if ((position > LineStart(line)) && (CharAt(position - 1) == '\r')) { + position--; + } + return position; + } +} + Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const noexcept { return plv->LineFromPosition(pos); } |