aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx33
-rw-r--r--src/Editor.h2
-rw-r--r--src/ScintillaBase.cxx14
-rw-r--r--src/ScintillaBase.h6
4 files changed, 32 insertions, 23 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 2500e6157..2f35862e8 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -100,10 +100,10 @@ Timer::Timer() noexcept :
Idler::Idler() noexcept :
state(false), idlerID(0) {}
-static constexpr bool IsAllSpacesOrTabs(const char *s, unsigned int len) noexcept {
- for (unsigned int i = 0; i < len; i++) {
+static constexpr bool IsAllSpacesOrTabs(std::string_view sv) noexcept {
+ for (const char ch : sv) {
// This is safe because IsSpaceOrTab() will return false for null terminators
- if (!IsSpaceOrTab(s[i]))
+ if (!IsSpaceOrTab(ch))
return false;
}
return true;
@@ -1891,7 +1891,7 @@ void Editor::AddChar(char ch) {
char s[2];
s[0] = ch;
s[1] = '\0';
- AddCharUTF(s, 1);
+ InsertCharacter(std::string_view(s, 1));
}
void Editor::FilterSelections() {
@@ -1901,9 +1901,9 @@ void Editor::FilterSelections() {
}
}
-// AddCharUTF inserts an array of bytes which may or may not be in UTF-8.
-void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
- if (len == 0) {
+// InsertCharacter inserts a character encoded in document code page.
+void Editor::InsertCharacter(std::string_view sv) {
+ if (sv.empty()) {
return;
}
FilterSelections();
@@ -1943,7 +1943,7 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
}
}
positionInsert = RealizeVirtualSpace(positionInsert, currentSel->caret.VirtualSpace());
- const Sci::Position lengthInserted = pdoc->InsertString(positionInsert, s, len);
+ const Sci::Position lengthInserted = pdoc->InsertString(positionInsert, sv.data(), sv.length());
if (lengthInserted > 0) {
currentSel->caret.SetPosition(positionInsert + lengthInserted);
currentSel->anchor.SetPosition(positionInsert + lengthInserted);
@@ -1972,32 +1972,33 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
// Avoid blinking during rapid typing:
ShowCaretAtCurrentPosition();
if ((caretSticky == SC_CARETSTICKY_OFF) ||
- ((caretSticky == SC_CARETSTICKY_WHITESPACE) && !IsAllSpacesOrTabs(s, len))) {
+ ((caretSticky == SC_CARETSTICKY_WHITESPACE) && !IsAllSpacesOrTabs(sv))) {
SetLastXChosen();
}
- int ch = static_cast<unsigned char>(s[0]);
- if (treatAsDBCS || pdoc->dbcsCodePage != SC_CP_UTF8) {
- if (len > 1) {
+ int ch = static_cast<unsigned char>(sv[0]);
+ if (pdoc->dbcsCodePage != SC_CP_UTF8) {
+ if (sv.length() > 1) {
// DBCS code page or DBCS font character set.
- ch = (ch << 8) | static_cast<unsigned char>(s[1]);
+ ch = (ch << 8) | static_cast<unsigned char>(sv[1]);
}
} else {
- if ((ch < 0xC0) || (1 == len)) {
+ if ((ch < 0xC0) || (1 == sv.length())) {
// Handles UTF-8 characters between 0x01 and 0x7F and single byte
// characters when not in UTF-8 mode.
// Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
// characters representing themselves.
} else {
unsigned int utf32[1] = { 0 };
- UTF32FromUTF8(std::string_view(s, len), utf32, std::size(utf32));
+ UTF32FromUTF8(sv, utf32, std::size(utf32));
ch = utf32[0];
}
}
NotifyChar(ch);
if (recordingMacro) {
- NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(s));
+ std::string copy(sv); // ensure NUL-terminated
+ NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(copy.data()));
}
}
diff --git a/src/Editor.h b/src/Editor.h
index c5bddb1e0..5716ba048 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -393,7 +393,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
Sci::Position RealizeVirtualSpace(Sci::Position position, Sci::Position virtualSpace);
SelectionPosition RealizeVirtualSpace(const SelectionPosition &position);
void AddChar(char ch);
- virtual void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false);
+ virtual void InsertCharacter(std::string_view sv);
void ClearBeforeTentativeStart();
void InsertPaste(const char *text, Sci::Position len);
enum PasteShape { pasteStream=0, pasteRectangular = 1, pasteLine = 2 };
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 5a44fd9af..6799dfd06 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -79,17 +79,21 @@ void ScintillaBase::Finalise() {
popup.Destroy();
}
-void ScintillaBase::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
- const bool isFillUp = ac.Active() && ac.IsFillUpChar(*s);
+void ScintillaBase::AddCharUTF(const char *s, unsigned int len, bool /*treatAsDBCS*/) {
+ InsertCharacter(std::string_view(s, len));
+}
+
+void ScintillaBase::InsertCharacter(std::string_view sv) {
+ const bool isFillUp = ac.Active() && ac.IsFillUpChar(sv[0]);
if (!isFillUp) {
- Editor::AddCharUTF(s, len, treatAsDBCS);
+ Editor::InsertCharacter(sv);
}
if (ac.Active()) {
- AutoCompleteCharacterAdded(s[0]);
+ AutoCompleteCharacterAdded(sv[0]);
// For fill ups add the character after the autocompletion has
// triggered so containers see the key so can display a calltip.
if (isFillUp) {
- Editor::AddCharUTF(s, len, treatAsDBCS);
+ Editor::InsertCharacter(sv);
}
}
}
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index f03d1c090..d28e47c4e 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -59,7 +59,11 @@ protected:
void Initialise() override {}
void Finalise() override;
- void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false) override;
+ [[deprecated]]
+ // This method is deprecated, use InsertCharacter instead. The treatAsDBCS parameter is no longer used.
+ virtual void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false);
+
+ void InsertCharacter(std::string_view sv) override;
void Command(int cmdId);
void CancelModes() override;
int KeyCommand(unsigned int iMessage) override;