Merge pull request #457 from RaiKoHoff/BugFixes_RC_III

Bugfixes RC III
This commit is contained in:
Derick Payne 2018-04-24 23:24:34 +02:00 committed by GitHub
commit 6265442caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 255 additions and 243 deletions

View File

@ -338,11 +338,6 @@ public:
virtual void SetDBCSMode(int codePage)=0;
};
/**
* A simple callback action passing one piece of untyped user data.
*/
typedef void (*CallBackAction)(void*);
/**
* Class to hide the details of window manipulation.
* Does not own the window which will normally have a longer life than this object.

View File

@ -8,8 +8,8 @@
// The License.txt file describes the conditions under which this software may be distributed.
#include <algorithm>
#include <iterator>
#include "StringCopy.h"
#include "CharacterCategory.h"
namespace Scintilla {
@ -3679,7 +3679,6 @@ const int catRanges[] = {
const int maxUnicode = 0x10ffff;
const int maskCategory = 0x1F;
const int nRanges = ELEMENTS(catRanges);
}
@ -3698,7 +3697,7 @@ CharacterCategory CategoriseCharacter(int character) {
if (character < 0 || character > maxUnicode)
return ccCn;
const int baseValue = character * (maskCategory+1) + maskCategory;
const int *placeAfter = std::lower_bound(catRanges, catRanges+nRanges, baseValue);
const int *placeAfter = std::lower_bound(catRanges, std::end(catRanges), baseValue);
return static_cast<CharacterCategory>(*(placeAfter-1) & maskCategory);
}

View File

@ -106,7 +106,7 @@ public:
return true;
}
char StyleAt(Sci_Position position) const {
return static_cast<char>(pAccess->StyleAt(position));
return pAccess->StyleAt(position);
}
Sci_Position GetLine(Sci_Position position) const {
return pAccess->LineFromPosition(position);

View File

@ -26,8 +26,8 @@ bool StyleContext::MatchIgnoreCase(const char *s) {
return false;
s++;
for (int n = 2; *s; n++) {
if (static_cast<unsigned char>(*s) !=
MakeLowerCase(static_cast<unsigned char>(styler.SafeGetCharAt(currentPos + n, 0))))
if (*s !=
MakeLowerCase(styler.SafeGetCharAt(currentPos + n, 0)))
return false;
s++;
}
@ -58,7 +58,7 @@ static void getRangeLowered(Sci_PositionU start,
Sci_PositionU len) {
Sci_PositionU i = 0;
while ((i < end - start + 1) && (i < len-1)) {
s[i] = static_cast<char>(tolower(styler[start + i]));
s[i] = MakeLowerCase(styler[start + i]);
i++;
}
s[i] = '\0';

View File

@ -113,7 +113,7 @@ static int cmpWords(const void *a, const void *b) {
}
static void SortWordList(char **words, unsigned int len) {
qsort(static_cast<void *>(words), len, sizeof(*words), cmpWords);
qsort(words, len, sizeof(*words), cmpWords);
}
#endif
@ -147,7 +147,7 @@ bool WordList::InList(const char *s) const {
const unsigned char firstChar = s[0];
int j = starts[firstChar];
if (j >= 0) {
while (static_cast<unsigned char>(words[j][0]) == firstChar) {
while (words[j][0] == firstChar) {
if (s[1] == words[j][1]) {
const char *a = words[j] + 1;
const char *b = s + 1;
@ -189,7 +189,7 @@ bool WordList::InListAbbreviated(const char *s, const char marker) const {
const unsigned char firstChar = s[0];
int j = starts[firstChar];
if (j >= 0) {
while (static_cast<unsigned char>(words[j][0]) == firstChar) {
while (words[j][0] == firstChar) {
bool isSubword = false;
int start = 1;
if (words[j][1] == marker) {
@ -243,7 +243,7 @@ bool WordList::InListAbridged(const char *s, const char marker) const {
const unsigned char firstChar = s[0];
int j = starts[firstChar];
if (j >= 0) {
while (static_cast<unsigned char>(words[j][0]) == firstChar) {
while (words[j][0] == firstChar) {
const char *a = words[j];
const char *b = s;
while (*a && *a == *b) {

View File

@ -563,8 +563,7 @@ class CaseConverter : public ICaseConverter {
enum { maxConversionLength=6 };
struct ConversionString {
char conversion[maxConversionLength+1];
ConversionString() {
conversion[0] = '\0';
ConversionString() : conversion{} {
}
};
// Conversions are initially store in a vector of structs but then decomposed into
@ -572,10 +571,10 @@ class CaseConverter : public ICaseConverter {
struct CharacterConversion {
int character;
ConversionString conversion;
CharacterConversion(int character_=0, const char *conversion_="") : character(character_) {
CharacterConversion(int character_=0, const char *conversion_="") noexcept : character(character_) {
StringCopy(conversion.conversion, conversion_);
}
bool operator<(const CharacterConversion &other) const {
bool operator<(const CharacterConversion &other) const noexcept {
return character < other.character;
}
};
@ -607,9 +606,9 @@ public:
size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixed, size_t lenMixed) override {
size_t lenConverted = 0;
size_t mixedPos = 0;
unsigned char bytes[UTF8MaxBytes + 1];
unsigned char bytes[UTF8MaxBytes + 1]{};
while (mixedPos < lenMixed) {
const unsigned char leadByte = static_cast<unsigned char>(mixed[mixedPos]);
const unsigned char leadByte = mixed[mixedPos];
const char *caseConverted = 0;
size_t lenMixedChar = 1;
if (UTF8IsAscii(leadByte)) {
@ -705,10 +704,10 @@ void SetupConversions(enum CaseConversion conversion) {
while (*sComplex) {
// Longest ligature is 3 character so 5 for safety
const size_t lenUTF8 = 5*UTF8MaxBytes+1;
char originUTF8[lenUTF8];
char foldedUTF8[lenUTF8];
char lowerUTF8[lenUTF8];
char upperUTF8[lenUTF8];
unsigned char originUTF8[lenUTF8]{};
char foldedUTF8[lenUTF8]{};
char lowerUTF8[lenUTF8]{};
char upperUTF8[lenUTF8]{};
size_t i = 0;
while (*sComplex && *sComplex != '|') {
originUTF8[i++] = *sComplex;
@ -738,7 +737,7 @@ void SetupConversions(enum CaseConversion conversion) {
sComplex++;
lowerUTF8[i] = 0;
const int character = UnicodeFromUTF8(reinterpret_cast<unsigned char *>(originUTF8));
const int character = UnicodeFromUTF8(originUTF8);
if (conversion == CaseConversionFold && foldedUTF8[0]) {
caseConvFold.Add(character, foldedUTF8);

View File

@ -17,7 +17,7 @@ using namespace Scintilla;
CaseFolder::~CaseFolder() {
}
CaseFolderTable::CaseFolderTable() {
CaseFolderTable::CaseFolderTable() : mapping{} {
for (size_t iChar=0; iChar<sizeof(mapping); iChar++) {
mapping[iChar] = static_cast<char>(iChar);
}

View File

@ -35,9 +35,9 @@ public:
virtual void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) = 0;
virtual void SetLineStart(Sci::Line line, Sci::Position position) = 0;
virtual void RemoveLine(Sci::Line line) = 0;
virtual Sci::Line Lines() const = 0;
virtual Sci::Line LineFromPosition(Sci::Position pos) const = 0;
virtual Sci::Position LineStart(Sci::Line line) const = 0;
virtual Sci::Line Lines() const noexcept = 0;
virtual Sci::Line LineFromPosition(Sci::Position pos) const noexcept = 0;
virtual Sci::Position LineStart(Sci::Line line) const noexcept = 0;
virtual ~ILineVector() {}
};
@ -84,13 +84,13 @@ public:
perLine->RemoveLine(line);
}
}
Sci::Line Lines() const override {
Sci::Line Lines() const noexcept override {
return static_cast<Sci::Line>(starts.Partitions());
}
Sci::Line LineFromPosition(Sci::Position pos) const override {
Sci::Line LineFromPosition(Sci::Position pos) const noexcept override {
return static_cast<Sci::Line>(starts.PartitionFromPosition(static_cast<POS>(pos)));
}
Sci::Position LineStart(Sci::Line line) const override {
Sci::Position LineStart(Sci::Line line) const noexcept override {
return starts.PositionFromPartition(static_cast<POS>(line));
}
};
@ -377,12 +377,12 @@ CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) :
CellBuffer::~CellBuffer() {
}
char CellBuffer::CharAt(Sci::Position position) const {
char CellBuffer::CharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
}
unsigned char CellBuffer::UCharAt(Sci::Position position) const {
return static_cast<unsigned char>(substance.ValueAt(position));
unsigned char CellBuffer::UCharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
}
void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const {
@ -398,7 +398,7 @@ void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Positio
substance.GetRange(buffer, position, lengthRetrieve);
}
char CellBuffer::StyleAt(Sci::Position position) const {
char CellBuffer::StyleAt(Sci::Position position) const noexcept {
return hasStyles ? style.ValueAt(position) : 0;
}
@ -496,7 +496,7 @@ const char *CellBuffer::DeleteChars(Sci::Position position, Sci::Position delete
return data;
}
Sci::Position CellBuffer::Length() const {
Sci::Position CellBuffer::Length() const noexcept {
return substance.Length();
}
@ -537,11 +537,11 @@ void CellBuffer::SetPerLine(PerLine *pl) {
plv->SetPerLine(pl);
}
Sci::Line CellBuffer::Lines() const {
Sci::Line CellBuffer::Lines() const noexcept {
return plv->Lines();
}
Sci::Position CellBuffer::LineStart(Sci::Line line) const {
Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept {
if (line < 0)
return 0;
else if (line >= Lines())
@ -550,7 +550,7 @@ Sci::Position CellBuffer::LineStart(Sci::Line line) const {
return plv->LineStart(line);
}
Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const {
Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const noexcept {
return plv->LineFromPosition(pos);
}

View File

@ -132,28 +132,30 @@ public:
CellBuffer(bool hasStyles_, bool largeDocument_);
// Deleted so CellBuffer objects can not be copied.
CellBuffer(const CellBuffer &) = delete;
CellBuffer(CellBuffer &&) = delete;
void operator=(const CellBuffer &) = delete;
void operator=(CellBuffer &&) = delete;
~CellBuffer();
/// Retrieving positions outside the range of the buffer works and returns 0
char CharAt(Sci::Position position) const;
unsigned char UCharAt(Sci::Position position) const;
char CharAt(Sci::Position position) const noexcept;
unsigned char UCharAt(Sci::Position position) const noexcept;
void GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
char StyleAt(Sci::Position position) const;
char StyleAt(Sci::Position position) const noexcept;
void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
const char *BufferPointer();
const char *RangePointer(Sci::Position position, Sci::Position rangeLength);
Sci::Position GapPosition() const;
Sci::Position Length() const;
Sci::Position Length() const noexcept;
void Allocate(Sci::Position newSize);
int GetLineEndTypes() const { return utf8LineEnds; }
void SetLineEndTypes(int utf8LineEnds_);
bool ContainsLineEnd(const char *s, Sci::Position length) const;
void SetPerLine(PerLine *pl);
Sci::Line Lines() const;
Sci::Position LineStart(Sci::Line line) const;
Sci::Line LineFromPosition(Sci::Position pos) const;
Sci::Line Lines() const noexcept;
Sci::Position LineStart(Sci::Line line) const noexcept;
Sci::Line LineFromPosition(Sci::Position pos) const noexcept;
void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
void RemoveLine(Sci::Line line);
const char *InsertString(Sci::Position position, const char *s, Sci::Position insertLength, bool &startSequence);

View File

@ -14,7 +14,7 @@
using namespace Scintilla;
CharClassify::CharClassify() {
CharClassify::CharClassify() : charClass{} {
SetDefaultCharClasses(true);
}

View File

@ -11,9 +11,9 @@ using namespace Scintilla;
namespace Scintilla {
bool DBCSIsLeadByte(int codePage, char ch) {
bool DBCSIsLeadByte(int codePage, char ch) noexcept {
// Byte ranges found in Wikipedia articles with relevant search strings in each case
const unsigned char uch = static_cast<unsigned char>(ch);
const unsigned char uch = ch;
switch (codePage) {
case 932:
// Shift_jis

View File

@ -10,7 +10,7 @@
namespace Scintilla {
bool DBCSIsLeadByte(int codePage, char ch);
bool DBCSIsLeadByte(int codePage, char ch) noexcept;
}

View File

@ -387,7 +387,7 @@ Sci_Position SCI_METHOD Document::LineFromPosition(Sci_Position pos) const {
return cb.LineFromPosition(pos);
}
Sci::Line Document::SciLineFromPosition(Sci::Position pos) const {
Sci::Line Document::SciLineFromPosition(Sci::Position pos) const noexcept {
// Avoids casting in callers for this very common function
return cb.LineFromPosition(pos);
}
@ -582,13 +582,13 @@ int Document::LenChar(Sci::Position pos) {
else
return widthCharBytes;
} else if (dbcsCodePage) {
return IsDBCSLeadByte(cb.CharAt(pos)) ? 2 : 1;
return IsDBCSLeadByteNoExcept(cb.CharAt(pos)) ? 2 : 1;
} else {
return 1;
}
}
bool Document::InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const {
bool Document::InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const noexcept {
Sci::Position trail = pos;
while ((trail>0) && (pos-trail < UTF8MaxBytes) && UTF8IsTrailByte(cb.UCharAt(trail-1)))
trail--;
@ -604,10 +604,10 @@ bool Document::InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position
if (len > trailBytes)
// pos too far from lead
return false;
char charBytes[UTF8MaxBytes] = {static_cast<char>(leadByte),0,0,0};
unsigned char charBytes[UTF8MaxBytes] = {leadByte,0,0,0};
for (Sci::Position b=1; b<widthCharBytes && ((start+b) < Length()); b++)
charBytes[b] = cb.CharAt(start+b);
const int utf8status = UTF8Classify(reinterpret_cast<const unsigned char *>(charBytes), widthCharBytes);
const int utf8status = UTF8Classify(charBytes, widthCharBytes);
if (utf8status & UTF8MaskInvalid)
return false;
end = start + widthCharBytes;
@ -661,12 +661,12 @@ Sci::Position Document::MovePositionOutsideChar(Sci::Position pos, Sci::Position
// Step back until a non-lead-byte is found.
Sci::Position posCheck = pos;
while ((posCheck > posStartLine) && IsDBCSLeadByte(cb.CharAt(posCheck-1)))
while ((posCheck > posStartLine) && IsDBCSLeadByteNoExcept(cb.CharAt(posCheck-1)))
posCheck--;
// Check from known start of character.
while (posCheck < pos) {
const int mbsize = IsDBCSLeadByte(cb.CharAt(posCheck)) ? 2 : 1;
const int mbsize = IsDBCSLeadByteNoExcept(cb.CharAt(posCheck)) ? 2 : 1;
if (posCheck + mbsize == pos) {
return pos;
} else if (posCheck + mbsize > pos) {
@ -687,13 +687,13 @@ Sci::Position Document::MovePositionOutsideChar(Sci::Position pos, Sci::Position
// NextPosition moves between valid positions - it can not handle a position in the middle of a
// multi-byte character. It is used to iterate through text more efficiently than MovePositionOutsideChar.
// A \r\n pair is treated as two characters.
Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const {
Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexcept {
// If out of range, just return minimum/maximum value.
const int increment = (moveDir > 0) ? 1 : -1;
if (pos + increment <= 0)
return 0;
if (pos + increment >= Length())
return Length();
if (pos + increment >= cb.Length())
return cb.Length();
if (dbcsCodePage) {
if (SC_CP_UTF8 == dbcsCodePage) {
@ -705,10 +705,10 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const {
pos++;
} else {
const int widthCharBytes = UTF8BytesOfLead[leadByte];
char charBytes[UTF8MaxBytes] = {static_cast<char>(leadByte),0,0,0};
unsigned char charBytes[UTF8MaxBytes] = {leadByte,0,0,0};
for (int b=1; b<widthCharBytes; b++)
charBytes[b] = cb.CharAt(pos+b);
const int utf8status = UTF8Classify(reinterpret_cast<const unsigned char *>(charBytes), widthCharBytes);
const int utf8status = UTF8Classify(charBytes, widthCharBytes);
if (utf8status & UTF8MaskInvalid)
pos++;
else
@ -731,25 +731,25 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const {
}
} else {
if (moveDir > 0) {
const int mbsize = IsDBCSLeadByte(cb.CharAt(pos)) ? 2 : 1;
const int mbsize = IsDBCSLeadByteNoExcept(cb.CharAt(pos)) ? 2 : 1;
pos += mbsize;
if (pos > Length())
pos = Length();
if (pos > cb.Length())
pos = cb.Length();
} else {
// Anchor DBCS calculations at start of line because start of line can
// not be a DBCS trail byte.
const Sci::Position posStartLine = LineStart(LineFromPosition(pos));
const Sci::Position posStartLine = cb.LineStart(cb.LineFromPosition(pos));
// See http://msdn.microsoft.com/en-us/library/cc194792%28v=MSDN.10%29.aspx
// http://msdn.microsoft.com/en-us/library/cc194790.aspx
if ((pos - 1) <= posStartLine) {
return pos - 1;
} else if (IsDBCSLeadByte(cb.CharAt(pos - 1))) {
} else if (IsDBCSLeadByteNoExcept(cb.CharAt(pos - 1))) {
// Must actually be trail byte
return pos - 2;
} else {
// Otherwise, step back until a non-lead-byte is found.
Sci::Position posTemp = pos - 1;
while (posStartLine <= --posTemp && IsDBCSLeadByte(cb.CharAt(posTemp)))
while (posStartLine <= --posTemp && IsDBCSLeadByteNoExcept(cb.CharAt(posTemp)))
;
// Now posTemp+1 must point to the beginning of a character,
// so figure out whether we went back an even or an odd
@ -765,7 +765,7 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const {
return pos;
}
bool Document::NextCharacter(Sci::Position &pos, int moveDir) const {
bool Document::NextCharacter(Sci::Position &pos, int moveDir) const noexcept {
// Returns true if pos changed
Sci::Position posNext = NextPosition(pos, moveDir);
if (posNext == pos) {
@ -798,7 +798,7 @@ Document::CharacterExtracted Document::CharacterAfter(Sci::Position position) co
return CharacterExtracted(UnicodeFromUTF8(charBytes), utf8status & UTF8MaskWidth);
}
} else {
if (IsDBCSLeadByte(leadByte) && ((position + 1) < Length())) {
if (IsDBCSLeadByteNoExcept(leadByte) && ((position + 1) < Length())) {
return CharacterExtracted::DBCS(leadByte, cb.UCharAt(position + 1));
} else {
return CharacterExtracted(leadByte, 1);
@ -912,7 +912,7 @@ int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Positio
}
}
} else {
if (IsDBCSLeadByte(leadByte)) {
if (IsDBCSLeadByteNoExcept(leadByte)) {
bytesInCharacter = 2;
character = (leadByte << 8) | cb.UCharAt(position+1);
} else {
@ -933,8 +933,14 @@ int SCI_METHOD Document::CodePage() const {
}
bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const {
// Used by lexers so must match IDocument method exactly
return IsDBCSLeadByteNoExcept(ch);
}
bool Document::IsDBCSLeadByteNoExcept(char ch) const noexcept {
// Used inside core Scintilla
// Byte ranges found in Wikipedia articles with relevant search strings in each case
const unsigned char uch = static_cast<unsigned char>(ch);
const unsigned char uch = ch;
switch (dbcsCodePage) {
case 932:
// Shift_jis
@ -960,7 +966,7 @@ bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const {
return false;
}
static inline bool IsSpaceOrTab(int ch) {
static inline bool IsSpaceOrTab(int ch) noexcept {
return ch == ' ' || ch == '\t';
}
@ -982,7 +988,7 @@ int Document::SafeSegment(const char *text, int length, int lengthSegment) const
int lastPunctuationBreak = -1;
int lastEncodingAllowedBreak = 0;
for (int j=0; j < lengthSegment;) {
const unsigned char ch = static_cast<unsigned char>(text[j]);
const unsigned char ch = text[j];
if (j > 0) {
if (IsSpaceOrTab(text[j - 1]) && !IsSpaceOrTab(text[j])) {
lastSpaceBreak = j;
@ -996,7 +1002,7 @@ int Document::SafeSegment(const char *text, int length, int lengthSegment) const
if (dbcsCodePage == SC_CP_UTF8) {
j += UTF8BytesOfLead[ch];
} else if (dbcsCodePage) {
j += IsDBCSLeadByte(ch) ? 2 : 1;
j += IsDBCSLeadByteNoExcept(ch) ? 2 : 1;
} else {
j++;
}
@ -1306,7 +1312,7 @@ void Document::DelCharBack(Sci::Position pos) {
}
}
static Sci::Position NextTab(Sci::Position pos, Sci::Position tabSize) {
static Sci::Position NextTab(Sci::Position pos, Sci::Position tabSize) noexcept {
return ((pos / tabSize) + 1) * tabSize;
}
@ -1818,7 +1824,7 @@ void Document::SetCaseFolder(CaseFolder *pcf_) {
pcf.reset(pcf_);
}
Document::CharacterExtracted Document::ExtractCharacter(Sci::Position position) const {
Document::CharacterExtracted Document::ExtractCharacter(Sci::Position position) const noexcept {
const unsigned char leadByte = cb.UCharAt(position);
if (UTF8IsAscii(leadByte)) {
// Common case: ASCII character
@ -1894,8 +1900,8 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
std::vector<char> searchThing((lengthFind+1) * UTF8MaxBytes * maxFoldingExpansion + 1);
const size_t lenSearch =
pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind);
char bytes[UTF8MaxBytes + 1];
char folded[UTF8MaxBytes * maxFoldingExpansion + 1];
char bytes[UTF8MaxBytes + 1] = "";
char folded[UTF8MaxBytes * maxFoldingExpansion + 1] = "";
while (forward ? (pos < endPos) : (pos >= endPos)) {
int widthFirstCharacter = 0;
Sci::Position posIndexDocument = pos;
@ -1955,7 +1961,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
(indexSearch < lenSearch)) {
char bytes[maxBytesCharacter + 1];
bytes[0] = cb.CharAt(pos + indexDocument);
const Sci::Position widthChar = IsDBCSLeadByte(bytes[0]) ? 2 : 1;
const Sci::Position widthChar = IsDBCSLeadByteNoExcept(bytes[0]) ? 2 : 1;
if (widthChar == 2)
bytes[1] = cb.CharAt(pos + indexDocument + 1);
if ((pos + indexDocument + widthChar) > limitPos)
@ -2295,7 +2301,7 @@ void Document::NotifyModified(DocModification mh) {
}
// Used for word part navigation.
static bool IsASCIIPunctuationCharacter(unsigned int ch) {
static bool IsASCIIPunctuationCharacter(unsigned int ch) noexcept {
switch (ch) {
case '!':
case '"':
@ -2429,7 +2435,7 @@ Sci::Position Document::WordPartRight(Sci::Position pos) const {
return pos;
}
static bool IsLineEndChar(char c) {
static bool IsLineEndChar(char c) noexcept {
return (c == '\n' || c == '\r');
}
@ -2446,7 +2452,7 @@ Sci::Position Document::ExtendStyleRange(Sci::Position pos, int delta, bool sing
return pos;
}
static char BraceOpposite(char ch) {
static char BraceOpposite(char ch) noexcept {
switch (ch) {
case '(':
return ')';
@ -2506,9 +2512,11 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe
class BuiltinRegex : public RegexSearchBase {
public:
explicit BuiltinRegex(CharClassify *charClassTable) : search(charClassTable) {}
~BuiltinRegex() override {
}
BuiltinRegex(const BuiltinRegex &) = delete;
BuiltinRegex(BuiltinRegex &&) = delete;
BuiltinRegex &operator=(const BuiltinRegex &) = delete;
BuiltinRegex &operator=(BuiltinRegex &&) = delete;
~BuiltinRegex() override = default;
Sci::Position FindText(Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s,
bool caseSensitive, bool word, bool wordStart, int flags,
@ -2569,14 +2577,18 @@ class DocumentIndexer : public CharacterIndexer {
Document *pdoc;
Sci::Position end;
public:
DocumentIndexer(Document *pdoc_, Sci::Position end_) :
DocumentIndexer(Document *pdoc_, Sci::Position end_) noexcept :
pdoc(pdoc_), end(end_) {
}
~DocumentIndexer() override {
}
DocumentIndexer(const DocumentIndexer &) = delete;
DocumentIndexer(DocumentIndexer &&) = delete;
DocumentIndexer &operator=(const DocumentIndexer &) = delete;
DocumentIndexer &operator=(DocumentIndexer &&) = delete;
char CharAt(Sci::Position index) const override {
~DocumentIndexer() override = default;
char CharAt(Sci::Position index) const noexcept override {
if (index < 0 || index >= end)
return 0;
else
@ -2596,45 +2608,53 @@ public:
const Document *doc;
Sci::Position position;
ByteIterator(const Document *doc_ = 0, Sci::Position position_ = 0) : doc(doc_), position(position_) {
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 &operator=(const ByteIterator &other) {
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;
}
char operator*() const {
ByteIterator &operator=(ByteIterator &&) noexcept = default;
~ByteIterator() = default;
char operator*() const noexcept {
return doc->CharAt(position);
}
ByteIterator &operator++() {
ByteIterator &operator++() noexcept {
position++;
return *this;
}
ByteIterator operator++(int) {
ByteIterator operator++(int) noexcept {
ByteIterator retVal(*this);
position++;
return retVal;
}
ByteIterator &operator--() {
ByteIterator &operator--() noexcept {
position--;
return *this;
}
bool operator==(const ByteIterator &other) const {
bool operator==(const ByteIterator &other) const noexcept {
return doc == other.doc && position == other.position;
}
bool operator!=(const ByteIterator &other) const {
bool operator!=(const ByteIterator &other) const noexcept {
return doc != other.doc || position != other.position;
}
Sci::Position Pos() const {
Sci::Position Pos() const noexcept {
return position;
}
Sci::Position PosRoundUp() const {
Sci::Position PosRoundUp() const noexcept {
return position;
}
};
@ -2671,15 +2691,15 @@ public:
typedef wchar_t* pointer;
typedef wchar_t& reference;
UTF8Iterator(const Document *doc_ = 0, Sci::Position position_ = 0) :
doc(doc_), position(position_), characterIndex(0), lenBytes(0), lenCharacters(0) {
UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
doc(doc_), position(position_), characterIndex(0), lenBytes(0), lenCharacters(0), buffered{} {
buffered[0] = 0;
buffered[1] = 0;
if (doc) {
ReadCharacter();
}
}
UTF8Iterator(const UTF8Iterator &other) {
UTF8Iterator(const UTF8Iterator &other) noexcept : buffered{} {
doc = other.doc;
position = other.position;
characterIndex = other.characterIndex;
@ -2688,7 +2708,8 @@ public:
buffered[0] = other.buffered[0];
buffered[1] = other.buffered[1];
}
UTF8Iterator &operator=(const UTF8Iterator &other) {
UTF8Iterator(UTF8Iterator &&other) noexcept = default;
UTF8Iterator &operator=(const UTF8Iterator &other) noexcept {
if (this != &other) {
doc = other.doc;
position = other.position;
@ -2700,11 +2721,13 @@ public:
}
return *this;
}
wchar_t operator*() const {
UTF8Iterator &operator=(UTF8Iterator &&) noexcept = default;
~UTF8Iterator() = default;
wchar_t operator*() const noexcept {
assert(lenCharacters != 0);
return buffered[characterIndex];
}
UTF8Iterator &operator++() {
UTF8Iterator &operator++() noexcept {
if ((characterIndex + 1) < (lenCharacters)) {
characterIndex++;
} else {
@ -2714,7 +2737,7 @@ public:
}
return *this;
}
UTF8Iterator operator++(int) {
UTF8Iterator operator++(int) noexcept {
UTF8Iterator retVal(*this);
if ((characterIndex + 1) < (lenCharacters)) {
characterIndex++;
@ -2725,7 +2748,7 @@ public:
}
return retVal;
}
UTF8Iterator &operator--() {
UTF8Iterator &operator--() noexcept {
if (characterIndex) {
characterIndex--;
} else {
@ -2735,29 +2758,29 @@ public:
}
return *this;
}
bool operator==(const UTF8Iterator &other) const {
bool operator==(const UTF8Iterator &other) const noexcept {
// Only test the determining fields, not the character widths and values derived from this
return doc == other.doc &&
position == other.position &&
characterIndex == other.characterIndex;
}
bool operator!=(const UTF8Iterator &other) const {
bool operator!=(const UTF8Iterator &other) const noexcept {
// Only test the determining fields, not the character widths and values derived from this
return doc != other.doc ||
position != other.position ||
characterIndex != other.characterIndex;
}
Sci::Position Pos() const {
Sci::Position Pos() const noexcept {
return position;
}
Sci::Position PosRoundUp() const {
Sci::Position PosRoundUp() const noexcept {
if (characterIndex)
return position + lenBytes; // Force to end of character
else
return position;
}
private:
void ReadCharacter() {
void ReadCharacter() noexcept {
const Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position);
lenBytes = charExtracted.widthBytes;
if (charExtracted.character == unicodeReplacementChar) {
@ -2783,46 +2806,50 @@ public:
typedef wchar_t* pointer;
typedef wchar_t& reference;
UTF8Iterator(const Document *doc_=0, Sci::Position position_=0) : doc(doc_), position(position_) {
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 &operator=(const UTF8Iterator &other) {
UTF8Iterator(UTF8Iterator &&other) noexcept = default;
UTF8Iterator &operator=(const UTF8Iterator &other) noexcept {
if (this != &other) {
doc = other.doc;
position = other.position;
}
return *this;
}
wchar_t operator*() const {
Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position);
UTF8Iterator &operator=(UTF8Iterator &&) noexcept = default;
~UTF8Iterator() = default;
wchar_t operator*() const noexcept {
const Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position);
return charExtracted.character;
}
UTF8Iterator &operator++() {
UTF8Iterator &operator++() noexcept {
position = doc->NextPosition(position, 1);
return *this;
}
UTF8Iterator operator++(int) {
UTF8Iterator operator++(int) noexcept {
UTF8Iterator retVal(*this);
position = doc->NextPosition(position, 1);
return retVal;
}
UTF8Iterator &operator--() {
UTF8Iterator &operator--() noexcept {
position = doc->NextPosition(position, -1);
return *this;
}
bool operator==(const UTF8Iterator &other) const {
bool operator==(const UTF8Iterator &other) const noexcept {
return doc == other.doc && position == other.position;
}
bool operator!=(const UTF8Iterator &other) const {
bool operator!=(const UTF8Iterator &other) const noexcept {
return doc != other.doc || position != other.position;
}
Sci::Position Pos() const {
Sci::Position Pos() const noexcept {
return position;
}
Sci::Position PosRoundUp() const {
Sci::Position PosRoundUp() const noexcept {
return position;
}
};
@ -2893,7 +2920,7 @@ bool MatchOnLines(const Document *doc, const Regex &regexp, const RESearchRange
return matched;
}
Sci::Position Cxx11RegexFindText(Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s,
Sci::Position Cxx11RegexFindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s,
bool caseSensitive, Sci::Position *length, RESearch &search) {
const RESearchRange resr(doc, minPos, maxPos);
try {

View File

@ -242,11 +242,11 @@ public:
struct CharacterExtracted {
unsigned int character;
unsigned int widthBytes;
CharacterExtracted(unsigned int character_, unsigned int widthBytes_) :
CharacterExtracted(unsigned int character_, unsigned int widthBytes_) noexcept :
character(character_), widthBytes(widthBytes_) {
}
// For DBCS characters turn 2 bytes into an int
static CharacterExtracted DBCS(unsigned char lead, unsigned char trail) {
static CharacterExtracted DBCS(unsigned char lead, unsigned char trail) noexcept {
return CharacterExtracted((lead << 8) | trail, 2);
}
};
@ -268,7 +268,9 @@ public:
Document(int options);
// Deleted so Document objects can not be copied.
Document(const Document &) = delete;
Document(Document &&) = delete;
void operator=(const Document &) = delete;
Document &operator=(Document &&) = delete;
~Document() override;
int AddRef();
@ -292,15 +294,15 @@ public:
void SCI_METHOD SetErrorStatus(int status) override;
Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const override;
Sci::Line SciLineFromPosition(Sci::Position pos) const; // Avoids casting LineFromPosition
Sci::Line SciLineFromPosition(Sci::Position pos) const noexcept; // Avoids casting LineFromPosition
Sci::Position ClampPositionIntoDocument(Sci::Position pos) const;
bool ContainsLineEnd(const char *s, Sci::Position length) const { return cb.ContainsLineEnd(s, length); }
bool IsCrLf(Sci::Position pos) const;
int LenChar(Sci::Position pos);
bool InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const;
bool InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const noexcept;
Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir, bool checkLineEnd=true) const;
Sci::Position NextPosition(Sci::Position pos, int moveDir) const;
bool NextCharacter(Sci::Position &pos, int moveDir) const; // Returns true if pos changed
Sci::Position NextPosition(Sci::Position pos, int moveDir) const noexcept;
bool NextCharacter(Sci::Position &pos, int moveDir) const noexcept; // Returns true if pos changed
Document::CharacterExtracted CharacterAfter(Sci::Position position) const;
Document::CharacterExtracted CharacterBefore(Sci::Position position) const;
Sci_Position SCI_METHOD GetRelativePosition(Sci_Position positionStart, Sci_Position characterOffset) const override;
@ -308,6 +310,7 @@ public:
int SCI_METHOD GetCharacterAndWidth(Sci_Position position, Sci_Position *pWidth) const override;
int SCI_METHOD CodePage() const override;
bool SCI_METHOD IsDBCSLeadByte(char ch) const override;
bool IsDBCSLeadByteNoExcept(char ch) const noexcept;
int SafeSegment(const char *text, int length, int lengthSegment) const;
EncodingFamily CodePageFamily() const;
@ -361,7 +364,7 @@ public:
void DelChar(Sci::Position pos);
void DelCharBack(Sci::Position pos);
char CharAt(Sci::Position position) const { return cb.CharAt(position); }
char CharAt(Sci::Position position) const noexcept { return cb.CharAt(position); }
void SCI_METHOD GetCharRange(char *buffer, Sci_Position position, Sci_Position lengthRetrieve) const override {
cb.GetCharRange(buffer, position, lengthRetrieve);
}
@ -399,7 +402,7 @@ public:
Sci_Position SCI_METHOD Length() const override { return cb.Length(); }
void Allocate(Sci::Position newSize) { cb.Allocate(newSize); }
CharacterExtracted ExtractCharacter(Sci::Position position) const;
CharacterExtracted ExtractCharacter(Sci::Position position) const noexcept;
bool IsWordStartAt(Sci::Position pos) const;
bool IsWordEndAt(Sci::Position pos) const;

View File

@ -51,7 +51,7 @@ using namespace Scintilla;
Caret::Caret() :
active(false), on(false), period(500) {}
EditModel::EditModel() {
EditModel::EditModel() : braces{} {
inOverstrike = false;
xOffset = 0;
trackLineWidth = false;

View File

@ -25,10 +25,12 @@ public:
}
// Deleted so SplitVectorWithRangeAdd objects can not be copied.
SplitVectorWithRangeAdd(const SplitVectorWithRangeAdd &) = delete;
SplitVectorWithRangeAdd(SplitVectorWithRangeAdd &&) = delete;
void operator=(const SplitVectorWithRangeAdd &) = delete;
void operator=(SplitVectorWithRangeAdd &&) = delete;
~SplitVectorWithRangeAdd() {
}
void RangeAddDelta(ptrdiff_t start, ptrdiff_t end, T delta) {
void RangeAddDelta(ptrdiff_t start, ptrdiff_t end, T delta) noexcept {
// end is 1 past end, so end-start is number of elements to change
ptrdiff_t i = 0;
const ptrdiff_t rangeLength = end - start;
@ -65,7 +67,7 @@ private:
std::unique_ptr<SplitVectorWithRangeAdd<T>> body;
// Move step forward
void ApplyStep(T partitionUpTo) {
void ApplyStep(T partitionUpTo) noexcept {
if (stepLength != 0) {
body->RangeAddDelta(stepPartition+1, partitionUpTo + 1, stepLength);
}
@ -77,7 +79,7 @@ private:
}
// Move step backward
void BackStep(T partitionDownTo) {
void BackStep(T partitionDownTo) noexcept {
if (stepLength != 0) {
body->RangeAddDelta(partitionDownTo+1, stepPartition+1, -stepLength);
}
@ -93,18 +95,20 @@ private:
}
public:
explicit Partitioning(int growSize) {
explicit Partitioning(int growSize) : stepPartition(0), stepLength(0) {
Allocate(growSize);
}
// Deleted so Partitioning objects can not be copied.
Partitioning(const Partitioning &) = delete;
Partitioning(Partitioning &&) = delete;
void operator=(const Partitioning &) = delete;
void operator=(Partitioning &&) = delete;
~Partitioning() {
}
T Partitions() const {
T Partitions() const noexcept {
return static_cast<T>(body->Length())-1;
}
@ -116,7 +120,7 @@ public:
stepPartition++;
}
void SetPartitionStartPosition(T partition, T pos) {
void SetPartitionStartPosition(T partition, T pos) noexcept {
ApplyStep(partition+1);
if ((partition < 0) || (partition > body->Length())) {
return;
@ -156,7 +160,7 @@ public:
body->Delete(partition);
}
T PositionFromPartition(T partition) const {
T PositionFromPartition(T partition) const noexcept {
PLATFORM_ASSERT(partition >= 0);
PLATFORM_ASSERT(partition < body->Length());
const ptrdiff_t lengthBody = body->Length();
@ -170,7 +174,7 @@ public:
}
/// Return value in range [0 .. Partitions() - 1] even for arguments outside interval
T PartitionFromPosition(T pos) const {
T PartitionFromPosition(T pos) const noexcept {
if (body->Length() <= 1)
return 0;
if (pos >= (PositionFromPartition(Partitions())))

View File

@ -33,11 +33,11 @@ MarkerHandleSet::~MarkerHandleSet() {
mhList.clear();
}
bool MarkerHandleSet::Empty() const {
bool MarkerHandleSet::Empty() const noexcept {
return mhList.empty();
}
int MarkerHandleSet::MarkValue() const {
int MarkerHandleSet::MarkValue() const noexcept {
unsigned int m = 0;
for (const MarkerHandleNumber &mhn : mhList) {
m |= (1 << mhn.number);
@ -45,7 +45,7 @@ int MarkerHandleSet::MarkValue() const {
return m;
}
bool MarkerHandleSet::Contains(int handle) const {
bool MarkerHandleSet::Contains(int handle) const noexcept {
for (const MarkerHandleNumber &mhn : mhList) {
if (mhn.handle == handle) {
return true;
@ -125,7 +125,7 @@ void LineMarkers::MergeMarkers(Sci::Line line) {
}
}
int LineMarkers::MarkValue(Sci::Line line) {
int LineMarkers::MarkValue(Sci::Line line) noexcept {
if (markers.Length() && (line >= 0) && (line < markers.Length()) && markers[line])
return markers[line]->MarkValue();
else

View File

@ -32,9 +32,9 @@ public:
MarkerHandleSet(const MarkerHandleSet &) = delete;
void operator=(const MarkerHandleSet &) = delete;
~MarkerHandleSet();
bool Empty() const;
int MarkValue() const; ///< Bit set of marker numbers.
bool Contains(int handle) const;
bool Empty() const noexcept;
int MarkValue() const noexcept; ///< Bit set of marker numbers.
bool Contains(int handle) const noexcept;
bool InsertHandle(int handle, int markerNum);
void RemoveHandle(int handle);
bool RemoveNumber(int markerNum, bool all);
@ -50,13 +50,15 @@ public:
}
// Deleted so Worker objects can not be copied.
LineMarkers(const LineMarkers &) = delete;
LineMarkers(LineMarkers &&) = delete;
void operator=(const LineMarkers &) = delete;
void operator=(LineMarkers &&) = delete;
~LineMarkers() override;
void Init() override;
void InsertLine(Sci::Line line) override;
void RemoveLine(Sci::Line line) override;
int MarkValue(Sci::Line line);
int MarkValue(Sci::Line line) noexcept;
Sci::Line MarkerNext(Sci::Line lineStart, int mask) const;
int AddMark(Sci::Line line, int markerNum, Sci::Line lines);
void MergeMarkers(Sci::Line line);

View File

@ -497,7 +497,7 @@ TextSegment BreakFinder::Next() {
charWidth = UTF8DrawBytes(reinterpret_cast<unsigned char *>(&ll->chars[nextBreak]),
static_cast<int>(lineRange.end - nextBreak));
else if (encodingFamily == efDBCS)
charWidth = pdoc->IsDBCSLeadByte(ll->chars[nextBreak]) ? 2 : 1;
charWidth = pdoc->IsDBCSLeadByteNoExcept(ll->chars[nextBreak]) ? 2 : 1;
const Representation *repr = preprs->RepresentationFromCharacter(&ll->chars[nextBreak], charWidth);
if (((nextBreak > 0) && (ll->styles[nextBreak] != ll->styles[nextBreak - 1])) ||
repr ||

View File

@ -23,11 +23,11 @@ public:
double x;
double y;
explicit PointDocument(double x_ = 0, double y_ = 0) : x(x_), y(y_) {
explicit PointDocument(double x_ = 0, double y_ = 0) noexcept : x(x_), y(y_) {
}
// Conversion from Point.
explicit PointDocument(Point pt) : x(pt.x), y(pt.y) {
explicit PointDocument(Point pt) noexcept : x(pt.x), y(pt.y) {
}
};
@ -172,10 +172,10 @@ struct TextSegment {
int start;
int length;
const Representation *representation;
TextSegment(int start_=0, int length_=0, const Representation *representation_=0) :
TextSegment(int start_=0, int length_=0, const Representation *representation_=nullptr) noexcept :
start(start_), length(length_), representation(representation_) {
}
int end() const {
int end() const noexcept {
return start + length;
}
};

View File

@ -29,7 +29,7 @@ using namespace Scintilla;
// Find the first run at a position
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::RunFromPosition(DISTANCE position) const {
DISTANCE RunStyles<DISTANCE, STYLE>::RunFromPosition(DISTANCE position) const noexcept {
DISTANCE run = starts->PartitionFromPosition(position);
// Go to first element with this position
while ((run > 0) && (position == starts->PositionFromPartition(run-1))) {
@ -88,17 +88,17 @@ RunStyles<DISTANCE, STYLE>::~RunStyles() {
}
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::Length() const {
DISTANCE RunStyles<DISTANCE, STYLE>::Length() const noexcept {
return starts->PositionFromPartition(starts->Partitions());
}
template <typename DISTANCE, typename STYLE>
STYLE RunStyles<DISTANCE, STYLE>::ValueAt(DISTANCE position) const {
STYLE RunStyles<DISTANCE, STYLE>::ValueAt(DISTANCE position) const noexcept {
return styles->ValueAt(starts->PartitionFromPosition(position));
}
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::FindNextChange(DISTANCE position, DISTANCE end) const {
DISTANCE RunStyles<DISTANCE, STYLE>::FindNextChange(DISTANCE position, DISTANCE end) const noexcept {
const DISTANCE run = starts->PartitionFromPosition(position);
if (run < starts->Partitions()) {
const DISTANCE runChange = starts->PositionFromPartition(run);
@ -118,12 +118,12 @@ DISTANCE RunStyles<DISTANCE, STYLE>::FindNextChange(DISTANCE position, DISTANCE
}
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::StartRun(DISTANCE position) const {
DISTANCE RunStyles<DISTANCE, STYLE>::StartRun(DISTANCE position) const noexcept {
return starts->PositionFromPartition(starts->PartitionFromPosition(position));
}
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::EndRun(DISTANCE position) const {
DISTANCE RunStyles<DISTANCE, STYLE>::EndRun(DISTANCE position) const noexcept {
return starts->PositionFromPartition(starts->PartitionFromPosition(position) + 1);
}
@ -243,12 +243,12 @@ void RunStyles<DISTANCE, STYLE>::DeleteRange(DISTANCE position, DISTANCE deleteL
}
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::Runs() const {
DISTANCE RunStyles<DISTANCE, STYLE>::Runs() const noexcept {
return starts->Partitions();
}
template <typename DISTANCE, typename STYLE>
bool RunStyles<DISTANCE, STYLE>::AllSame() const {
bool RunStyles<DISTANCE, STYLE>::AllSame() const noexcept {
for (int run = 1; run < starts->Partitions(); run++) {
if (styles->ValueAt(run) != styles->ValueAt(run - 1))
return false;
@ -257,12 +257,12 @@ bool RunStyles<DISTANCE, STYLE>::AllSame() const {
}
template <typename DISTANCE, typename STYLE>
bool RunStyles<DISTANCE, STYLE>::AllSameAs(STYLE value) const {
bool RunStyles<DISTANCE, STYLE>::AllSameAs(STYLE value) const noexcept {
return AllSame() && (styles->ValueAt(0) == value);
}
template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::Find(STYLE value, DISTANCE start) const {
DISTANCE RunStyles<DISTANCE, STYLE>::Find(STYLE value, DISTANCE start) const noexcept {
if (start < Length()) {
DISTANCE run = start ? RunFromPosition(start) : 0;
if (styles->ValueAt(run) == value)

View File

@ -27,7 +27,7 @@ class RunStyles {
private:
std::unique_ptr<Partitioning<DISTANCE>> starts;
std::unique_ptr<SplitVector<STYLE>> styles;
DISTANCE RunFromPosition(DISTANCE position) const;
DISTANCE RunFromPosition(DISTANCE position) const noexcept;
DISTANCE SplitRun(DISTANCE position);
void RemoveRun(DISTANCE run);
void RemoveRunIfEmpty(DISTANCE run);
@ -36,23 +36,25 @@ public:
RunStyles();
// Deleted so RunStyles objects can not be copied.
RunStyles(const RunStyles &) = delete;
RunStyles(RunStyles &&) = delete;
void operator=(const RunStyles &) = delete;
void operator=(RunStyles &&) = delete;
~RunStyles();
DISTANCE Length() const;
STYLE ValueAt(DISTANCE position) const;
DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const;
DISTANCE StartRun(DISTANCE position) const;
DISTANCE EndRun(DISTANCE position) const;
DISTANCE Length() const noexcept;
STYLE ValueAt(DISTANCE position) const noexcept;
DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const noexcept;
DISTANCE StartRun(DISTANCE position) const noexcept;
DISTANCE EndRun(DISTANCE position) const noexcept;
// Returns changed=true if some values may have changed
FillResult<DISTANCE> FillRange(DISTANCE position, STYLE value, DISTANCE fillLength);
void SetValueAt(DISTANCE position, STYLE value);
void InsertSpace(DISTANCE position, DISTANCE insertLength);
void DeleteAll();
void DeleteRange(DISTANCE position, DISTANCE deleteLength);
DISTANCE Runs() const;
bool AllSame() const;
bool AllSameAs(STYLE value) const;
DISTANCE Find(STYLE value, DISTANCE start) const;
DISTANCE Runs() const noexcept;
bool AllSame() const noexcept;
bool AllSameAs(STYLE value) const noexcept;
DISTANCE Find(STYLE value, DISTANCE start) const noexcept;
void Check() const;
};

View File

@ -24,7 +24,7 @@ protected:
/// Move the gap to a particular position so that insertion and
/// deletion at that point will not require much copying and
/// hence be fast.
void GapTo(ptrdiff_t position) {
void GapTo(ptrdiff_t position) noexcept {
if (position != part1Length) {
if (position < part1Length) {
// Moving the gap towards start so moving elements towards end
@ -56,21 +56,22 @@ protected:
void Init() {
body.clear();
body.shrink_to_fit();
growSize = 8;
lengthBody = 0;
part1Length = 0;
gapLength = 0;
growSize = 8;
}
public:
/// Construct a split buffer.
SplitVector() : empty() {
Init();
SplitVector() : empty(), lengthBody(0), part1Length(0), gapLength(0), growSize(8) {
}
// Deleted so SplitVector objects can not be copied.
SplitVector(const SplitVector &) = delete;
SplitVector(SplitVector &&) = delete;
void operator=(const SplitVector &) = delete;
void operator=(SplitVector &&) = delete;
~SplitVector() {
}
@ -104,7 +105,7 @@ public:
/// Retrieve the element at a particular position.
/// Retrieving positions outside the range of the buffer returns empty or 0.
const T& ValueAt(ptrdiff_t position) const {
const T& ValueAt(ptrdiff_t position) const noexcept {
if (position < part1Length) {
if (position < 0) {
return empty;
@ -124,7 +125,7 @@ public:
/// Setting positions outside the range of the buffer performs no assignment
/// but asserts in debug builds.
template <typename ParamType>
void SetValueAt(ptrdiff_t position, ParamType&& v) {
void SetValueAt(ptrdiff_t position, ParamType&& v) noexcept {
if (position < part1Length) {
PLATFORM_ASSERT(position >= 0);
if (position < 0) {
@ -144,7 +145,7 @@ public:
/// Retrieve the element at a particular position.
/// The position must be within bounds or an assertion is triggered.
const T &operator[](ptrdiff_t position) const {
const T &operator[](ptrdiff_t position) const noexcept {
PLATFORM_ASSERT(position >= 0 && position < lengthBody);
if (position < part1Length) {
return body[position];
@ -156,7 +157,7 @@ public:
/// Retrieve reference to the element at a particular position.
/// This, instead of the const variant, can be used to mutate in-place.
/// The position must be within bounds or an assertion is triggered.
T &operator[](ptrdiff_t position) {
T &operator[](ptrdiff_t position) noexcept {
PLATFORM_ASSERT(position >= 0 && position < lengthBody);
if (position < part1Length) {
return body[position];
@ -166,7 +167,7 @@ public:
}
/// Retrieve the length of the buffer.
ptrdiff_t Length() const {
ptrdiff_t Length() const noexcept {
return lengthBody;
}
@ -250,14 +251,12 @@ public:
/// Delete one element from the buffer.
void Delete(ptrdiff_t position) {
PLATFORM_ASSERT((position >= 0) && (position < lengthBody));
if ((position < 0) || (position >= lengthBody)) {
return;
}
DeleteRange(position, 1);
}
/// Delete a range from the buffer.
/// Deleting positions outside the current range fails.
/// Cannot be noexcept as vector::shrink_to_fit may be called and it may throw.
void DeleteRange(ptrdiff_t position, ptrdiff_t deleteLength) {
PLATFORM_ASSERT((position >= 0) && (position + deleteLength <= lengthBody));
if ((position < 0) || ((position + deleteLength) > lengthBody)) {
@ -265,8 +264,6 @@ public:
}
if ((position == 0) && (deleteLength == lengthBody)) {
// Full deallocation returns storage and is faster
body.clear();
body.shrink_to_fit();
Init();
} else if (deleteLength > 0) {
GapTo(position);
@ -281,7 +278,7 @@ public:
}
/// Retrieve a range of elements into an array
void GetRange(T *buffer, ptrdiff_t position, ptrdiff_t retrieveLength) const {
void GetRange(T *buffer, ptrdiff_t position, ptrdiff_t retrieveLength) const noexcept {
// Split into up to 2 ranges, before and after the split then use memcpy on each.
ptrdiff_t range1Length = 0;
if (position < part1Length) {
@ -298,6 +295,8 @@ public:
}
/// Compact the buffer and return a pointer to the first element.
/// Also ensures there is an empty element beyond logical end in case its
/// passed to a function expecting a NUL terminated string.
T *BufferPointer() {
RoomFor(1);
GapTo(lengthBody);
@ -308,7 +307,7 @@ public:
/// Return a pointer to a range of elements, first rearranging the buffer if
/// needed to make that range contiguous.
T *RangePointer(ptrdiff_t position, ptrdiff_t rangeLength) {
T *RangePointer(ptrdiff_t position, ptrdiff_t rangeLength) noexcept {
if (position < part1Length) {
if ((position + rangeLength) > part1Length) {
// Range overlaps gap, so move gap to start of range.
@ -323,7 +322,7 @@ public:
}
/// Return the position of the gap within the buffer.
ptrdiff_t GapPosition() const {
ptrdiff_t GapPosition() const noexcept {
return part1Length;
}
};

View File

@ -87,9 +87,8 @@ void UTF8FromUTF32Character(int uch, char *putf) {
size_t UTF16Length(const char *s, size_t len) {
size_t ulen = 0;
const unsigned char *us = reinterpret_cast<const unsigned char *>(s);
for (size_t i = 0; i < len;) {
const unsigned char ch = us[i];
const unsigned char ch = s[i];
const unsigned int byteCount = UTF8BytesOfLead[ch];
const unsigned int utf16Len = UTF16LengthFromUTF8ByteCount(byteCount);
i += byteCount;
@ -218,7 +217,7 @@ size_t UTF32FromUTF8(const char *s, size_t len, unsigned int *tbuf, size_t tlen)
return ui;
}
unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) {
unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept {
if (val < SUPPLEMENTAL_PLANE_FIRST) {
tbuf[0] = static_cast<wchar_t>(val);
return 1;
@ -254,7 +253,7 @@ const unsigned char UTF8BytesOfLead[256] = {
// the non-characters *FFFE, *FFFF and FDD0 .. FDEF return 3 or 4 as they can be
// reasonably treated as code points in some circumstances. They will, however,
// not have associated glyphs.
int UTF8Classify(const unsigned char *us, int len) {
int UTF8Classify(const unsigned char *us, int len) noexcept {
// For the rules: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
if (us[0] < 0x80) {
// ASCII
@ -325,7 +324,7 @@ int UTF8Classify(const unsigned char *us, int len) {
return UTF8MaskInvalid | 1;
}
int UTF8DrawBytes(const unsigned char *us, int len) {
int UTF8DrawBytes(const unsigned char *us, int len) noexcept {
const int utf8StatusNext = UTF8Classify(us, len);
return (utf8StatusNext & UTF8MaskInvalid) ? 1 : (utf8StatusNext & UTF8MaskWidth);
}

View File

@ -20,12 +20,12 @@ void UTF8FromUTF32Character(int uch, char *putf);
size_t UTF16Length(const char *s, size_t len);
size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen);
size_t UTF32FromUTF8(const char *s, size_t len, unsigned int *tbuf, size_t tlen);
unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf);
unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept;
std::string FixInvalidUTF8(const std::string &text);
extern const unsigned char UTF8BytesOfLead[256];
inline int UnicodeFromUTF8(const unsigned char *us) {
inline int UnicodeFromUTF8(const unsigned char *us) noexcept {
switch (UTF8BytesOfLead[us[0]]) {
case 1:
return us[0];
@ -38,31 +38,31 @@ inline int UnicodeFromUTF8(const unsigned char *us) {
}
}
inline bool UTF8IsTrailByte(unsigned char ch) {
inline bool UTF8IsTrailByte(unsigned char ch) noexcept {
return (ch >= 0x80) && (ch < 0xc0);
}
inline bool UTF8IsAscii(int ch) {
inline bool UTF8IsAscii(int ch) noexcept {
return ch < 0x80;
}
enum { UTF8MaskWidth=0x7, UTF8MaskInvalid=0x8 };
int UTF8Classify(const unsigned char *us, int len);
int UTF8Classify(const unsigned char *us, int len) noexcept;
// Similar to UTF8Classify but returns a length of 1 for invalid bytes
// instead of setting the invalid flag
int UTF8DrawBytes(const unsigned char *us, int len);
int UTF8DrawBytes(const unsigned char *us, int len) noexcept;
// Line separator is U+2028 \xe2\x80\xa8
// Paragraph separator is U+2029 \xe2\x80\xa9
const int UTF8SeparatorLength = 3;
inline bool UTF8IsSeparator(const unsigned char *us) {
inline bool UTF8IsSeparator(const unsigned char *us) noexcept {
return (us[0] == 0xe2) && (us[1] == 0x80) && ((us[2] == 0xa8) || (us[2] == 0xa9));
}
// NEL is U+0085 \xc2\x85
const int UTF8NELLength = 2;
inline bool UTF8IsNEL(const unsigned char *us) {
inline bool UTF8IsNEL(const unsigned char *us) noexcept {
return (us[0] == 0xc2) && (us[1] == 0x85);
}
@ -72,11 +72,11 @@ enum { SURROGATE_TRAIL_FIRST = 0xDC00 };
enum { SURROGATE_TRAIL_LAST = 0xDFFF };
enum { SUPPLEMENTAL_PLANE_FIRST = 0x10000 };
inline unsigned int UTF16CharLength(wchar_t uch) {
inline unsigned int UTF16CharLength(wchar_t uch) noexcept {
return ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST)) ? 2 : 1;
}
inline unsigned int UTF16LengthFromUTF8ByteCount(unsigned int byteCount) {
inline unsigned int UTF16LengthFromUTF8ByteCount(unsigned int byteCount) noexcept {
return (byteCount < 4) ? 1 : 2;
}

View File

@ -120,7 +120,7 @@ void XPM::Init(const char *const *linesForm) {
const char *lform = linesForm[y+nColours+1];
const size_t len = MeasureLength(lform);
for (size_t x = 0; x<len; x++)
pixels[y * width + x] = static_cast<unsigned char>(lform[x]);
pixels[y * width + x] = lform[x];
}
}

View File

@ -2811,7 +2811,7 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) {
GlobalMemory ansiText;
ansiText.Allocate(selectedText.LengthWithTerminator());
if (ansiText) {
memcpy(static_cast<char *>(ansiText.ptr), selectedText.Data(), selectedText.LengthWithTerminator());
memcpy(ansiText.ptr, selectedText.Data(), selectedText.LengthWithTerminator());
ansiText.SetClip(CF_TEXT);
}
}
@ -3168,7 +3168,7 @@ STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) {
} else {
text.Allocate(drag.LengthWithTerminator());
if (text) {
memcpy(static_cast<char *>(text.ptr), drag.Data(), drag.LengthWithTerminator());
memcpy(text.ptr, drag.Data(), drag.LengthWithTerminator());
}
}
pSTM->hGlobal = text ? text.Unlock() : 0;
@ -3257,9 +3257,9 @@ BOOL ScintillaWin::CreateSystemCaret() {
sysCaretHeight = vs.lineHeight;
int bitmapSize = (((sysCaretWidth + 15) & ~15) >> 3) *
sysCaretHeight;
std::vector<char> bits(bitmapSize);
std::vector<BYTE> bits(bitmapSize);
sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,
1, reinterpret_cast<BYTE *>(&bits[0]));
1, &bits[0]);
BOOL retval = ::CreateCaret(
MainHWND(), sysCaretBitmap,
sysCaretWidth, sysCaretHeight);

View File

@ -8048,33 +8048,8 @@ void EditToggleFolds(FOLD_ACTION action, bool bForceAll)
bool fToggled = false;
if (bAllLines) {
if (action == SNIFF) {
// determine majority to find action for all
int cntFolded = 0;
int cntExpanded = 0;
for (DocLn ln = iStartLine; ln <= iEndLine; ++ln)
{
if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
{
if (SciCall_GetLastChild(ln, -1) != ln)
{
if (SciCall_GetFoldExpanded(ln))
++cntExpanded;
else
++cntFolded;
}
}
}
if (cntFolded == cntExpanded) {
action = (sbLastSniffAllAction == FOLD) ? EXPAND : FOLD;
}
else {
action = (cntFolded < cntExpanded) ? FOLD : EXPAND;
}
sbLastSniffAllAction = action;
}
if (bAllLines)
{
SciCall_FoldAll(action);
fToggled = true;
}
@ -8167,7 +8142,13 @@ void EditFoldAltArrow(FOLD_MOVE move, FOLD_ACTION action)
}
// Perform a fold/unfold operation
if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
DocLn const iBegLn = SciCall_LineFromPosition(SciCall_GetSelectionStart());
DocLn const iEndLn = SciCall_LineFromPosition(SciCall_GetSelectionEnd());
// selection range must span at least two lines for action
if (iBegLn != iEndLn) {
EditToggleFolds(action, false);
}
else if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
{
if (action != SNIFF) {
_FoldToggleNode(ln, action);