aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Document.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Document.cxx')
-rw-r--r--src/Document.cxx52
1 files changed, 27 insertions, 25 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 458c1e93f..289fb6731 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -530,6 +530,13 @@ void SCI_METHOD Document::SetErrorStatus(int status) {
}
}
+void Document::CheckPosition(Sci::Position pos) const {
+ PLATFORM_ASSERT((pos >= 0) && (pos <= LengthNoExcept()));
+ if ((pos < 0) || (pos > LengthNoExcept())) {
+ throw Failure(Status::OutsideDocument);
+ }
+}
+
Sci_Position SCI_METHOD Document::LineFromPosition(Sci_Position pos) const {
return cb.LineFromPosition(pos);
}
@@ -1485,6 +1492,7 @@ Sci::Position Document::InsertString(Sci::Position position, const char *s, Sci:
if (insertLength <= 0) {
return 0;
}
+ CheckPosition(position);
CheckReadOnly(); // Application may change read only state here
if (cb.IsReadOnly()) {
return 0;
@@ -1907,8 +1915,7 @@ std::string Document::TransformLineEnds(const char *s, size_t len, EndOfLine eol
void Document::ConvertLineEnds(EndOfLine eolModeSet) {
UndoGroup ug(this);
- const Sci::Position length = Length();
- for (Sci::Position pos = 0; pos < length; pos++) {
+ for (Sci::Position pos = 0; pos < LengthNoExcept(); pos++) {
const char ch = cb.CharAt(pos);
if (ch == '\r') {
if (cb.CharAt(pos + 1) == '\n') {
@@ -2572,10 +2579,10 @@ bool SCI_METHOD Document::SetStyleFor(Sci_Position length, char style) {
return false;
}
enteredStyling++;
- const Sci::Position prevEndStyled = endStyled;
- if (cb.SetStyleFor(endStyled, length, style)) {
+ const ChangedRange cr = cb.SetStyleFor(endStyled, length, style);
+ if (!cr.Empty()) {
const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User,
- prevEndStyled, length);
+ cr.start, cr.end - cr.start + 1);
NotifyModified(mh);
}
endStyled += length;
@@ -2588,22 +2595,11 @@ bool SCI_METHOD Document::SetStyles(Sci_Position length, const char *styles) {
return false;
}
enteredStyling++;
- bool didChange = false;
- Sci::Position startMod = 0;
- Sci::Position endMod = 0;
- for (int iPos = 0; iPos < length; iPos++, endStyled++) {
- PLATFORM_ASSERT(endStyled < Length());
- if (cb.SetStyleAt(endStyled, styles[iPos])) {
- if (!didChange) {
- startMod = endStyled;
- }
- didChange = true;
- endMod = endStyled;
- }
- }
- if (didChange) {
+ const ChangedRange cr = cb.SetStyles(endStyled, styles, length);
+ endStyled += length;
+ if (!cr.Empty()) {
const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User,
- startMod, endMod - startMod + 1);
+ cr.start, cr.end - cr.start + 1);
NotifyModified(mh);
}
enteredStyling--;
@@ -3022,7 +3018,7 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe
return -1;
const int styBrace = StyleIndexAt(position);
int direction = -1;
- if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<')
+ if (AnyOf(chBrace, '(', '[', '{', '<'))
direction = 1;
int depth = 1;
position = useStartPos ? startPos : position + direction;
@@ -3035,7 +3031,7 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe
while ((position >= 0) && (position < LengthNoExcept())) {
const unsigned char chAtPos = CharAt(position);
- if (chAtPos == chBrace || chAtPos == chSeek) {
+ if (AnyOf(chAtPos, chBrace, chSeek)) {
if (((position > GetEndStyled()) || (StyleIndexAt(position) == styBrace)) &&
(chAtPos <= maxSafeChar || position == MovePositionOutsideChar(position, direction, false))) {
depth += (chAtPos == chBrace) ? 1 : -1;
@@ -3141,7 +3137,9 @@ public:
const Document *doc;
Sci::Position position;
- explicit ByteIterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
+ ByteIterator() noexcept :
+ ByteIterator(nullptr) {}
+ explicit ByteIterator(const Document *doc_, Sci::Position position_=0) noexcept :
doc(doc_), position(position_) {
}
char operator*() const noexcept {
@@ -3206,7 +3204,9 @@ public:
using pointer = wchar_t*;
using reference = wchar_t&;
- explicit UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
+ UTF8Iterator() noexcept :
+ UTF8Iterator(nullptr) {}
+ explicit UTF8Iterator(const Document *doc_, Sci::Position position_=0) noexcept :
doc(doc_), position(position_) {
if (doc) {
ReadCharacter();
@@ -3295,7 +3295,9 @@ public:
using pointer = wchar_t*;
using reference = wchar_t&;
- explicit UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
+ UTF8Iterator() noexcept :
+ UTF8Iterator(nullptr) {}
+ explicit UTF8Iterator(const Document *doc_, Sci::Position position_=0) noexcept :
doc(doc_), position(position_) {
}
wchar_t operator*() const noexcept {