+upd: to Scintilla Lib v.5.1.5 (incl. adapt. for length queries on Sci-Calls: SCI_GETTEXT, SCI_GETSELTEXT, and SCI_GETCURLINE)

This commit is contained in:
METANEOCORTEX\Kotti 2021-12-09 13:24:23 +01:00
parent e4b651d30f
commit 6bc214bb6d
24 changed files with 365 additions and 348 deletions

View File

@ -128,7 +128,7 @@
<h1>Scintilla Documentation</h1>
<p>Last edited 21 October 2021 ZL</p>
<p>Last edited 12 November 2021 NH</p>
<p style="background:#90F0C0">Scintilla 5 has moved the lexers from Scintilla into a new
<a href="Lexilla.html">Lexilla</a> project.<br />
@ -551,12 +551,12 @@
</code>
<p><b id="SCI_GETTEXT">SCI_GETTEXT(position length, char *text NUL-terminated) &rarr; position</b><br />
This returns at most <code class="parameter">length</code>-1 characters of text from the start of the document plus one
terminating 0 character. When <code class="parameter">length</code>-1 is beyond document length, it returns document length.
This returns at most <code class="parameter">length</code> characters of text from the start of the document plus one
terminating 0 character. When <code class="parameter">length</code> is beyond document length, it returns document length.
To collect all the text in a document, use <code>SCI_GETLENGTH</code>
to get the number of characters in the document (<code>nLen</code>), allocate a character
buffer of length <code>nLen+1</code> bytes, then call <code>SCI_GETTEXT(nLen+1, char
*text)</code>. If the text argument is 0 then the length that should be allocated to store the
buffer of length <code>nLen+1</code> bytes, then call <code>SCI_GETTEXT(nLen, char
*text)</code>. If the text argument is NULL(0) then the length that should be allocated to store the
entire document is returned.
If you then save the text, you should use <code>SCI_SETSAVEPOINT</code> to mark
the text as unmodified.</p>
@ -586,7 +586,7 @@
<p><b id="SCI_GETLINE">SCI_GETLINE(line line, char *text) &rarr; position</b><br />
This fills the buffer defined by text with the contents of the nominated line (lines start at
0). The buffer is not terminated by a 0 character. It is up to you to make sure that the buffer
0). The buffer is not terminated by a NUL(0) character. It is up to you to make sure that the buffer
is long enough for the text, use <a class="message"
href="#SCI_LINELENGTH"><code>SCI_LINELENGTH(line line)</code></a>. The returned value is the
number of characters copied to the buffer. The returned text includes any end of line
@ -1499,9 +1499,9 @@ struct Sci_TextToFind {
href="#SCI_POSITIONFROMLINE"><code>SCI_POSITIONFROMLINE(line)</code></a>.</p>
<p><b id="SCI_GETSELTEXT">SCI_GETSELTEXT(&lt;unused&gt;, char *text NUL-terminated) &rarr; position</b><br />
This copies the currently selected text and a terminating 0 byte to the <code class="parameter">text</code>
buffer. The buffer size should be determined by calling with a NULL pointer for the <code class="parameter">text</code> argument
<code>SCI_GETSELTEXT(0,0)</code>.
This copies the currently selected text and a terminating NUL(0) byte to the <code class="parameter">text</code>
buffer. The buffer size should be determined by calling with a NULL pointer for the <code class="parameter">text</code> argument:
<code>1 + SCI_GETSELTEXT(0, NULL)</code>.
This allows for rectangular and discontiguous selections as well as simple selections.
See <a class="toc" href="#MultipleSelectionAndVirtualSpace">Multiple Selection</a> for information on
how multiple and rectangular selections and virtual space are copied.</p>
@ -1516,10 +1516,10 @@ struct Sci_TextToFind {
<p><b id="SCI_GETCURLINE">SCI_GETCURLINE(position length, char *text NUL-terminated) &rarr; position</b><br />
This retrieves the text of the line containing the caret and returns the position within the
line of the caret. Pass in <code>char* text</code> pointing at a buffer large enough to hold
the text you wish to retrieve and a terminating 0 character.
the text you wish to retrieve and a terminating NUL(0) character.
Set <code class="parameter">length</code> to the
length of the buffer which must be at least 1 to hold the terminating 0 character.
If the text argument is 0 then the length that should be allocated
length of the buffer not including the terminating NUL character.
If the text argument is NULL(0) then the length that should be allocated
to store the entire current line is returned.</p>
<p>See also: <code><a class="seealso" href="#SCI_GETSELTEXT">SCI_GETSELTEXT</a>, <a

View File

@ -26,9 +26,9 @@
<table bgcolor="#CCCCCC" width="100%" cellspacing="0" cellpadding="8" border="0">
<tr>
<td>
<font size="4"> <a href="https://www.scintilla.org/scintilla514.zip">
<font size="4"> <a href="https://www.scintilla.org/scintilla515.zip">
Windows</a>&nbsp;&nbsp;
<a href="https://www.scintilla.org/scintilla514.tgz">
<a href="https://www.scintilla.org/scintilla515.tgz">
GTK/Linux</a>&nbsp;&nbsp;
</font>
</td>
@ -42,7 +42,7 @@
containing very few restrictions.
</p>
<h3>
Release 5.1.4
Release 5.1.5
</h3>
<h4>
Source Code
@ -50,8 +50,8 @@
The source code package contains all of the source code for Scintilla but no binary
executable code and is available in
<ul>
<li><a href="https://www.scintilla.org/scintilla514.zip">zip format</a> (1.3M) commonly used on Windows</li>
<li><a href="https://www.scintilla.org/scintilla514.tgz">tgz format</a> (1.2M) commonly used on Linux and compatible operating systems</li>
<li><a href="https://www.scintilla.org/scintilla515.zip">zip format</a> (1.3M) commonly used on Windows</li>
<li><a href="https://www.scintilla.org/scintilla515.tgz">tgz format</a> (1.2M) commonly used on Linux and compatible operating systems</li>
</ul>
Instructions for building on both Windows and Linux are included in the readme file.
<h4>

View File

@ -564,9 +564,59 @@
</tr><tr>
<td>Michael Neuroth</td>
<td>Arne Scheffler</td>
<td>Jan Dolinár</td>
<td>Rowan Daniell</td>
</tr>
</table>
<h2>Releases</h2>
<h3>
<a href="https://www.scintilla.org/scintilla515.zip">Release 5.1.5</a>
</h3>
<ul>
<li>
Released 7 December 2021.
</li>
<li>
ScintillaEditPy, Python bindings for Qt using PySide, has been removed.
Scintilla was never updated for PySide 2 which was released in 2018 and PySide 1
fell out of support making it difficult to use.
Tests that use ScintillaEditPy were removed.
</li>
<li>
When calling SCI_GETTEXT, SCI_GETSELTEXT, and SCI_GETCURLINE with a NULL buffer argument
to discover the length that should be allocated, do not include the terminating NUL in the returned value.
The value returned is 1 less than previous versions of Scintilla.
Applications should allocate a buffer 1 more than this to accommodate the NUL.
The wParam (length) argument to SCI_GETTEXT and SCI_GETCURLINE also omits the NUL.
This is more consistent with other APIs.
</li>
<li>
Fix assertion failure with autocompletion list when order is SC_ORDER_CUSTOM
or SC_ORDER_PERFORMSORT and the list is empty.
<a href="https://sourceforge.net/p/scintilla/bugs/2294/">Bug #2294</a>.
</li>
<li>
On Win32 prevent potential memory leaks for Korean language input.
<a href="https://sourceforge.net/p/scintilla/bugs/2295/">Bug #2295</a>.
</li>
<li>
On Cocoa set active state correctly at creation.
<a href="https://sourceforge.net/p/scintilla/bugs/2299/">Bug #2299</a>.
</li>
<li>
On macOS 12, fix bug where margin would not draw when scrolled.
<a href="https://sourceforge.net/p/scintilla/bugs/2292/">Bug #2292</a>.
</li>
<li>
On Cocoa, fix crash when drag image empty.
<a href="https://sourceforge.net/p/scintilla/bugs/2300/">Bug #2300</a>.
</li>
<li>
On GTK using Wayland, display autocompletion with window on a secondary monitor.
<a href="https://sourceforge.net/p/scintilla/bugs/2296/">Bug #2296</a>,
<a href="https://sourceforge.net/p/scintilla/bugs/2261/">Bug #2261</a>.
</li>
</ul>
<h3>
<a href="https://www.scintilla.org/scintilla514.zip">Release 5.1.4</a>
</h3>

View File

@ -127,6 +127,10 @@
<h3>
Projects using Scintilla
</h3>
<p>
<a href="https://github.com/simdsoft/x-studio/blob/master/README_EN.md">x-studio</a>
is a powerful and very lightweight developer IDE that supports Lua debugging.
</p>
<p>
<a href="https://sourceforge.net/projects/autogui/">Adventure IDE</a>
is a general-purpose IDE and lightweight text editor for Windows.

View File

@ -9,7 +9,7 @@
<meta name="keywords" content="Scintilla, SciTE, Editing Component, Text Editor" />
<meta name="Description"
content="www.scintilla.org is the home of the Scintilla editing component and SciTE text editor application." />
<meta name="Date.Modified" content="20211108" />
<meta name="Date.Modified" content="20211207" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
#versionlist {
@ -56,8 +56,8 @@
GTK, and OS X</font>
</td>
<td width="40%" align="right">
<font color="#FFCC99" size="3"> Release version 5.1.4<br />
Site last modified November 8 2021</font>
<font color="#FFCC99" size="3"> Release version 5.1.5<br />
Site last modified December 7 2021</font>
</td>
<td width="20%">
&nbsp;
@ -72,6 +72,7 @@
</tr>
</table>
<ul id="versionlist">
<li>Version 5.1.5 changes string-returning APIs to be more consistent and removes ScintillaEditPy.</li>
<li>Version 5.1.4 fixes primary selection paste within one instance on GTK.</li>
<li>Version 5.1.3 fixes a layout bug with monospaced fonts on Cocoa.</li>
<li>Version 5.1.2 can optimize monospaced fonts and allows hiding the first line.</li>
@ -162,10 +163,6 @@ if (!IsRemote()) { //if NOT remote...
<p>
<a href="https://www.scintilla.org/Icons.html">Icons that can be used with Scintilla.</a>
</p>
<p>
The <a href="https://scintilla.sourceforge.io/LongTermDownload.html">LongTerm3</a>
branch of Scintilla avoids using features from C++14 or later in order to support older systems.
</p>
<p>
Questions and comments about Scintilla should be directed to the
<a href="https://groups.google.com/forum/#!forum/scintilla-interest">scintilla-interest</a>
@ -176,8 +173,6 @@ if (!IsRemote()) { //if NOT remote...
New versions of Scintilla are announced on scintilla-interest and may also be received by SourceForge
members by clicking on the Monitor column icon for "scintilla" on
<a href="https://sourceforge.net/project/showfiles.php?group_id=2439">the downloads page</a>.
Messages sent to my personal email address that could have been sent to the list
may receive no response.
<br />
</p>
There is a <a href="https://sourceforge.net/projects/scintilla/">Scintilla project page</a>

View File

@ -151,6 +151,7 @@
// Platform-specific headers
// win32
#include "WinTypes.h"
#include "PlatWin.h"
#include "HanjaDic.h"
#include "ScintillaWin.h"

View File

@ -115,6 +115,11 @@ struct Sorter {
Sorter(AutoComplete *ac_, const char *list_) : ac(ac_), list(list_) {
int i = 0;
if (!list[i]) {
// Empty list has a single empty member
indices.push_back(i); // word start
indices.push_back(i); // word end
}
while (list[i]) {
indices.push_back(i); // word start
while (list[i] != ac->GetTypesep() && list[i] != ac->GetSeparator() && list[i])

View File

@ -2871,35 +2871,18 @@ public:
class ByteIterator {
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef char value_type;
typedef ptrdiff_t difference_type;
typedef char* pointer;
typedef char& reference;
using iterator_category = std::bidirectional_iterator_tag;
using value_type = char;
using difference_type = ptrdiff_t;
using pointer = char*;
using reference = char&;
const Document *doc;
Sci::Position position;
ByteIterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
explicit ByteIterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
doc(doc_), position(position_) {
}
ByteIterator(const ByteIterator &other) noexcept {
doc = other.doc;
position = other.position;
}
ByteIterator(ByteIterator &&other) noexcept {
doc = other.doc;
position = other.position;
}
ByteIterator &operator=(const ByteIterator &other) noexcept {
if (this != &other) {
doc = other.doc;
position = other.position;
}
return *this;
}
ByteIterator &operator=(ByteIterator &&) noexcept = default;
~ByteIterator() = default;
char operator*() const noexcept {
return doc->CharAt(position);
}
@ -2956,11 +2939,11 @@ class UTF8Iterator {
size_t lenCharacters;
wchar_t buffered[2];
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef wchar_t value_type;
typedef ptrdiff_t difference_type;
typedef wchar_t* pointer;
typedef wchar_t& reference;
using iterator_category = std::bidirectional_iterator_tag;
using value_type = wchar_t;
using difference_type = ptrdiff_t;
using pointer = wchar_t*;
using reference = wchar_t&;
explicit UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
doc(doc_), position(position_), characterIndex(0), lenBytes(0), lenCharacters(0), buffered{} {
@ -2970,30 +2953,6 @@ public:
ReadCharacter();
}
}
UTF8Iterator(const UTF8Iterator &other) noexcept : buffered{} {
doc = other.doc;
position = other.position;
characterIndex = other.characterIndex;
lenBytes = other.lenBytes;
lenCharacters = other.lenCharacters;
buffered[0] = other.buffered[0];
buffered[1] = other.buffered[1];
}
UTF8Iterator(UTF8Iterator &&other) noexcept = default;
UTF8Iterator &operator=(const UTF8Iterator &other) noexcept {
if (this != &other) {
doc = other.doc;
position = other.position;
characterIndex = other.characterIndex;
lenBytes = other.lenBytes;
lenCharacters = other.lenCharacters;
buffered[0] = other.buffered[0];
buffered[1] = other.buffered[1];
}
return *this;
}
UTF8Iterator &operator=(UTF8Iterator &&) noexcept = default;
~UTF8Iterator() = default;
wchar_t operator*() const noexcept {
assert(lenCharacters != 0);
return buffered[characterIndex];
@ -3071,29 +3030,15 @@ class UTF8Iterator {
const Document *doc;
Sci::Position position;
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef wchar_t value_type;
typedef ptrdiff_t difference_type;
typedef wchar_t* pointer;
typedef wchar_t& reference;
using iterator_category = std::bidirectional_iterator_tag;
using value_type = wchar_t;
using difference_type = ptrdiff_t;
using pointer = wchar_t*;
using reference = wchar_t&;
UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
explicit UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
doc(doc_), position(position_) {
}
UTF8Iterator(const UTF8Iterator &other) noexcept {
doc = other.doc;
position = other.position;
}
UTF8Iterator(UTF8Iterator &&other) noexcept = default;
UTF8Iterator &operator=(const UTF8Iterator &other) noexcept {
if (this != &other) {
doc = other.doc;
position = other.position;
}
return *this;
}
UTF8Iterator &operator=(UTF8Iterator &&) noexcept = default;
~UTF8Iterator() = default;
wchar_t operator*() const noexcept {
const Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position);
return charExtracted.character;

View File

@ -4151,7 +4151,7 @@ Sci::Position Editor::SearchText(
///< @c FindOption::WordStart, @c FindOption::RegExp or @c FindOption::Posix.
sptr_t lParam) { ///< The text to search for.
const char *txt = CharPtrFromSPtr(lParam);
const char *txt = ConstCharPtrFromSPtr(lParam);
Sci::Position pos = Sci::invalidPosition;
Sci::Position lengthFound = strlen(txt);
if (!pdoc->HasCaseFolder())
@ -5765,7 +5765,7 @@ void Editor::StyleSetMessage(Message iMessage, uptr_t wParam, sptr_t lParam) {
break;
case Message::StyleSetFont:
if (lParam != 0) {
vs.SetStyleFontName(static_cast<int>(wParam), CharPtrFromSPtr(lParam));
vs.SetStyleFontName(static_cast<int>(wParam), ConstCharPtrFromSPtr(lParam));
}
break;
case Message::StyleSetUnderline:
@ -5923,11 +5923,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::GetText: {
if (lParam == 0)
return pdoc->Length() + 1;
if (wParam == 0)
return 0;
return pdoc->Length();
char *ptr = CharPtrFromSPtr(lParam);
const Sci_Position len = std::min<Sci_Position>(wParam - 1, pdoc->Length());
const Sci_Position len = std::min<Sci_Position>(wParam, pdoc->Length());
pdoc->GetCharRange(ptr, 0, len);
ptr[len] = '\0';
return len;
@ -5939,7 +5937,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
UndoGroup ug(pdoc);
pdoc->DeleteChars(0, pdoc->Length());
SetEmptySelection(0);
const char *text = CharPtrFromSPtr(lParam);
const char *text = ConstCharPtrFromSPtr(lParam);
pdoc->InsertString(0, text, strlen(text));
return 1;
}
@ -5977,7 +5975,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
break;
case Message::CopyText:
CopyText(wParam, CharPtrFromSPtr(lParam));
CopyText(wParam, ConstCharPtrFromSPtr(lParam));
break;
case Message::Paste:
@ -5993,7 +5991,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
if (!sel.Empty()) {
ClearSelection(); // want to replace rectangular selection contents
}
InsertPasteShape(CharPtrFromSPtr(lParam), PositionFromUPtr(wParam), PasteShape::rectangular);
InsertPasteShape(ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam), PasteShape::rectangular);
break;
}
@ -6068,20 +6066,16 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::GetSelText: {
SelectionText selectedText;
CopySelectionRange(&selectedText);
if (lParam == 0) {
return selectedText.LengthWithTerminator();
} else {
if (lParam) {
char *ptr = CharPtrFromSPtr(lParam);
size_t iChar = selectedText.Length();
if (iChar) {
memcpy(ptr, selectedText.Data(), iChar);
ptr[iChar++] = '\0';
} else {
ptr[0] = '\0';
}
return iChar;
ptr[iChar] = '\0';
}
}
return selectedText.Length();
}
case Message::LineFromPosition:
if (PositionFromUPtr(wParam) < 0)
@ -6111,7 +6105,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
return 0;
UndoGroup ug(pdoc);
ClearSelection();
const char *replacement = CharPtrFromSPtr(lParam);
const char *replacement = ConstCharPtrFromSPtr(lParam);
const Sci::Position lengthInserted = pdoc->InsertString(
sel.MainCaret(), replacement, strlen(replacement));
SetEmptySelection(sel.MainCaret() + lengthInserted);
@ -6170,15 +6164,15 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::ReplaceTarget:
PLATFORM_ASSERT(lParam);
return ReplaceTarget(false, CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
return ReplaceTarget(false, ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
case Message::ReplaceTargetRE:
PLATFORM_ASSERT(lParam);
return ReplaceTarget(true, CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
return ReplaceTarget(true, ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
case Message::SearchInTarget:
PLATFORM_ASSERT(lParam);
return SearchInTarget(CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
return SearchInTarget(ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
case Message::SetSearchFlags:
searchFlags = static_cast<FindOption>(wParam);
@ -6305,14 +6299,14 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
if (lParam == 0)
return 0;
const Sci::Position lengthInserted = pdoc->InsertString(
CurrentPosition(), CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
CurrentPosition(), ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
SetEmptySelection(sel.MainCaret() + lengthInserted);
return 0;
}
case Message::AddStyledText:
if (lParam)
AddStyledText(CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
AddStyledText(ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
return 0;
case Message::InsertText: {
@ -6322,7 +6316,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
if (insertPos == -1)
insertPos = CurrentPosition();
Sci::Position newCurrent = CurrentPosition();
const char *sz = CharPtrFromSPtr(lParam);
const char *sz = ConstCharPtrFromSPtr(lParam);
const Sci::Position lengthInserted = pdoc->InsertString(insertPos, sz, strlen(sz));
if (newCurrent > insertPos)
newCurrent += lengthInserted;
@ -6332,12 +6326,12 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::ChangeInsertion:
PLATFORM_ASSERT(lParam);
pdoc->ChangeInsertion(CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
pdoc->ChangeInsertion(ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
return 0;
case Message::AppendText:
pdoc->InsertString(pdoc->Length(),
CharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
return 0;
case Message::ClearAll:
@ -6591,11 +6585,10 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
const Sci::Position lineStart = pdoc->LineStart(lineCurrentPos);
const Sci::Position lineEnd = pdoc->LineStart(lineCurrentPos + 1);
if (lParam == 0) {
return 1 + lineEnd - lineStart;
return lineEnd - lineStart;
}
PLATFORM_ASSERT(wParam > 0);
char *ptr = CharPtrFromSPtr(lParam);
const Sci::Position len = std::min<uptr_t>(lineEnd - lineStart, wParam - 1);
const Sci::Position len = std::min<uptr_t>(lineEnd - lineStart, wParam);
pdoc->GetCharRange(ptr, lineStart, len);
ptr[len] = '\0';
return sel.MainCaret() - lineStart;
@ -6640,7 +6633,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::SetStylingEx: // Specify a complete styling buffer
if (lParam == 0)
return 0;
pdoc->SetStyles(PositionFromUPtr(wParam), CharPtrFromSPtr(lParam));
pdoc->SetStyles(PositionFromUPtr(wParam), ConstCharPtrFromSPtr(lParam));
break;
case Message::SetBufferedDraw:
@ -6879,7 +6872,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::TextWidth:
PLATFORM_ASSERT(wParam < vs.styles.size());
PLATFORM_ASSERT(lParam);
return TextWidth(wParam, CharPtrFromSPtr(lParam));
return TextWidth(wParam, ConstCharPtrFromSPtr(lParam));
case Message::TextHeight:
RefreshStyleData();
@ -7131,7 +7124,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::MarkerDefinePixmap:
if (wParam <= MarkerMax) {
vs.markers[wParam].SetXPM(CharPtrFromSPtr(lParam));
vs.markers[wParam].SetXPM(ConstCharPtrFromSPtr(lParam));
vs.CalcLargestMarkerHeight();
}
InvalidateStyleData();
@ -7326,7 +7319,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::SetFontLocale:
if (lParam) {
vs.SetFontLocaleName(CharPtrFromSPtr(lParam));
vs.SetFontLocaleName(ConstCharPtrFromSPtr(lParam));
InvalidateStyleRedraw();
}
break;
@ -7488,7 +7481,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
break;
case Message::ToggleFoldShowText:
pcs->SetFoldDisplayText(LineFromUPtr(wParam), CharPtrFromSPtr(lParam));
pcs->SetFoldDisplayText(LineFromUPtr(wParam), ConstCharPtrFromSPtr(lParam));
FoldLine(LineFromUPtr(wParam), FoldAction::Toggle);
break;
@ -7501,7 +7494,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
return static_cast<sptr_t>(foldDisplayTextStyle);
case Message::SetDefaultFoldDisplayText:
SetDefaultFoldDisplayText(CharPtrFromSPtr(lParam));
SetDefaultFoldDisplayText(ConstCharPtrFromSPtr(lParam));
Redraw();
break;
@ -8334,7 +8327,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
return static_cast<sptr_t>(marginOptions);
case Message::MarginSetText:
pdoc->MarginSetText(LineFromUPtr(wParam), CharPtrFromSPtr(lParam));
pdoc->MarginSetText(LineFromUPtr(wParam), ConstCharPtrFromSPtr(lParam));
break;
case Message::MarginGetText: {
@ -8365,7 +8358,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
break;
case Message::AnnotationSetText:
pdoc->AnnotationSetText(LineFromUPtr(wParam), CharPtrFromSPtr(lParam));
pdoc->AnnotationSetText(LineFromUPtr(wParam), ConstCharPtrFromSPtr(lParam));
break;
case Message::AnnotationGetText: {
@ -8414,7 +8407,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
return vs.annotationStyleOffset;
case Message::EOLAnnotationSetText:
pdoc->EOLAnnotationSetText(LineFromUPtr(wParam), CharPtrFromSPtr(lParam));
pdoc->EOLAnnotationSetText(LineFromUPtr(wParam), ConstCharPtrFromSPtr(lParam));
break;
case Message::EOLAnnotationGetText: {

View File

@ -1 +1 @@
514
515

View File

@ -8,23 +8,30 @@
#include <string>
#include <string_view>
#include <memory>
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <ole2.h>
#include "UniConversion.h"
#include "WinTypes.h"
#include "HanjaDic.h"
namespace Scintilla::Internal {
namespace Scintilla::Internal::HanjaDict {
namespace HanjaDict {
struct BSTRDeleter {
void operator()(BSTR bstr) const noexcept {
SysFreeString(bstr);
}
};
using UniqueBSTR = std::unique_ptr<OLECHAR[], BSTRDeleter>;
interface IRadical;
interface IHanja;
interface IStrokes;
typedef enum { HANJA_UNKNOWN = 0, HANJA_K0 = 1, HANJA_K1 = 2, HANJA_OTHER = 3 } HANJA_TYPE;
enum HANJA_TYPE { HANJA_UNKNOWN = 0, HANJA_K0 = 1, HANJA_K1 = 2, HANJA_OTHER = 3 };
interface IHanjaDic : IUnknown {
STDMETHOD(OpenMainDic)();
@ -60,82 +67,71 @@ extern "C" const GUID __declspec(selectany) IID_IHanjaDic =
{ 0xad75f3ac, 0x18cd, 0x48c6, { 0xa2, 0x7d, 0xf1, 0xe9, 0xa7, 0xdc, 0xe4, 0x32 } };
class HanjaDic {
private:
HRESULT hr;
CLSID CLSID_HanjaDic;
std::unique_ptr<IHanjaDic, UnknownReleaser> HJinterface;
public:
IHanjaDic *HJinterface;
HanjaDic() noexcept : HJinterface(nullptr) {
hr = CLSIDFromProgID(OLESTR("mshjdic.hanjadic"), &CLSID_HanjaDic);
bool OpenHanjaDic(LPCOLESTR lpszProgID) noexcept {
CLSID CLSID_HanjaDic;
HRESULT hr = CLSIDFromProgID(lpszProgID, &CLSID_HanjaDic);
if (SUCCEEDED(hr)) {
IHanjaDic *instance = nullptr;
hr = CoCreateInstance(CLSID_HanjaDic, nullptr,
CLSCTX_INPROC_SERVER, IID_IHanjaDic,
(LPVOID *)& HJinterface);
CLSCTX_INPROC_SERVER, IID_IHanjaDic,
(LPVOID *)&instance);
if (SUCCEEDED(hr)) {
hr = HJinterface->OpenMainDic();
HJinterface.reset(instance);
hr = instance->OpenMainDic();
return SUCCEEDED(hr);
}
}
}
// Deleted so HanjaDic objects can not be copied.
HanjaDic(const HanjaDic &) = delete;
HanjaDic(HanjaDic &&) = delete;
HanjaDic &operator=(const HanjaDic &) = delete;
HanjaDic &operator=(HanjaDic &&) = delete;
~HanjaDic() {
if (SUCCEEDED(hr)) {
hr = HJinterface->CloseMainDic();
try {
// This can never fail but IUnknown::Release is not marked noexcept.
HJinterface->Release();
} catch (...) {
// Ignore any exception
}
}
}
bool HJdictAvailable() const noexcept {
return SUCCEEDED(hr);
}
bool IsHanja(int hanja) noexcept {
HANJA_TYPE hanjaType;
hr = HJinterface->GetHanjaType(static_cast<unsigned short>(hanja), &hanjaType);
if (SUCCEEDED(hr)) {
return (hanjaType > 0);
}
return false;
}
public:
bool Open() noexcept {
return OpenHanjaDic(OLESTR("imkrhjd.hanjadic"))
|| OpenHanjaDic(OLESTR("mshjdic.hanjadic"));
}
void Close() const noexcept {
HJinterface->CloseMainDic();
}
bool IsHanja(wchar_t hanja) const noexcept {
HANJA_TYPE hanjaType = HANJA_UNKNOWN;
const HRESULT hr = HJinterface->GetHanjaType(hanja, &hanjaType);
return SUCCEEDED(hr) && hanjaType > HANJA_UNKNOWN;
}
bool HanjaToHangul(BSTR bstrHanja, UniqueBSTR &bstrHangul) const noexcept {
BSTR result = nullptr;
const HRESULT hr = HJinterface->HanjaToHangul(bstrHanja, &result);
bstrHangul.reset(result);
return SUCCEEDED(hr);
}
};
int GetHangulOfHanja(wchar_t *inout) noexcept {
bool GetHangulOfHanja(std::wstring &inout) noexcept {
// Convert every hanja to hangul.
// Return the number of characters converted.
int changed = 0;
// Return whether any character been converted.
// Hanja linked to different notes in Hangul have different codes,
// so current character based conversion is enough.
// great thanks for BLUEnLIVE.
bool changed = false;
HanjaDic dict;
if (dict.HJdictAvailable()) {
const size_t len = wcslen(inout);
wchar_t conv[UTF8MaxBytes] = {0};
BSTR bstrHangul = SysAllocString(conv);
for (size_t i=0; i<len; i++) {
if (dict.IsHanja(static_cast<int>(inout[i]))) { // Pass hanja only!
conv[0] = inout[i];
BSTR bstrHanja = SysAllocString(conv);
const HRESULT hr = dict.HJinterface->HanjaToHangul(bstrHanja, &bstrHangul);
if (SUCCEEDED(hr)) {
inout[i] = static_cast<wchar_t>(bstrHangul[0]);
changed += 1;
if (dict.Open()) {
for (wchar_t &character : inout) {
if (dict.IsHanja(character)) { // Pass hanja only!
const UniqueBSTR bstrHanja{SysAllocStringLen(&character, 1)};
UniqueBSTR bstrHangul;
if (dict.HanjaToHangul(bstrHanja.get(), bstrHangul)) {
changed = true;
character = bstrHangul[0];
}
SysFreeString(bstrHanja);
}
}
SysFreeString(bstrHangul);
dict.Close();
}
return changed;
}
}
}

View File

@ -5,7 +5,7 @@
**/
// Copyright 2015 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#pragma once
#ifndef HANJADIC_H
#define HANJADIC_H
@ -13,7 +13,7 @@ namespace Scintilla::Internal {
namespace HanjaDict {
int GetHangulOfHanja(wchar_t *inout) noexcept;
bool GetHangulOfHanja(std::wstring &inout) noexcept;
}

View File

@ -55,6 +55,7 @@
#include "UniConversion.h"
#include "DBCS.h"
#include "WinTypes.h"
#include "PlatWin.h"
#ifndef SPI_GETFONTSMOOTHINGCONTRAST
@ -1980,7 +1981,7 @@ void SurfaceD2D::Copy(PRectangle rc, Point from, Surface &surfaceSource) {
const HRESULT hr = surfOther.GetBitmap(&pBitmap);
if (SUCCEEDED(hr) && pBitmap) {
const D2D1_RECT_F rcDestination = RectangleFromPRectangle(rc);
D2D1_RECT_F rcSource = RectangleFromPRectangle(PRectangle(
const D2D1_RECT_F rcSource = RectangleFromPRectangle(PRectangle(
from.x, from.y, from.x + rc.Width(), from.y + rc.Height()));
pRenderTarget->DrawBitmap(pBitmap, rcDestination, 1.0f,
D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, rcSource);
@ -2411,7 +2412,7 @@ void SurfaceD2D::DrawTextCommon(PRectangle rc, const Font *font_, XYPOSITION yba
static_cast<FLOAT>(rc.Height()),
&pTextLayout);
if (SUCCEEDED(hr)) {
D2D1_POINT_2F origin = DPointFromPoint(Point(rc.left, ybase-yAscent));
const D2D1_POINT_2F origin = DPointFromPoint(Point(rc.left, ybase-yAscent));
pRenderTarget->DrawTextLayout(origin, pTextLayout, pBrush, d2dDrawTextOptions);
ReleaseUnknown(pTextLayout);
}

View File

@ -43,37 +43,6 @@ inline HWND HwndFromWindow(const Window &w) noexcept {
void *PointerFromWindow(HWND hWnd) noexcept;
void SetWindowPointer(HWND hWnd, void *ptr) noexcept;
/// Find a function in a DLL and convert to a function pointer.
/// This avoids undefined and conditionally defined behaviour.
template<typename T>
T DLLFunction(HMODULE hModule, LPCSTR lpProcName) noexcept {
if (!hModule) {
return nullptr;
}
FARPROC function = ::GetProcAddress(hModule, lpProcName);
static_assert(sizeof(T) == sizeof(function));
T fp {};
memcpy(&fp, &function, sizeof(T));
return fp;
}
// Release an IUnknown* and set to nullptr.
// While IUnknown::Release must be noexcept, it isn't marked as such so produces
// warnings which are avoided by the catch.
template <class T>
void ReleaseUnknown(T *&ppUnknown) noexcept {
if (ppUnknown) {
try {
ppUnknown->Release();
}
catch (...) {
// Never occurs
}
ppUnknown = nullptr;
}
}
UINT DpiForWindow(WindowID wid) noexcept;
int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept;

View File

@ -6,8 +6,8 @@
#include <windows.h>
#define VERSION_SCINTILLA "5.1.4"
#define VERSION_WORDS 5, 1, 4, 0
#define VERSION_SCINTILLA "5.1.5"
#define VERSION_WORDS 5, 1, 5, 0
VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_WORDS

View File

@ -93,6 +93,7 @@
#include "AutoComplete.h"
#include "ScintillaBase.h"
#include "WinTypes.h"
#include "PlatWin.h"
#include "HanjaDic.h"
#include "ScintillaWin.h"
@ -769,8 +770,7 @@ int InputCodePage() noexcept {
}
/** Map the key codes to their equivalent Keys:: form. */
Keys KeyTranslate(int keyIn) noexcept {
//PLATFORM_ASSERT(!keyIn);
Keys KeyTranslate(uptr_t keyIn) noexcept {
switch (keyIn) {
case VK_DOWN: return Keys::Down;
case VK_UP: return Keys::Up;
@ -1068,10 +1068,10 @@ void ScintillaWin::SelectionToHangul() {
pdoc->GetCharRange(&documentStr[0], selStart, documentStrLen);
std::wstring uniStr = StringDecode(documentStr, CodePageOfDocument());
const int converted = HanjaDict::GetHangulOfHanja(&uniStr[0]);
documentStr = StringEncode(uniStr, CodePageOfDocument());
const bool converted = HanjaDict::GetHangulOfHanja(uniStr);
if (converted > 0) {
if (converted) {
documentStr = StringEncode(uniStr, CodePageOfDocument());
pdoc->BeginUndoAction();
ClearSelection();
InsertPaste(&documentStr[0], documentStr.size());
@ -1691,7 +1691,7 @@ sptr_t ScintillaWin::KeyMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPa
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
const int ret = KeyDownWithModifiers(
static_cast<Keys>(KeyTranslate(static_cast<int>(wParam))),
KeyTranslate(wParam),
ModifierFlags(KeyboardIsKeyDown(VK_SHIFT),
KeyboardIsKeyDown(VK_CONTROL),
altDown),

View File

@ -0,0 +1,58 @@
// Scintilla source code edit control
/** @file WinTypes.h
** Implement safe release of COM objects and access to functions in DLLs.
** Header contains all implementation - there is no .cxx file.
**/
// Copyright 2020-2021 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#ifndef WINTYPES_H
#define WINTYPES_H
namespace Scintilla::Internal {
// Release an IUnknown* and set to nullptr.
// While IUnknown::Release must be noexcept, it isn't marked as such so produces
// warnings which are avoided by the catch.
template <class T>
inline void ReleaseUnknown(T *&ppUnknown) noexcept {
if (ppUnknown) {
try {
ppUnknown->Release();
} catch (...) {
// Never occurs
}
ppUnknown = nullptr;
}
}
struct UnknownReleaser {
// Called by unique_ptr to destroy/free the resource
template <class T>
void operator()(T *pUnknown) noexcept {
try {
pUnknown->Release();
} catch (...) {
// IUnknown::Release must not throw, ignore if it does.
}
}
};
/// Find a function in a DLL and convert to a function pointer.
/// This avoids undefined and conditionally defined behaviour.
template<typename T>
inline T DLLFunction(HMODULE hModule, LPCSTR lpProcName) noexcept {
if (!hModule) {
return nullptr;
}
FARPROC function = ::GetProcAddress(hModule, lpProcName);
static_assert(sizeof(T) == sizeof(function));
T fp {};
memcpy(&fp, &function, sizeof(T));
return fp;
}
}
#endif

View File

@ -1,7 +1,7 @@
# Created by DepGen.py. To recreate, run DepGen.py.
HanjaDic.o: \
HanjaDic.cxx \
../src/UniConversion.h \
WinTypes.h \
HanjaDic.h
PlatWin.o: \
PlatWin.cxx \
@ -12,6 +12,7 @@ PlatWin.o: \
../src/XPM.h \
../src/UniConversion.h \
../src/DBCS.h \
WinTypes.h \
PlatWin.h
ScintillaDLL.o: \
ScintillaDLL.cxx \
@ -57,6 +58,7 @@ ScintillaWin.o: \
../src/ElapsedPeriod.h \
../src/AutoComplete.h \
../src/ScintillaBase.h \
WinTypes.h \
PlatWin.h \
HanjaDic.h \
ScintillaWin.h

View File

@ -1,7 +1,7 @@
# Created by DepGen.py. To recreate, run DepGen.py.
$(DIR_O)/HanjaDic.obj: \
HanjaDic.cxx \
../src/UniConversion.h \
WinTypes.h \
HanjaDic.h
$(DIR_O)/PlatWin.obj: \
PlatWin.cxx \
@ -12,6 +12,7 @@ $(DIR_O)/PlatWin.obj: \
../src/XPM.h \
../src/UniConversion.h \
../src/DBCS.h \
WinTypes.h \
PlatWin.h
$(DIR_O)/ScintillaDLL.obj: \
ScintillaDLL.cxx \
@ -57,6 +58,7 @@ $(DIR_O)/ScintillaWin.obj: \
../src/ElapsedPeriod.h \
../src/AutoComplete.h \
../src/ScintillaBase.h \
WinTypes.h \
PlatWin.h \
HanjaDic.h \
ScintillaWin.h

View File

@ -618,26 +618,26 @@ bool EditIsRecodingNeeded(WCHAR* pszText, int cchLen)
//
// EditGetSelectedText()
//
size_t EditGetSelectedText(LPWSTR pwchBuffer, size_t wchLength)
size_t EditGetSelectedText(LPWSTR pwchBuffer, size_t wchCount)
{
if (!pwchBuffer || (wchLength == 0)) {
if (!pwchBuffer || (wchCount == 0)) {
return FALSE;
}
size_t const selSize = SciCall_GetSelText(NULL);
if (1 < selSize) {
char* const pszText = AllocMem(selSize, HEAP_ZERO_MEMORY);
size_t const selLen = SciCall_GetSelText(NULL);
if (0 < selLen) {
char* const pszText = AllocMem((selLen + 1), HEAP_ZERO_MEMORY);
if (pszText) {
SciCall_GetSelText(pszText);
size_t const length = (size_t)MultiByteToWideChar(Encoding_SciCP, 0, pszText, -1, pwchBuffer, (int)wchLength);
size_t const count = (size_t)MultiByteToWideChar(Encoding_SciCP, 0, pszText, -1, pwchBuffer, (int)wchCount);
FreeMem(pszText);
return length;
return count;
}
}
if (wchLength > 0) {
if (wchCount > 0) {
pwchBuffer[0] = L'\0';
return selSize;
return 1;
}
return FALSE;
return 0;
}
@ -852,12 +852,12 @@ bool EditSwapClipboard(HWND hwnd, bool bSkipUnicodeCheck)
UndoTransActionBegin();
char* pszText = NULL;
size_t const size = SciCall_GetSelText(NULL);
if (size > 0) {
pszText = AllocMem(size, HEAP_ZERO_MEMORY);
size_t const len = SciCall_GetSelText(NULL);
if (len > 0) {
pszText = AllocMem((len + 1), HEAP_ZERO_MEMORY);
SciCall_GetSelText(pszText);
SciCall_Paste(); //~SciCall_ReplaceSel(pClip);
EditSetClipboardText(hwnd, pszText, (size - 1));
EditSetClipboardText(hwnd, pszText, len);
} else {
SciCall_Paste(); //~SciCall_ReplaceSel(pClip);
SciCall_Clear();
@ -1532,7 +1532,7 @@ bool EditSaveFile(
if (bom) {
CopyMemory(lpData, bom, bomoffset);
}
SciCall_GetText((cbData + 1), &lpData[bomoffset]);
SciCall_GetText(cbData, &lpData[bomoffset]);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE *)lpData, (size_t)(cbData + bomoffset), &bytesWritten);
Globals.dwLastError = GetLastError();
FreeMem(lpData);
@ -1630,9 +1630,9 @@ bool EditSaveFile(
else {
if (IsEncryptionRequired()) {
char* const lpData = AllocMem(cbData + 1, HEAP_ZERO_MEMORY);
char* const lpData = AllocMem((cbData + 1), HEAP_ZERO_MEMORY);
if (lpData) {
SciCall_GetText((cbData + 1), lpData);
SciCall_GetText(cbData, lpData);
SetEndOfFile(hFile);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE *)lpData, (DWORD)cbData, &bytesWritten);
Globals.dwLastError = GetLastError();
@ -1678,12 +1678,12 @@ void EditInvertCase(HWND hwnd)
const DocPos iSelStart = SciCall_GetSelectionStart();
const DocPos iSelEnd = SciCall_GetSelectionEnd();
const DocPos iSelSize = SciCall_GetSelText(NULL);
const DocPos iSelLen = SciCall_GetSelText(NULL);
LPWSTR const pszTextW = AllocMem(iSelSize * sizeof(WCHAR), HEAP_ZERO_MEMORY);
LPWSTR const pszTextW = AllocMem((iSelLen + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (pszTextW) {
size_t const cchTextW = EditGetSelectedText(pszTextW, iSelSize);
size_t const cchTextW = EditGetSelectedText(pszTextW, (iSelLen + 1));
bool bChanged = false;
for (size_t i = 0; i < cchTextW; i++) {
@ -1697,8 +1697,8 @@ void EditInvertCase(HWND hwnd)
}
if (bChanged) {
char* const pszText = AllocMem(iSelSize, HEAP_ZERO_MEMORY);
WideCharToMultiByteEx(Encoding_SciCP, 0, pszTextW, cchTextW, pszText, iSelSize, NULL, NULL);
char* const pszText = AllocMem((iSelLen + 1), HEAP_ZERO_MEMORY);
WideCharToMultiByte(Encoding_SciCP, 0, pszTextW, (int)cchTextW, pszText, (int)(iSelLen + 1), NULL, NULL);
UndoTransActionBegin();
SciCall_Clear();
SciCall_AddText((iSelEnd - iSelStart), pszText);
@ -1729,23 +1729,23 @@ void EditTitleCase(HWND hwnd)
}
const DocPos iSelStart = SciCall_GetSelectionStart();
const DocPos iSelEnd = SciCall_GetSelectionEnd();
const DocPos iSelSize = SciCall_GetSelText(NULL);
const DocPos iSelLen = SciCall_GetSelText(NULL);
LPWSTR const pszTextW = AllocMem((iSelSize * sizeof(WCHAR)), HEAP_ZERO_MEMORY);
LPWSTR const pszTextW = AllocMem(((iSelLen + 1) * sizeof(WCHAR)), HEAP_ZERO_MEMORY);
if (pszTextW == NULL) {
FreeMem(pszTextW);
return;
}
size_t const cchTextW = EditGetSelectedText(pszTextW, iSelSize);
size_t const cchTextW = EditGetSelectedText(pszTextW, (iSelLen + 1));
bool bChanged = false;
LPWSTR const pszMappedW = AllocMem(SizeOfMem(pszTextW), HEAP_ZERO_MEMORY);
if (pszMappedW) {
// first make lower case, before applying TitleCase
if (LCMapString(LOCALE_SYSTEM_DEFAULT, (LCMAP_LINGUISTIC_CASING | LCMAP_LOWERCASE), pszTextW, (int)cchTextW, pszMappedW, (int)iSelSize)) {
if (LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TITLECASE, pszMappedW, (int)cchTextW, pszTextW, (int)iSelSize)) {
if (LCMapString(LOCALE_SYSTEM_DEFAULT, (LCMAP_LINGUISTIC_CASING | LCMAP_LOWERCASE), pszTextW, (int)cchTextW, pszMappedW, (int)(iSelLen + 1))) {
if (LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TITLECASE, pszMappedW, (int)cchTextW, pszTextW, (int)(iSelLen + 1))) {
bChanged = true;
}
}
@ -1753,8 +1753,8 @@ void EditTitleCase(HWND hwnd)
}
if (bChanged) {
char* pszText = AllocMem(iSelSize, HEAP_ZERO_MEMORY);
WideCharToMultiByteEx(Encoding_SciCP, 0, pszTextW, cchTextW, pszText, iSelSize, NULL, NULL);
char* pszText = AllocMem((iSelLen + 1), HEAP_ZERO_MEMORY);
WideCharToMultiByteEx(Encoding_SciCP, 0, pszTextW, cchTextW, pszText, (iSelLen + 1), NULL, NULL);
UndoTransActionBegin();
SciCall_Clear();
SciCall_AddText((iSelEnd - iSelStart), pszText);
@ -1783,16 +1783,16 @@ void EditSentenceCase(HWND hwnd)
}
const DocPos iSelStart = SciCall_GetSelectionStart();
const DocPos iSelEnd = SciCall_GetSelectionEnd();
const DocPos iSelSize = SciCall_GetSelText(NULL);
const DocPos iSelLen = SciCall_GetSelText(NULL);
LPWSTR const pszTextW = AllocMem((iSelSize * sizeof(WCHAR)), HEAP_ZERO_MEMORY);
LPWSTR const pszTextW = AllocMem(((iSelLen + 1) * sizeof(WCHAR)), HEAP_ZERO_MEMORY);
if (pszTextW == NULL) {
FreeMem(pszTextW);
return;
}
size_t const cchTextW = EditGetSelectedText(pszTextW, iSelSize);
size_t const cchTextW = EditGetSelectedText(pszTextW, (iSelLen + 1));
bool bChanged = false;
bool bNewSentence = true;
@ -1818,8 +1818,8 @@ void EditSentenceCase(HWND hwnd)
}
if (bChanged) {
char* pszText = AllocMem(iSelSize, HEAP_ZERO_MEMORY);
WideCharToMultiByteEx(Encoding_SciCP, 0, pszTextW, cchTextW, pszText, iSelSize, NULL, NULL);
char* const pszText = AllocMem((iSelLen + 1), HEAP_ZERO_MEMORY);
WideCharToMultiByteEx(Encoding_SciCP, 0, pszTextW, cchTextW, pszText, (iSelLen + 1), NULL, NULL);
UndoTransActionBegin();
SciCall_Clear();
SciCall_AddText((iSelEnd - iSelStart), pszText);
@ -1848,17 +1848,17 @@ void EditURLEncode(const bool isPathConvert)
DocPos const iSelStart = SciCall_GetSelectionStart();
//DocPos const iSelEnd = SciCall_GetSelectionEnd();
DocPos const iSelSize = SciCall_GetSelText(NULL) - 1; // w/o terminating zero
DocPos const iSelLen = SciCall_GetSelText(NULL);
bool const bStraightSel = (SciCall_GetAnchor() <= SciCall_GetCurrentPos());
const char* const pszText = (const char*)SciCall_GetRangePointer(iSelStart, iSelSize);
const char* const pszText = (const char*)SciCall_GetRangePointer(iSelStart, iSelLen);
WCHAR szTextW[INTERNET_MAX_URL_LENGTH+1];
ptrdiff_t const cchTextW = MultiByteToWideChar(Encoding_SciCP, 0, pszText, (int)iSelSize, szTextW, INTERNET_MAX_URL_LENGTH);
ptrdiff_t const cchTextW = MultiByteToWideChar(Encoding_SciCP, 0, pszText, (int)iSelLen, szTextW, INTERNET_MAX_URL_LENGTH);
szTextW[cchTextW] = L'\0';
StrTrim(szTextW, L" \r\n\t");
size_t const cchEscaped = iSelSize * 3 + 1;
size_t const cchEscaped = iSelLen * 3 + 1;
char* const pszEscaped = (char*)AllocMem(cchEscaped, HEAP_ZERO_MEMORY);
if (pszEscaped == NULL) {
return;
@ -1921,19 +1921,19 @@ void EditURLDecode(const bool isPathConvert)
DocPos const iSelStart = SciCall_GetSelectionStart();
//DocPos const iSelEnd = SciCall_GetSelectionEnd();
DocPos const iSelSize = SciCall_GetSelText(NULL) - 1; // w/o terminating zero
DocPos const iSelLen = SciCall_GetSelText(NULL);
bool const bStraightSel = (SciCall_GetAnchor() <= SciCall_GetCurrentPos());
const char * const pszText = SciCall_GetRangePointer(iSelStart, iSelSize);
const char* const pszText = SciCall_GetRangePointer(iSelStart, iSelLen);
LPWSTR const pszTextW = AllocMem((iSelSize + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
LPWSTR const pszTextW = AllocMem((iSelLen + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (pszTextW == NULL) {
return;
}
/*int cchTextW =*/ MultiByteToWideChar(Encoding_SciCP, 0, pszText, (int)iSelSize, pszTextW, (int)iSelSize);
/*int cchTextW =*/MultiByteToWideChar(Encoding_SciCP, 0, pszText, (int)iSelLen, pszTextW, (int)(iSelLen + 1));
size_t const cchUnescaped = iSelSize * 3 + 1;
size_t const cchUnescaped = iSelLen * 3 + 1;
char* const pszUnescaped = (char*)AllocMem(cchUnescaped, HEAP_ZERO_MEMORY);
if (pszUnescaped == NULL) {
FreeMem(pszTextW);
@ -2001,17 +2001,17 @@ void EditReplaceAllChr(const WCHAR chSearch, const WCHAR chReplace) {
DocPos const iSelStart = SciCall_GetSelectionStart();
DocPos const iSelEnd = SciCall_GetSelectionEnd();
DocPos const iSelSize = SciCall_GetSelText(NULL) - 1; // w/o terminating zero
DocPos const iSelLen = SciCall_GetSelText(NULL);
bool const bStraightSel = (SciCall_GetAnchor() <= SciCall_GetCurrentPos());
const char *pchText = SciCall_GetRangePointer(iSelStart, iSelSize);
const char* pchText = SciCall_GetRangePointer(iSelStart, iSelLen);
int const reqsize = MultiByteToWideChar(Encoding_SciCP, 0, pchText, (int)iSelSize, NULL, 0);
int const reqsize = MultiByteToWideChar(Encoding_SciCP, 0, pchText, (int)iSelLen, NULL, 0);
LPWSTR const pwchText = AllocMem(((size_t)reqsize + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (pwchText == NULL) {
return;
}
MultiByteToWideChar(Encoding_SciCP, 0, pchText, (int)iSelSize, pwchText, (int)reqsize);
MultiByteToWideChar(Encoding_SciCP, 0, pchText, (int)iSelLen, pwchText, (int)reqsize);
StrReplChr(pwchText, chSearch, chReplace);
@ -2060,17 +2060,17 @@ void EditBase64Code(HWND hwnd, const bool bEncode, cpi_enc_t cpi) {
//DocPos const iSelEnd = SciCall_GetSelectionEnd();
bool const bStraightSel = (SciCall_GetAnchor() <= SciCall_GetCurrentPos());
size_t iSelSize = SciCall_GetSelText(NULL) - 1; // w/o terminating zero
char * pchText = (char *)SciCall_GetRangePointer(iSelStart, (DocPos)iSelSize);
size_t iSelLen = SciCall_GetSelText(NULL);
char* pchText = (char*)SciCall_GetRangePointer(iSelStart, (DocPos)iSelLen);
bool bAllocatedText = false;
if (bEncode && (codePage != Encoding_SciCP)) {
int new_size = 0;
pchText = (char *)EditReInterpretText(pchText, (int)iSelSize, Enc_SciCPI, cpi, &new_size);
pchText = (char*)EditReInterpretText(pchText, (int)iSelLen, Enc_SciCPI, cpi, &new_size);
bAllocatedText = true;
iSelSize = (size_t)new_size;
iSelLen = (size_t)new_size;
}
if (iSelSize == 0) {
if (iSelLen == 0) {
if (bAllocatedText) {
FreeMem(pchText);
pchText = NULL;
@ -2079,8 +2079,8 @@ void EditBase64Code(HWND hwnd, const bool bEncode, cpi_enc_t cpi) {
}
size_t base64Size = 0;
char * pBase64CodedTxt = (char *)(bEncode ? Encoding_Base64Encode((unsigned char *)pchText, iSelSize, &base64Size) :
Encoding_Base64Decode((unsigned char *)pchText, iSelSize, &base64Size));
char* pBase64CodedTxt = (char*)(bEncode ? Encoding_Base64Encode((unsigned char*)pchText, iSelLen, &base64Size) :
Encoding_Base64Decode((unsigned char*)pchText, iSelLen, &base64Size));
if (bAllocatedText) {
FreeMem(pchText);
@ -2209,7 +2209,7 @@ void EditChar2Hex(HWND hwnd)
if (bSelEmpty) {
SciCall_SetSelection(iCurPos, iAnchorPos);
}
DocPos const count = Sci_GetSelTextLength();
DocPos const count = SciCall_GetSelText(NULL);
char const uesc = 'u';
//???char const uesc = (LEXER == CSHARP) ? 'x' : 'u'; // '\xn[n][n][n]' - variable length version
@ -2221,7 +2221,7 @@ void EditChar2Hex(HWND hwnd)
// break;
//}
size_t const alloc = count * (2 + MAX_ESCAPE_HEX_DIGIT) + 1;
size_t const alloc = (count + 1) * (2 + MAX_ESCAPE_HEX_DIGIT) + 1;
char* const ch = (char*)AllocMem(alloc, HEAP_ZERO_MEMORY);
WCHAR* const wch = (WCHAR*)AllocMem(alloc * sizeof(WCHAR), HEAP_ZERO_MEMORY);
@ -2279,12 +2279,12 @@ void EditHex2Char(HWND hwnd)
DocPos const iCurPos = SciCall_GetCurrentPos();
DocPos const iAnchorPos = SciCall_GetAnchor();
DocPos const count = Sci_GetSelTextLength();
DocPos const count = SciCall_GetSelText(NULL);
if (count <= 0) {
return;
}
size_t const alloc = count * (2 + MAX_ESCAPE_HEX_DIGIT) + 1;
size_t const alloc = (count + 1) * (2 + MAX_ESCAPE_HEX_DIGIT) + 1;
char* const ch = (char*)AllocMem(alloc, HEAP_ZERO_MEMORY);
SciCall_GetSelText(ch);
@ -2382,7 +2382,8 @@ void EditModifyNumber(HWND hwnd,bool bIncrease)
if ((iSelEnd - iSelStart) > 0) {
char chNumber[32] = { '\0' };
if (SciCall_GetSelText(NULL) <= COUNTOF(chNumber)) {
if (SciCall_GetSelText(NULL) < COUNTOF(chNumber)) {
SciCall_GetSelText(chNumber);
if (StrChrIA(chNumber, '-')) {
@ -4318,11 +4319,11 @@ void EditCompressBlanks()
cch = SciCall_GetTextLength();
} else {
pszIn = (const char*)SciCall_GetRangePointer(iSelStartPos, iSelLength + 1);
cch = SciCall_GetSelText(NULL) - 1;
cch = SciCall_GetSelText(NULL);
bIsLineStart = (iSelStartPos == SciCall_PositionFromLine(iLineStart));
bIsLineEnd = (iSelEndPos == SciCall_GetLineEndPosition(iLineEnd));
}
char* const pszOut = (char*)AllocMem(cch + 1, HEAP_ZERO_MEMORY);
char* const pszOut = (char*)AllocMem((cch + 1), HEAP_ZERO_MEMORY);
if (pszIn && pszOut) {
bool bModified = false;
@ -6489,8 +6490,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
if (Globals.bFindReplCopySelOrClip) {
char* lpszSelection = NULL;
DocPos const cchSelection = SciCall_GetSelText(NULL);
if ((cchSelection > 1) && (LOWORD(wParam) != IDC_REPLACETEXT)) {
lpszSelection = AllocMem(cchSelection + 1, HEAP_ZERO_MEMORY);
if ((cchSelection > 0) && (LOWORD(wParam) != IDC_REPLACETEXT)) {
lpszSelection = AllocMem((cchSelection + 1), HEAP_ZERO_MEMORY);
SciCall_GetSelText(lpszSelection);
} else { // (cchSelection <= 1)
// nothing is selected in the editor:
@ -7182,8 +7183,7 @@ void EditMarkAllOccurrences(HWND hwnd, bool bForceClear)
//
void EditSelectionMultiSelectAll()
{
if (SciCall_GetSelText(NULL) > 1) {
if (SciCall_GetSelText(NULL) > 0) {
SciCall_TargetWholeDocument();
SciCall_SetSearchFlags(GetMarkAllOccSearchFlags());
SciCall_MultipleSelectAddEach();
@ -7590,7 +7590,7 @@ void EditMarkAll(LPCWSTR wchFind, int sFlags, DocPos rangeStart, DocPos rangeEnd
__leave;
}
iFindLength = SciCall_GetSelText(pchText) - 1;
iFindLength = SciCall_GetSelText(pchText);
// exit if selection is not a word and Match whole words only is enabled
if (sFlags & SCFIND_WHOLEWORD) {

View File

@ -31,7 +31,7 @@ void EditSetNewText(HWND hwnd,const char* lpstrText, DocPosU lenText,bool);
bool EditConvertText(HWND hwnd, cpi_enc_t encSource, cpi_enc_t encDest);
bool EditSetNewEncoding(HWND hwnd, cpi_enc_t iNewEncoding,bool bSupressWarning);
bool EditIsRecodingNeeded(WCHAR* pszText,int cchLen);
size_t EditGetSelectedText(LPWSTR pwchBuffer, size_t wchLength);
size_t EditGetSelectedText(LPWSTR pwchBuffer, size_t wchCount);
char* EditGetClipboardText(HWND hwnd,bool,int* pLineCount,int* pLenLastLn);
void EditGetClipboardW(LPWSTR pwchBuffer, size_t wchLength);
bool EditSetClipboardText(HWND hwnd, const char* pszText, size_t cchText);

View File

@ -1457,8 +1457,8 @@ static bool SetCurrentSelAsFindReplaceData()
size_t const cchSelection = SciCall_GetSelText(NULL);
if (1 < cchSelection) {
char* szSelection = AllocMem(cchSelection, HEAP_ZERO_MEMORY);
if (0 < cchSelection) {
char* const szSelection = AllocMem((cchSelection + 1), HEAP_ZERO_MEMORY);
if (szSelection) {
SciCall_GetSelText(szSelection);
SetFindPatternMB(szSelection);
@ -2301,20 +2301,20 @@ static bool _EvalTinyExpr(bool qmark)
}
if (chBefore == '=') { // got "=?" or ENTER : evaluate expression trigger
int const lineLen = (int)SciCall_LineLength(SciCall_LineFromPosition(posSelStart)) + 1;
char *lineBuf = (char *)AllocMem(lineLen, HEAP_ZERO_MEMORY);
WCHAR *lineBufW = (WCHAR *)AllocMem(lineLen * sizeof(WCHAR), HEAP_ZERO_MEMORY);
int const lineLen = (int)SciCall_LineLength(SciCall_LineFromPosition(posSelStart));
char * const lineBuf = (char *)AllocMem((lineLen + 1), HEAP_ZERO_MEMORY);
WCHAR * const lineBufW = (WCHAR *)AllocMem((lineLen + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (lineBuf && lineBufW) {
if (posSelStart < SciCall_GetCurrentPos()) {
SciCall_SwapMainAnchorCaret();
}
DocPos const iLnCaretPos = SciCall_GetCurLine((lineLen - 1), lineBuf);
DocPos const iLnCaretPos = SciCall_GetCurLine(lineLen, lineBuf);
lineBuf[iLnCaretPos - (posSelStart - posBefore)] = '\0'; // exclude "=?"
char const defchar = (char)te_invalid_chr();
MultiByteToWideChar(Encoding_SciCP, 0, lineBuf, -1, lineBufW, lineLen);
int const len = WideCharToMultiByte(te_cp(), (WC_COMPOSITECHECK | WC_DISCARDNS), lineBufW, -1, lineBuf, lineLen, &defchar, NULL);
MultiByteToWideChar(Encoding_SciCP, 0, lineBuf, -1, lineBufW, (lineLen + 1));
int const len = WideCharToMultiByte(te_cp(), (WC_COMPOSITECHECK | WC_DISCARDNS), lineBufW, -1, lineBuf, (lineLen + 1), &defchar, NULL);
FreeMem(lineBufW);
if (!len) {
return false;
@ -3404,7 +3404,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam)
SetDlgItemInt(hwnd, IDC_REUSELOCK, GetTickCount(), false);
if (pcds->dwData == DATA_NOTEPAD3_PARAMS) {
LPnp3params params = AllocMem(pcds->cbData, HEAP_ZERO_MEMORY);
LPnp3params const params = AllocMem(pcds->cbData, HEAP_ZERO_MEMORY);
if (params) {
CopyMemory(params, pcds->lpData, pcds->cbData);
@ -7637,7 +7637,7 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
if (cchTextW > 0) {
DWORD cchEscapedW = (DWORD)(length * 3 + 1);
LPWSTR pszEscapedW = (LPWSTR)AllocMem(cchEscapedW * sizeof(WCHAR), HEAP_ZERO_MEMORY);
LPWSTR const pszEscapedW = (LPWSTR)AllocMem(cchEscapedW * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (pszEscapedW) {
//~UrlEscape(szTextW, pszEscapedW, &cchEscapedW, (URL_BROWSER_MODE | URL_ESCAPE_AS_UTF8));
UrlEscapeEx(szTextW, pszEscapedW, &cchEscapedW, false);
@ -7902,7 +7902,7 @@ static void _HandleAutoIndent(int const charAdded)
{
DocLn const iPrevLine = iCurLine - 1;
DocPos const iPrevLineLength = SciCall_LineLength(iPrevLine);
char* pLineBuf = (char*)AllocMem(iPrevLineLength + 1, HEAP_ZERO_MEMORY);
char * const pLineBuf = (char*)AllocMem(iPrevLineLength + 1, HEAP_ZERO_MEMORY);
if (pLineBuf) {
SciCall_GetLine_Safe(iPrevLine, pLineBuf);
for (char* pPos = pLineBuf; *pPos; pPos++) {
@ -8648,9 +8648,9 @@ void ParseCommandLine()
StrTab2Space(lpCmdLine);
DocPos const len = (DocPos)(StringCchLenW(lpCmdLine,0) + 2UL);
LPWSTR lp1 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY);
LPWSTR lp2 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY);
LPWSTR lp3 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY);
LPWSTR const lp1 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY);
LPWSTR const lp2 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY);
LPWSTR const lp3 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY);
if (lp1 && lp2 && lp3) {
bool bIsNotepadReplacement = false;
@ -9021,7 +9021,7 @@ void ParseCommandLine()
}
// pathname
else {
LPWSTR lpFileBuf = AllocMem(sizeof(WCHAR) * len, HEAP_ZERO_MEMORY);
LPWSTR const lpFileBuf = AllocMem(sizeof(WCHAR) * len, HEAP_ZERO_MEMORY);
if (lpFileBuf) {
size_t const fileArgLen = StringCchLenW(lp3, len);
@ -9029,7 +9029,7 @@ void ParseCommandLine()
if (s_lpOrigFileArg) {
FreeMem(s_lpOrigFileArg);
//s_lpOrigFileArg = NULL;
s_lpOrigFileArg = NULL;
}
s_lpOrigFileArg = AllocMem(sizeof(WCHAR)*(fileArgLen + 1), HEAP_ZERO_MEMORY); // changed for ActivatePrevInst() needs
StringCchCopy(s_lpOrigFileArg, fileArgLen + 1, lp3);
@ -9055,7 +9055,6 @@ void ParseCommandLine()
StringCchCopy(lp3, len, lp2);
}
}
FreeMem(lp1);
FreeMem(lp2);
FreeMem(lp3);
@ -9347,8 +9346,8 @@ static double _InterpMultiSelectionTinyExpr(te_xint_t* piExprError)
DocPosU const selCount = SciCall_GetSelections();
int const calcBufSize = (int)(_tmpBufCnt * selCount + 1);
char* calcBuffer = (char*)AllocMem(calcBufSize, HEAP_ZERO_MEMORY);
WCHAR* calcBufferW = (WCHAR*)AllocMem(calcBufSize * sizeof(WCHAR), HEAP_ZERO_MEMORY);
char * const calcBuffer = (char*)AllocMem(calcBufSize, HEAP_ZERO_MEMORY);
WCHAR * const calcBufferW = (WCHAR*)AllocMem(calcBufSize * sizeof(WCHAR), HEAP_ZERO_MEMORY);
bool bLastCharWasDigit = false;
for (DocPosU i = 0; i < selCount; ++i) {
@ -9603,8 +9602,8 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw)
if (bIsSelCharCountable) {
static char chSeBuf[LARGE_BUFFER] = { '\0' };
static WCHAR wchSelBuf[LARGE_BUFFER] = { L'\0' };
DocPos const iSelSize = SciCall_GetSelText(NULL);
if (iSelSize < COUNTOF(chSeBuf)) { // should be fast !
DocPos const iSelLen = SciCall_GetSelText(NULL);
if (iSelLen < COUNTOF(chSeBuf)) { // should be fast !
SciCall_GetSelText(chSeBuf);
//~StrDelChrA(chExpression, " \r\n\t\v");
StrDelChrA(chSeBuf, "\r\n");
@ -10701,7 +10700,7 @@ bool FileLoad(const HPATHL hfile_pth, FileLoadFlags fLoadFlags)
// the .LOG feature ...
if (SciCall_GetTextLength() >= 4) {
char tchLog[5] = { '\0', '\0', '\0', '\0', '\0' };
SciCall_GetText(COUNTOF(tchLog), tchLog);
SciCall_GetText(COUNTOF(tchLog) - 1, tchLog);
if (StringCchCompareXA(tchLog, ".LOG") == 0) {
SciCall_DocumentEnd();
UndoTransActionBegin();
@ -10829,7 +10828,7 @@ bool FileRevert(const HPATHL hfile_pth, bool bIgnoreCmdLnEnc)
if (SciCall_GetTextLength() >= 4) {
char tch[5] = { '\0', '\0', '\0', '\0', '\0' };
SciCall_GetText(COUNTOF(tch), tch);
SciCall_GetText(COUNTOF(tch) - 1, tch);
if (StringCchCompareXA(tch, ".LOG") == 0) {
SciCall_ClearSelections();
bPreserveView = false;
@ -10868,8 +10867,8 @@ bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus, bool bAutoSaveOnRelaunch)
LPWSTR lpCmdLine = GetCommandLine();
size_t const wlen = StringCchLen(lpCmdLine, 0) + 2;
LPWSTR lpExe = AllocMem(sizeof(WCHAR) * wlen, HEAP_ZERO_MEMORY);
LPWSTR lpArgs = AllocMem(sizeof(WCHAR) * wlen, HEAP_ZERO_MEMORY);
LPWSTR const lpExe = AllocMem(sizeof(WCHAR) * wlen, HEAP_ZERO_MEMORY);
LPWSTR const lpArgs = AllocMem(sizeof(WCHAR) * wlen, HEAP_ZERO_MEMORY);
// ~ don't use original argument list (try to reconstruct current state as close as possible
#if 0
@ -10986,7 +10985,7 @@ bool FileSave(FileSaveFlags fSaveFlags)
bIsEmptyNewFile = true;
} else if (cchText < 2048) {
char chTextBuf[2048] = { '\0' };
SciCall_GetText(COUNTOF(chTextBuf), chTextBuf);
SciCall_GetText(COUNTOF(chTextBuf) - 1, chTextBuf);
StrTrimA(chTextBuf, " \t\n\r");
if (StrIsEmptyA(chTextBuf)) {
bIsEmptyNewFile = true;

View File

@ -340,7 +340,7 @@ DeclareSciCallV2(CopyRange, COPYRANGE, DocPos, start, DocPos, end);
DeclareSciCallV0(Cancel, CANCEL);
DeclareSciCallV0(CopyAllowLine, COPYALLOWLINE);
DeclareSciCallV2(CopyText, COPYTEXT, DocPos, length, const char*, text);
DeclareSciCallR2(GetText, GETTEXT, DocPos, DocPos, length, const char*, text);
DeclareSciCallR2(GetText, GETTEXT, DocPos, DocPos, length, const char*, text); // NULL: w/o terminating '\0' (SCI v515)
DeclareSciCallR01(GetTextRange, GETTEXTRANGE, DocPos, struct Sci_TextRange*, textrange);
DeclareSciCallV0(UpperCase, UPPERCASE);
DeclareSciCallV0(LowerCase, LOWERCASE);
@ -352,7 +352,7 @@ DeclareSciCallV2(ReplaceRectangular, REPLACERECTANGULAR, DocPos, length, const c
DeclareSciCallV2(SetSel, SETSEL, DocPos, anchorPos, DocPos, currentPos);
DeclareSciCallV0(SelectAll, SELECTALL);
DeclareSciCallR01(GetSelText, GETSELTEXT, size_t, const char*, text);
DeclareSciCallR01(GetSelText, GETSELTEXT, size_t, const char*, text); // NULL: w/o terminating '\0' (SCI v515)
DeclareSciCallV01(ReplaceSel, REPLACESEL, const char*, text);
DeclareSciCallV2(InsertText, INSERTTEXT, DocPos, position, const char*, text);
DeclareSciCallV2(AppendText, APPENDTEXT, DocPos, length, const char*, text);
@ -406,7 +406,7 @@ DeclareSciCallR0(GetCharacterPointer, GETCHARACTERPOINTER, const char *const);
DeclareSciCallR2(GetRangePointer, GETRANGEPOINTER, char *const, DocPos, start, DocPos, length);
DeclareSciCallR2(GetLine, GETLINE, DocPos, DocLn, line, const char*, text);
DeclareSciCallR2(GetCurLine, GETCURLINE, DocPos, unsigned int, length, const char*, text);
DeclareSciCallR2(GetCurLine, GETCURLINE, DocPos, unsigned int, length, const char*, text); // NULL: w/o terminating '\0' (SCI v515)
inline DocPos SciCall_GetLine_Safe(DocLn iLine, char* pTxtBuf)
{
@ -729,9 +729,6 @@ DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool);
#define Sci_IsForwardSelection() (SciCall_GetAnchor() <= SciCall_GetCurrentPos())
// w/o terminating '\0'
#define Sci_GetSelTextLength() (SciCall_GetSelText(NULL) - 1)
#define Sci_HaveUndoRedoHistory() (SciCall_CanUndo() || SciCall_CanRedo())
#define Sci_GetCurrentLineNumber() SciCall_LineFromPosition(SciCall_GetCurrentPos())

View File

@ -2387,7 +2387,7 @@ bool Style_SetLexerFromFile(HWND hwnd, const HPATHL hpath)
if (!Flags.NoCGIGuess && (StringCchCompareNI(wchMode,COUNTOF(wchMode),L"cgi", CONSTSTRGLEN(L"cgi")) == 0 ||
StringCchCompareNI(wchMode,COUNTOF(wchMode),L"fcgi", CONSTSTRGLEN(L"fcgi")) == 0)) {
char tchText[256] = { '\0' };
SciCall_GetText(COUNTOF(tchText), tchText);
SciCall_GetText(COUNTOF(tchText) - 1, tchText);
StrTrimA(tchText," \t\n\r");
pLexSniffed = Style_SniffShebang(tchText);
if (pLexSniffed) {
@ -2434,7 +2434,7 @@ bool Style_SetLexerFromFile(HWND hwnd, const HPATHL hpath)
if (!Flags.NoCGIGuess && (StringCchCompareXI(lpszExt,L"cgi") == 0 || StringCchCompareXI(lpszExt,L"fcgi") == 0)) {
char tchText[256] = { '\0' };
SciCall_GetText(COUNTOF(tchText), tchText);
SciCall_GetText(COUNTOF(tchText) - 1, tchText);
StrTrimA(tchText," \t\n\r");
pLexSniffed = Style_SniffShebang(tchText);
if (pLexSniffed) {
@ -2455,7 +2455,7 @@ bool Style_SetLexerFromFile(HWND hwnd, const HPATHL hpath)
if (!bFound && s_bAutoSelect && (!Flags.NoHTMLGuess || !Flags.NoCGIGuess)) {
char tchText[512] = { '\0' };
SciCall_GetText(COUNTOF(tchText), tchText);
SciCall_GetText(COUNTOF(tchText) - 1, tchText);
StrTrimA(tchText," \t\n\r");
if (!Flags.NoCGIGuess) {
if (tchText[0] == '<') {
@ -2500,7 +2500,7 @@ bool Style_MaybeBinaryFile(HWND hwnd, const HPATHL hpath)
UNREFERENCED_PARAMETER(lpszFile);
#else
unsigned char buf[5] = { '\0' }; // magic
SciCall_GetText(COUNTOF(buf), (char*)buf);
SciCall_GetText(COUNTOF(buf) - 1, (char*)buf);
UINT const magic2 = (buf[0] << 8) | buf[1];
if (magic2 == 0x4D5AU || // PE: MZ
magic2 == 0x504BU || // ZIP: PK