From 2aa59d615ef7539b138b754ffee3df0a7056e005 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 21 Mar 2019 12:02:01 +0100 Subject: [PATCH 1/3] + chg: code cleanup --- src/Styles.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Styles.c b/src/Styles.c index 3119bfdb3..67ddb383e 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -128,8 +128,8 @@ typedef struct _themeFiles static THEMEFILES Theme_Files[] = { - { 0, L"", L"" }, // Standard - { 0, L"", L"" }, + { 0, L"Default", L"" }, + { 0, L"Standard", L"" }, { 0, L"", L"" }, { 0, L"", L"" }, { 0, L"", L"" }, @@ -162,16 +162,9 @@ const WCHAR* const STYLING_THEME_NAME = L"ThemeFileName"; static void _FillThemesMenuTable() { - WCHAR wchStdName[80]; - Theme_Files[0].rid = IDM_THEMES_DEFAULT; // factory default - GetLngString(IDM_THEMES_DEFAULT, wchStdName, COUNTOF(wchStdName)); - StringCchCopy(Theme_Files[0].szName, COUNTOF(Theme_Files[0].szName), wchStdName); - StringCchCopy(Theme_Files[0].szFilePath, COUNTOF(Theme_Files[0].szFilePath), L""); - Theme_Files[1].rid = IDM_THEMES_FILE_ITEM; // NP3.ini settings - GetLngString(IDM_THEMES_FILE_ITEM, wchStdName, COUNTOF(wchStdName)); - StringCchCopy(Theme_Files[1].szName, COUNTOF(Theme_Files[1].szName), wchStdName); + // names are filled by Style_InsertThemesMenu() StringCchCopy(Theme_Files[1].szFilePath, COUNTOF(Theme_Files[1].szFilePath), Globals.IniFile); unsigned iTheme = 1; // Standard @@ -249,13 +242,10 @@ bool Style_InsertThemesMenu(HMENU hMenuBar) HMENU hmenuThemes = CreatePopupMenu(); int const pos = GetMenuItemCount(hMenuBar) - 1; - GetLngString(IDM_THEMES_DEFAULT, Theme_Files[0].szName, COUNTOF(Theme_Files[0].szName)); - AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[0].rid, Theme_Files[0].szName); + GetLngString(Theme_Files[0].rid, Theme_Files[0].szName, COUNTOF(Theme_Files[0].szName)); + GetLngString(Theme_Files[1].rid, Theme_Files[1].szName, COUNTOF(Theme_Files[1].szName)); - GetLngString(IDM_THEMES_FILE_ITEM, Theme_Files[1].szName, COUNTOF(Theme_Files[1].szName)); - AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[1].rid, Theme_Files[1].szName); - - for (unsigned i = 2; i < ThemeItems_CountOf(); ++i) + for (unsigned i = 0; i < ThemeItems_CountOf(); ++i) { if (i == 2) { AppendMenu(hmenuThemes, MF_SEPARATOR, 0, 0); From 108503e2c3d3999b330e57c23a72f4892b5c5cb5 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 26 Mar 2019 09:14:27 +0100 Subject: [PATCH 2/3] + upd: merge current (2019-03-26) Scintilla GitHub mirror development stage --- scintilla/include/Platform.h | 2 + scintilla/include/Scintilla.h | 8 +++ scintilla/lexers/LexCPP.cxx | 79 ++++++++++++++----------- scintilla/lexlib/CharacterSet.cxx | 21 +------ scintilla/lexlib/CharacterSet.h | 98 ++++++++++++++++--------------- scintilla/src/CallTip.cxx | 6 +- scintilla/src/CellBuffer.h | 2 + scintilla/src/Document.cxx | 12 +--- scintilla/src/Document.h | 2 + scintilla/src/EditView.cxx | 18 +++--- scintilla/src/Editor.cxx | 2 +- scintilla/src/Editor.h | 2 +- scintilla/src/Indicator.cxx | 10 ++-- scintilla/src/Partitioning.h | 2 + scintilla/src/PositionCache.cxx | 2 +- scintilla/src/RESearch.h | 17 +++--- scintilla/src/ScintillaBase.cxx | 26 ++++++++ scintilla/src/ScintillaBase.h | 8 +++ scintilla/src/Selection.cxx | 4 +- scintilla/src/Selection.h | 4 +- scintilla/src/UniConversion.cxx | 83 +++++++++++++++++--------- scintilla/src/UniConversion.h | 16 +++-- scintilla/src/ViewStyle.cxx | 8 +-- scintilla/win32/PlatWin.cxx | 48 +++++++-------- scintilla/win32/ScintillaWin.cxx | 4 +- 25 files changed, 276 insertions(+), 208 deletions(-) diff --git a/scintilla/include/Platform.h b/scintilla/include/Platform.h index 2214f6073..acfac907d 100644 --- a/scintilla/include/Platform.h +++ b/scintilla/include/Platform.h @@ -76,9 +76,11 @@ #endif +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #include #include #include +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< namespace Scintilla { diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index 9c805c1e3..1d119370d 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -19,7 +19,9 @@ extern "C" { /* Return false on failure: */ int Scintilla_RegisterClasses(void *hInstance); int Scintilla_ReleaseResources(void); +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> int Scintilla_InputCodePage(void); +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< #endif int Scintilla_LinkLexers(void); @@ -103,8 +105,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_IME_INLINE 1 #define SCI_GETIMEINTERACTION 2678 #define SCI_SETIMEINTERACTION 2679 +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #define SCI_ISIMEOPEN 2719 #define SCI_ISIMEMODECJK 2720 +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< #define MARKER_MAX 31 #define SC_MARK_CIRCLE 0 #define SC_MARK_ROUNDRECT 1 @@ -401,7 +405,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETPRINTCOLOURMODE 2149 #define SCFIND_WHOLEWORD 0x2 #define SCFIND_MATCHCASE 0x4 +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #define SCFIND_DOT_MATCH_ALL 0x1000 +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< #define SCFIND_WORDSTART 0x00100000 #define SCFIND_REGEXP 0x00200000 #define SCFIND_POSIX 0x00400000 @@ -691,8 +697,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_POPUP_TEXT 2 #define SCI_USEPOPUP 2371 #define SCI_SELECTIONISRECTANGLE 2372 +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #define SC_MIN_ZOOM_LEVEL 10 #define SC_MAX_ZOOM_LEVEL 500 +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< #define SCI_SETZOOM 2373 #define SCI_GETZOOM 2374 #define SC_DOCUMENTOPTION_DEFAULT 0 diff --git a/scintilla/lexers/LexCPP.cxx b/scintilla/lexers/LexCPP.cxx index 78ee46724..49921fd8e 100644 --- a/scintilla/lexers/LexCPP.cxx +++ b/scintilla/lexers/LexCPP.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include "ILexer.h" #include "Scintilla.h" @@ -39,7 +40,7 @@ using namespace Scintilla; namespace { // Use an unnamed namespace to protect the functions and classes from name conflicts -bool IsSpaceEquiv(int state) noexcept { +constexpr bool IsSpaceEquiv(int state) noexcept { return (state <= SCE_C_COMMENTDOC) || // including SCE_C_DEFAULT, SCE_C_COMMENT, SCE_C_COMMENTLINE (state == SCE_C_COMMENTLINEDOC) || (state == SCE_C_COMMENTDOCKEYWORD) || @@ -86,7 +87,7 @@ bool followsReturnKeyword(const StyleContext &sc, LexAccessor &styler) { return !*s; } -bool IsSpaceOrTab(int ch) noexcept { +constexpr bool IsSpaceOrTab(int ch) noexcept { return ch == ' ' || ch == '\t'; } @@ -145,7 +146,7 @@ void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, if ((isoperator(sc.chPrev) || IsASpace(sc.chPrev)) && markerList.Length()) { const int lengthMarker = 50; char marker[lengthMarker+1] = ""; - const Sci_Position currPos = static_cast(sc.currentPos); + const Sci_Position currPos = sc.currentPos; int i = 0; while (i < lengthMarker) { const char ch = styler.SafeGetCharAt(currPos + i); @@ -173,7 +174,7 @@ struct EscapeSequence { CharacterSet *escapeSetValid; EscapeSequence() { digitsLeft = 0; - escapeSetValid = 0; + escapeSetValid = nullptr; setHexDigits = CharacterSet(CharacterSet::setDigits, "ABCDEFabcdef"); setOctDigits = CharacterSet(CharacterSet::setNone, "01234567"); } @@ -226,7 +227,7 @@ std::string GetRestOfLine(LexAccessor &styler, Sci_Position start, bool allowSpa return restOfLine; } -bool IsStreamCommentStyle(int style) noexcept { +constexpr bool IsStreamCommentStyle(int style) noexcept { return style == SCE_C_COMMENT || style == SCE_C_COMMENTDOC || style == SCE_C_COMMENTDOCKEYWORD || @@ -259,7 +260,7 @@ class LinePPState { } } public: - LinePPState() : state(0), ifTaken(0), level(-1) { + LinePPState() noexcept : state(0), ifTaken(0), level(-1) { } bool IsInactive() const noexcept { return state != 0; @@ -369,7 +370,7 @@ const char *const cppWordLists[] = { "Global classes and typedefs", "Preprocessor definitions", "Task marker and error marker keywords", - 0, + nullptr, }; struct OptionSetCPP : public OptionSet { @@ -478,6 +479,8 @@ LexicalClass lexicalClasses[] = { 27, "SCE_C_ESCAPESEQUENCE", "literal string escapesequence", "Escape sequence", }; +const int sizeLexicalClasses = static_cast(std::size(lexicalClasses)); + } class LexerCPP : public ILexer4 { @@ -500,7 +503,8 @@ class LexerCPP : public ILexer4 { struct SymbolValue { std::string value; std::string arguments; - SymbolValue(const std::string &value_="", const std::string &arguments_="") : value(value_), arguments(arguments_) { + SymbolValue() noexcept = default; + SymbolValue(const std::string &value_, const std::string &arguments_) : value(value_), arguments(arguments_) { } SymbolValue &operator = (const std::string &value_) { value = value_; @@ -532,12 +536,17 @@ public: setLogicalOp(CharacterSet::setNone, "|&"), subStyles(styleSubable, 0x80, 0x40, activeFlag) { } + // Deleted so LexerCPP objects can not be copied. + LexerCPP(const LexerCPP &) = delete; + LexerCPP(LexerCPP &&) = delete; + void operator=(const LexerCPP &) = delete; + void operator=(LexerCPP &&) = delete; virtual ~LexerCPP() { } - void SCI_METHOD Release() override { + void SCI_METHOD Release() noexcept override { delete this; } - int SCI_METHOD Version() const override { + int SCI_METHOD Version() const noexcept override { return lvRelease4; } const char * SCI_METHOD PropertyNames() override { @@ -557,11 +566,11 @@ public: void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) override { - return 0; + void * SCI_METHOD PrivateCall(int, void *) noexcept override { + return nullptr; } - int SCI_METHOD LineEndTypesSupported() override { + int SCI_METHOD LineEndTypesSupported() noexcept override { return SC_LINE_END_TYPE_UNICODE; } @@ -579,7 +588,7 @@ public: const int active = subStyle & activeFlag; return styleBase | active; } - int SCI_METHOD PrimaryStyleFromStyle(int style) override { + int SCI_METHOD PrimaryStyleFromStyle(int style) noexcept override { return MaskActive(style); } void SCI_METHOD FreeSubStyles() override { @@ -588,21 +597,21 @@ public: void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override { subStyles.SetIdentifiers(style, identifiers); } - int SCI_METHOD DistanceToSecondaryStyles() override { + int SCI_METHOD DistanceToSecondaryStyles() noexcept override { return activeFlag; } - const char * SCI_METHOD GetSubStyleBases() override { + const char * SCI_METHOD GetSubStyleBases() noexcept override { return styleSubable; } int SCI_METHOD NamedStyles() override { return std::max(subStyles.LastAllocated() + 1, - static_cast(ELEMENTS(lexicalClasses))) + + sizeLexicalClasses) + activeFlag; } const char * SCI_METHOD NameOfStyle(int style) override { if (style >= NamedStyles()) return ""; - if (style < static_cast(ELEMENTS(lexicalClasses))) + if (style < sizeLexicalClasses) return lexicalClasses[style].name; // TODO: inactive and substyles return ""; @@ -626,12 +635,12 @@ public: return returnBuffer.c_str(); } } - if (style < static_cast(ELEMENTS(lexicalClasses))) + if (style < sizeLexicalClasses) return lexicalClasses[style].tags; if (style >= activeFlag) { returnBuffer = "inactive "; const int styleActive = style - activeFlag; - if (styleActive < static_cast(ELEMENTS(lexicalClasses))) + if (styleActive < sizeLexicalClasses) returnBuffer += lexicalClasses[styleActive].tags; else returnBuffer = ""; @@ -642,7 +651,7 @@ public: const char * SCI_METHOD DescriptionOfStyle(int style) override { if (style >= NamedStyles()) return ""; - if (style < static_cast(ELEMENTS(lexicalClasses))) + if (style < sizeLexicalClasses) return lexicalClasses[style].description; // TODO: inactive and substyles return ""; @@ -654,7 +663,7 @@ public: static ILexer4 *LexerFactoryCPPInsensitive() { return new LexerCPP(false); } - static int MaskActive(int style) noexcept { + constexpr static int MaskActive(int style) noexcept { return style & ~activeFlag; } void EvaluateTokens(std::vector &tokens, const SymbolTable &preprocessorDefinitions); @@ -676,7 +685,7 @@ Sci_Position SCI_METHOD LexerCPP::PropertySet(const char *key, const char *val) } Sci_Position SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { - WordList *wordListN = 0; + WordList *wordListN = nullptr; switch (n) { case 0: wordListN = &keywords; @@ -818,7 +827,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i const WordClassifier &classifierIdentifiers = subStyles.Classifier(SCE_C_IDENTIFIER); const WordClassifier &classifierDocKeyWords = subStyles.Classifier(SCE_C_COMMENTDOCKEYWORD); - Sci_Position lineEndNext = styler.LineEnd(lineCurrent); + Sci_PositionU lineEndNext = styler.LineEnd(lineCurrent); for (; sc.More();) { @@ -856,7 +865,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i // Handle line continuation generically. if (sc.ch == '\\') { - if (static_cast((sc.currentPos+1)) >= lineEndNext) { + if ((sc.currentPos+1) >= lineEndNext) { lineCurrent++; lineEndNext = styler.LineEnd(lineCurrent); vlls.Add(lineCurrent, preproc); @@ -1128,7 +1137,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i while ((sc.ch < 0x80) && islower(sc.ch)) sc.Forward(); // gobble regex flags sc.SetState(SCE_C_DEFAULT|activitySet); - } else if (sc.ch == '\\' && (static_cast(sc.currentPos+1) < lineEndNext)) { + } else if (sc.ch == '\\' && ((sc.currentPos+1) < lineEndNext)) { // Gobble up the escaped character sc.Forward(); } else if (sc.ch == '[') { @@ -1316,7 +1325,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i while ((startName < restOfLine.length()) && IsSpaceOrTab(restOfLine[startName])) startName++; size_t endName = startName; - while ((endName < restOfLine.length()) && setWord.Contains(static_cast(restOfLine[endName]))) + while ((endName < restOfLine.length()) && setWord.Contains(restOfLine[endName])) endName++; std::string key = restOfLine.substr(startName, endName-startName); if ((endName < restOfLine.length()) && (restOfLine.at(endName) == '(')) { @@ -1542,7 +1551,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl size_t iterations = 0; // Limit number of iterations in case there is a recursive macro. for (size_t i = 0; (i(tokens[i][0]))) { + if (setWordStart.Contains(tokens[i][0])) { SymbolTable::const_iterator it = preprocessorDefinitions.find(tokens[i]); if (it != preprocessorDefinitions.end()) { // Tokenize value @@ -1569,7 +1578,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl macroTokens.erase(std::remove_if(macroTokens.begin(), macroTokens.end(), OnlySpaceOrTab), macroTokens.end()); for (size_t iMacro = 0; iMacro < macroTokens.size();) { - if (setWordStart.Contains(static_cast(macroTokens[iMacro][0]))) { + if (setWordStart.Contains(macroTokens[iMacro][0])) { std::map::const_iterator itFind = arguments.find(macroTokens[iMacro]); if (itFind != arguments.end()) { // TODO: Possible that value will be expression so should insert tokenized form @@ -1687,9 +1696,9 @@ std::vector LexerCPP::Tokenize(const std::string &expr) const { const char *cp = expr.c_str(); while (*cp) { std::string word; - if (setWord.Contains(static_cast(*cp))) { + if (setWord.Contains(*cp)) { // Identifiers and numbers - while (setWord.Contains(static_cast(*cp))) { + while (setWord.Contains(*cp)) { word += *cp; cp++; } @@ -1698,17 +1707,17 @@ std::vector LexerCPP::Tokenize(const std::string &expr) const { word += *cp; cp++; } - } else if (setRelOp.Contains(static_cast(*cp))) { + } else if (setRelOp.Contains(*cp)) { word += *cp; cp++; - if (setRelOp.Contains(static_cast(*cp))) { + if (setRelOp.Contains(*cp)) { word += *cp; cp++; } - } else if (setLogicalOp.Contains(static_cast(*cp))) { + } else if (setLogicalOp.Contains(*cp)) { word += *cp; cp++; - if (setLogicalOp.Contains(static_cast(*cp))) { + if (setLogicalOp.Contains(*cp)) { word += *cp; cp++; } diff --git a/scintilla/lexlib/CharacterSet.cxx b/scintilla/lexlib/CharacterSet.cxx index 12e7a553a..2a1dabc1c 100644 --- a/scintilla/lexlib/CharacterSet.cxx +++ b/scintilla/lexlib/CharacterSet.cxx @@ -8,7 +8,6 @@ #include #include -#include #include "CharacterSet.h" @@ -16,21 +15,7 @@ using namespace Scintilla; namespace Scintilla { -CharacterSet::CharacterSet(setBase base, const char *initialSet, int size_, bool valueAfter_) { - size = size_; - valueAfter = valueAfter_; - bset = new bool[size](); - AddString(initialSet); - if (base & setLower) - AddString("abcdefghijklmnopqrstuvwxyz"); - if (base & setUpper) - AddString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - if (base & setDigits) - AddString("0123456789"); -} - -#if 0 -int CompareCaseInsensitive(const char *a, const char *b) noexcept { +int CompareCaseInsensitive(const char *a, const char *b) { while (*a && *b) { if (*a != *b) { const char upperA = MakeUpperCase(*a); @@ -45,7 +30,7 @@ int CompareCaseInsensitive(const char *a, const char *b) noexcept { return *a - *b; } -int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept { +int CompareNCaseInsensitive(const char *a, const char *b, size_t len) { while (*a && *b && len) { if (*a != *b) { const char upperA = MakeUpperCase(*a); @@ -63,5 +48,5 @@ int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept { // Either *a or *b is nul return *a - *b; } -#endif + } diff --git a/scintilla/lexlib/CharacterSet.h b/scintilla/lexlib/CharacterSet.h index 989c088f2..358f6bed3 100644 --- a/scintilla/lexlib/CharacterSet.h +++ b/scintilla/lexlib/CharacterSet.h @@ -23,9 +23,22 @@ public: setAlpha=setLower|setUpper, setAlphaNum=setAlpha|setDigits }; - CharacterSet(setBase base=setNone, const char *initialSet="", int size_=0x80, bool valueAfter_=false); - - CharacterSet(const CharacterSet &other) { + CharacterSet(setBase base=setNone, const char *initialSet="", int size_=0x80, bool valueAfter_=false) { + size = size_; + valueAfter = valueAfter_; + bset = new bool[size]; + for (int i=0; i < size; i++) { + bset[i] = false; + } + AddString(initialSet); + if (base & setLower) + AddString("abcdefghijklmnopqrstuvwxyz"); + if (base & setUpper) + AddString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + if (base & setDigits) + AddString("0123456789"); + } + CharacterSet(const CharacterSet &other) { size = other.size; valueAfter = other.valueAfter; bset = new bool[size]; @@ -67,42 +80,40 @@ public: assert(val < size); bset[val] = true; } - void CharacterSet::AddString(const char *setToAdd) noexcept { - for (const char *cp = setToAdd; *cp; cp++) { - int val = static_cast(*cp); - assert(val >= 0); - assert(val < size); - bset[val] = true; + void AddString(const char *setToAdd) { + for (const char *cp=setToAdd; *cp; cp++) { + const unsigned char uch = *cp; + assert(uch < size); + bset[uch] = true; } } - bool Contains(int val) const noexcept { + bool Contains(int val) const { assert(val >= 0); if (val < 0) return false; return (val < size) ? bset[val] : valueAfter; } + bool Contains(char ch) const { + // Overload char as char may be signed + const unsigned char uch = ch; + return Contains(uch); + } }; // Functions for classifying characters -constexpr bool IsASpace(int ch) noexcept { +inline bool IsASpace(int ch) { return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); } -constexpr bool IsASpaceOrTab(int ch) noexcept { +inline bool IsASpaceOrTab(int ch) { return (ch == ' ') || (ch == '\t'); } -constexpr bool IsADigit(int ch) noexcept { +inline bool IsADigit(int ch) { return (ch >= '0') && (ch <= '9'); } -constexpr bool IsHexDigit(int ch) noexcept { - return (ch >= '0' && ch <= '9') - || (ch >= 'A' && ch <= 'F') - || (ch >= 'a' && ch <= 'f'); -} - -inline bool IsADigit(int ch, int base) noexcept { +inline bool IsADigit(int ch, int base) { if (base <= 10) { return (ch >= '0') && (ch < '0' + base); } else { @@ -112,24 +123,19 @@ inline bool IsADigit(int ch, int base) noexcept { } } -constexpr bool IsASCII(int ch) noexcept { +inline bool IsASCII(int ch) { return (ch >= 0) && (ch < 0x80); } -constexpr bool IsLowerCase(int ch) noexcept { +inline bool IsLowerCase(int ch) { return (ch >= 'a') && (ch <= 'z'); } -constexpr bool IsUpperCase(int ch) noexcept { +inline bool IsUpperCase(int ch) { return (ch >= 'A') && (ch <= 'Z'); } -constexpr bool IsAlpha(int ch) noexcept { - return ((ch >= 'a') && (ch <= 'z')) || - ((ch >= 'A') && (ch <= 'Z')); -} - -constexpr bool IsAlphaNumeric(int ch) noexcept { +inline bool IsAlphaNumeric(int ch) { return ((ch >= '0') && (ch <= '9')) || ((ch >= 'a') && (ch <= 'z')) || @@ -140,34 +146,35 @@ constexpr bool IsAlphaNumeric(int ch) noexcept { * Check if a character is a space. * This is ASCII specific but is safe with chars >= 0x80. */ -constexpr bool isspacechar(int ch) noexcept { +inline bool isspacechar(int ch) { return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); } -constexpr bool iswordchar(int ch) noexcept { +inline bool iswordchar(int ch) { return IsAlphaNumeric(ch) || ch == '.' || ch == '_'; } -constexpr bool iswordstart(int ch) noexcept { +inline bool iswordstart(int ch) { return IsAlphaNumeric(ch) || ch == '_'; } -inline bool isoperator(int ch) noexcept { +inline bool isoperator(int ch) { if (IsAlphaNumeric(ch)) return false; if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || - ch == '(' || ch == ')' || ch == '-' || ch == '+' || - ch == '=' || ch == '|' || ch == '{' || ch == '}' || - ch == '[' || ch == ']' || ch == ':' || ch == ';' || - ch == '<' || ch == '>' || ch == ',' || ch == '/' || - ch == '?' || ch == '!' || ch == '.' || ch == '~') + ch == '(' || ch == ')' || ch == '-' || ch == '+' || + ch == '=' || ch == '|' || ch == '{' || ch == '}' || + ch == '[' || ch == ']' || ch == ':' || ch == ';' || + ch == '<' || ch == '>' || ch == ',' || ch == '/' || + ch == '?' || ch == '!' || ch == '.' || ch == '~') return true; return false; } -// Simple case functions for ASCII. +// Simple case functions for ASCII supersets. + template -constexpr T MakeUpperCase(T ch) noexcept { +inline T MakeUpperCase(T ch) { if (ch < 'a' || ch > 'z') return ch; else @@ -175,20 +182,15 @@ constexpr T MakeUpperCase(T ch) noexcept { } template -constexpr T MakeLowerCase(T ch) noexcept { +inline T MakeLowerCase(T ch) { if (ch < 'A' || ch > 'Z') return ch; else return ch - 'A' + 'a'; } -#if 0 -int CompareCaseInsensitive(const char *a, const char *b) noexcept; -int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept; -#else -#define CompareCaseInsensitive _stricmp -#define CompareNCaseInsensitive _strnicmp -#endif +int CompareCaseInsensitive(const char *a, const char *b); +int CompareNCaseInsensitive(const char *a, const char *b, size_t len); } diff --git a/scintilla/src/CallTip.cxx b/scintilla/src/CallTip.cxx index 12df236d7..0cc818d44 100644 --- a/scintilla/src/CallTip.cxx +++ b/scintilla/src/CallTip.cxx @@ -155,7 +155,7 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, xEnd = NextTabPos(x); } else { std::string_view segText(s + startSeg, endSeg - startSeg); - xEnd = x + static_cast(lround(surface->WidthText(font, segText))); + xEnd = x + static_cast(std::lround(surface->WidthText(font, segText))); if (draw) { rcClient.left = static_cast(x); rcClient.right = static_cast(xEnd); @@ -176,7 +176,7 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { PRectangle rcClient(1.0f, 1.0f, rcClientSize.right - 1, rcClientSize.bottom - 1); // To make a nice small call tip window, it is only sized to fit most normal characters without accents - const int ascent = static_cast(lround(surfaceWindow->Ascent(font) - surfaceWindow->InternalLeading(font))); + const int ascent = static_cast(std::round(surfaceWindow->Ascent(font) - surfaceWindow->InternalLeading(font))); // For each line... // Draw the definition in three parts: before highlight, highlighted, after highlight @@ -280,7 +280,7 @@ PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, co rectDown = PRectangle(0,0,0,0); offsetMain = insetX; // changed to right edge of any arrows const int width = PaintContents(surfaceMeasure.get(), false) + insetX; - lineHeight = static_cast(lround(surfaceMeasure->Height(font))); + lineHeight = static_cast(std::lround(surfaceMeasure->Height(font))); // The returned // rectangle is aligned to the right edge of the last arrow encountered in diff --git a/scintilla/src/CellBuffer.h b/scintilla/src/CellBuffer.h index 81e7a7aeb..4ac083b00 100644 --- a/scintilla/src/CellBuffer.h +++ b/scintilla/src/CellBuffer.h @@ -8,7 +8,9 @@ #ifndef CELLBUFFER_H #define CELLBUFFER_H +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #include "Position.h" +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< namespace Scintilla { diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index f9cd654c7..4df512b1d 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -3058,17 +3058,9 @@ Sci::Position Cxx11RegexFindText(const Document *doc, Sci::Position minPos, Sci: bool matched = false; if (SC_CP_UTF8 == doc->dbcsCodePage) { - const std::string_view sv(s); - const size_t lenS = sv.length(); - std::vector ws(sv.length() + 1); -#if WCHAR_T_IS_16 - const size_t outLen = UTF16FromUTF8(sv, &ws[0], lenS); -#else - const size_t outLen = UTF32FromUTF8(sv, reinterpret_cast(&ws[0]), lenS); -#endif - ws[outLen] = 0; + const std::wstring ws = WStringFromUTF8(s); std::wregex regexp; - regexp.assign(&ws[0], flagsRe); + regexp.assign(ws, flagsRe); matched = MatchOnLines(doc, regexp, resr, search); } else { diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index 48c3987cf..96b1f8fd2 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -8,7 +8,9 @@ #ifndef DOCUMENT_H #define DOCUMENT_H +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #include "ILoader.h" +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< namespace Scintilla { diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index 399d7628a..9e8ca3474 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -702,7 +702,7 @@ Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, Sci:: SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs, const PRectangle rcClient) { pt.x = pt.x - vs.textStart; - Sci::Line visibleLine = static_cast(floor(pt.y / vs.lineHeight)); + Sci::Line visibleLine = static_cast(std::floor(pt.y / vs.lineHeight)); if (!canReturnInvalid && (visibleLine < 0)) visibleLine = 0; const Sci::Line lineDoc = model.pcs->DocFromDisplay(visibleLine); @@ -880,7 +880,7 @@ static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle r surface->FillRectangle(rcSegment, textBack); } FontAlias ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font; - const int normalCharHeight = static_cast(ceil(vsDraw.styles[STYLE_CONTROLCHAR].capitalHeight)); + const int normalCharHeight = static_cast(std::ceil(vsDraw.styles[STYLE_CONTROLCHAR].capitalHeight)); PRectangle rcCChar = rcSegment; rcCChar.left = rcCChar.left + 1; rcCChar.top = rcSegment.top + vsDraw.maxAscent - normalCharHeight; @@ -1263,8 +1263,8 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con if (model.foldDisplayTextStyle == SC_FOLDDISPLAYTEXT_BOXED) { surface->PenColour(textFore); PRectangle rcBox = rcSegment; - rcBox.left = round(rcSegment.left); - rcBox.right = round(rcSegment.right); + rcBox.left = std::round(rcSegment.left); + rcBox.right = std::round(rcSegment.right); const IntegerRectangle ircBox(rcBox); surface->MoveTo(ircBox.left, ircBox.top); surface->LineTo(ircBox.left, ircBox.bottom); @@ -1481,7 +1481,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt const ViewStyle::CaretShape caretShape = drawDrag ? ViewStyle::CaretShape::line : vsDraw.CaretShapeForMode(model.inOverstrike); if (drawDrag) { /* Dragging text, use a line caret */ - rcCaret.left = round(xposCaret - caretWidthOffset); + rcCaret.left = std::round(xposCaret - caretWidthOffset); rcCaret.right = rcCaret.left + vsDraw.caretWidth; } else if ((caretShape == ViewStyle::CaretShape::bar) && drawOverstrikeCaret) { /* Overstrike (insert mode), use a modified bar caret */ @@ -1499,7 +1499,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt } } else { /* Line caret */ - rcCaret.left = round(xposCaret - caretWidthOffset); + rcCaret.left = std::round(xposCaret - caretWidthOffset); rcCaret.right = rcCaret.left + vsDraw.caretWidth; } const ColourDesired caretColour = mainCaret ? vsDraw.caretcolour : vsDraw.additionalCaretColour; @@ -1843,7 +1843,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi indentCount <= (ll->positions[i + 1] - epsilon) / indentWidth; indentCount++) { if (indentCount > 0) { - const XYPOSITION xIndent = floor(indentCount * indentWidth); + const XYPOSITION xIndent = std::floor(indentCount * indentWidth); DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcSegment, (ll->xHighlightGuide == xIndent)); } @@ -1922,7 +1922,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi indentCount <= (ll->positions[cpos + ts.start + 1] - epsilon) / indentWidth; indentCount++) { if (indentCount > 0) { - const XYPOSITION xIndent = floor(indentCount * indentWidth); + const XYPOSITION xIndent = std::floor(indentCount * indentWidth); DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcSegment, (ll->xHighlightGuide == xIndent)); } @@ -1999,7 +1999,7 @@ void EditView::DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &mode } for (int indentPos = model.pdoc->IndentSize(); indentPos < indentSpace; indentPos += model.pdoc->IndentSize()) { - const XYPOSITION xIndent = floor(indentPos * vsDraw.spaceWidth); + const XYPOSITION xIndent = std::floor(indentPos * vsDraw.spaceWidth); if (xIndent < xStartText) { DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcLine, (ll->xHighlightGuide == xIndent)); diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 699d0c459..f3bf5babf 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -1409,7 +1409,7 @@ void Editor::SetXYScroll(XYScrollPosition newXY) { } } -void Editor::ScrollRange(const SelectionRange& range) { +void Editor::ScrollRange(SelectionRange range) { SetXYScroll(XYScrollToMakeVisible(range, xysDefault)); } diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index 88bc88a77..c5bddb1e0 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/src/Editor.h @@ -360,7 +360,7 @@ protected: // ScintillaBase subclass needs access to much of Editor XYScrollPosition XYScrollToMakeVisible(const SelectionRange &range, const XYScrollOptions options); void SetXYScroll(XYScrollPosition newXY); void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true); - void ScrollRange(const SelectionRange& range); + void ScrollRange(SelectionRange range); void ShowCaretAtCurrentPosition(); void DropCaret(); void CaretSetPeriod(int period); diff --git a/scintilla/src/Indicator.cxx b/scintilla/src/Indicator.cxx index 5ab0a7813..8db760f2b 100644 --- a/scintilla/src/Indicator.cxx +++ b/scintilla/src/Indicator.cxx @@ -25,8 +25,8 @@ using namespace Scintilla; static PRectangle PixelGridAlign(const PRectangle &rc) { // Move left and right side to nearest pixel to avoid blurry visuals - return PRectangle(round(rc.left), floor(rc.top), - round(rc.right), floor(rc.bottom)); + return PRectangle(std::round(rc.left), std::floor(rc.top), + std::round(rc.right), std::floor(rc.bottom)); } void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, const PRectangle &rcCharacter, DrawState drawState, int value) const { @@ -201,10 +201,10 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r surface->FillRectangle(rcComposition, sacDraw.fore); } else if (sacDraw.style == INDIC_POINT || sacDraw.style == INDIC_POINTCHARACTER) { if (rcCharacter.Width() >= 0.1) { - const XYPOSITION pixelHeight = floor(rc.Height() - 1.0f); // 1 pixel onto next line if multiphase + const XYPOSITION pixelHeight = std::floor(rc.Height() - 1.0f); // 1 pixel onto next line if multiphase const XYPOSITION x = (sacDraw.style == INDIC_POINT) ? (rcCharacter.left) : ((rcCharacter.right + rcCharacter.left) / 2); - const XYPOSITION ix = round(x); - const XYPOSITION iy = floor(rc.top + 1.0f); + const XYPOSITION ix = std::round(x); + const XYPOSITION iy = std::floor(rc.top + 1.0f); Point pts[] = { Point(ix - pixelHeight, iy + pixelHeight), // Left Point(ix + pixelHeight, iy + pixelHeight), // Right diff --git a/scintilla/src/Partitioning.h b/scintilla/src/Partitioning.h index 8f7276689..3c6ef6f3d 100644 --- a/scintilla/src/Partitioning.h +++ b/scintilla/src/Partitioning.h @@ -8,7 +8,9 @@ #ifndef PARTITIONING_H #define PARTITIONING_H +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> #include +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< namespace Scintilla { diff --git a/scintilla/src/PositionCache.cxx b/scintilla/src/PositionCache.cxx index aeb8d8bcf..65c90dd1d 100644 --- a/scintilla/src/PositionCache.cxx +++ b/scintilla/src/PositionCache.cxx @@ -348,7 +348,7 @@ XYPOSITION ScreenLine::RepresentationWidth(size_t position) const { } XYPOSITION ScreenLine::TabPositionAfter(XYPOSITION xPosition) const { - return (floor((xPosition + TabWidthMinimumPixels()) / TabWidth()) + 1) * TabWidth(); + return (std::floor((xPosition + TabWidthMinimumPixels()) / TabWidth()) + 1) * TabWidth(); } LineLayoutCache::LineLayoutCache() : diff --git a/scintilla/src/RESearch.h b/scintilla/src/RESearch.h index 285c9dc62..213055dac 100644 --- a/scintilla/src/RESearch.h +++ b/scintilla/src/RESearch.h @@ -11,14 +11,6 @@ namespace Scintilla { -/* - * The following defines are not meant to be changeable. - * They are for readability only. - */ -#define MAXCHR 256 -#define CHRBIT 8 -#define BITBLK MAXCHR/CHRBIT - class CharacterIndexer { public: virtual char CharAt(Sci::Position index) const=0; @@ -38,7 +30,6 @@ public: int Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Position endp); enum { MAXTAG=10 }; - enum { MAXNFA=4096 }; enum { NOTFOUND=-1 }; Sci::Position bopat[MAXTAG]; @@ -46,6 +37,14 @@ public: std::string pat[MAXTAG]; private: + + enum { MAXNFA = 4096 }; + // The following enums are not meant to be changeable. + // They are for readability only. + enum { MAXCHR = 256 }; + enum { CHRBIT = 8 }; + enum { BITBLK = MAXCHR / CHRBIT }; + void ChSet(unsigned char c); void ChSetWithCase(unsigned char c, bool caseSensitive); int GetBackslashExpression(const char *pattern, int &incr); diff --git a/scintilla/src/ScintillaBase.cxx b/scintilla/src/ScintillaBase.cxx index f8d7c058b..75ca5b853 100644 --- a/scintilla/src/ScintillaBase.cxx +++ b/scintilla/src/ScintillaBase.cxx @@ -499,6 +499,32 @@ void ScintillaBase::CallTipClick() { NotifyParent(scn); } +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> +#if 0 +bool ScintillaBase::ShouldDisplayPopup(Point ptInWindowCoordinates) const { + return (displayPopupMenu == SC_POPUP_ALL || + (displayPopupMenu == SC_POPUP_TEXT && !PointInSelMargin(ptInWindowCoordinates))); +} + +void ScintillaBase::ContextMenu(Point pt) { + if (displayPopupMenu) { + const bool writable = !WndProc(SCI_GETREADONLY, 0, 0); + popup.CreatePopUp(); + AddToPopUp("Undo", idcmdUndo, writable && pdoc->CanUndo()); + AddToPopUp("Redo", idcmdRedo, writable && pdoc->CanRedo()); + AddToPopUp(""); + AddToPopUp("Cut", idcmdCut, writable && !sel.Empty()); + AddToPopUp("Copy", idcmdCopy, !sel.Empty()); + AddToPopUp("Paste", idcmdPaste, writable && WndProc(SCI_CANPASTE, 0, 0)); + AddToPopUp("Delete", idcmdDelete, writable && !sel.Empty()); + AddToPopUp(""); + AddToPopUp("Select All", idcmdSelectAll); + popup.Show(pt, wMain); + } +} +#endif +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< + void ScintillaBase::CancelModes() { AutoCompleteCancel(); ct.CallTipCancel(); diff --git a/scintilla/src/ScintillaBase.h b/scintilla/src/ScintillaBase.h index 5ff050eb9..40d319ceb 100644 --- a/scintilla/src/ScintillaBase.h +++ b/scintilla/src/ScintillaBase.h @@ -83,6 +83,14 @@ protected: void CallTipShow(Point pt, const char *defn); virtual void CreateCallTipWindow(PRectangle rc) = 0; +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> +#if 0 + virtual void AddToPopUp(const char *label, int cmd=0, bool enabled=true) = 0; + bool ShouldDisplayPopup(Point ptInWindowCoordinates) const; + void ContextMenu(Point pt); +#endif +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< + void ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers) override; void RightButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers) override; diff --git a/scintilla/src/Selection.cxx b/scintilla/src/Selection.cxx index a342cb3fb..105b93315 100644 --- a/scintilla/src/Selection.cxx +++ b/scintilla/src/Selection.cxx @@ -131,7 +131,7 @@ void SelectionRange::Swap() { std::swap(caret, anchor); } -bool SelectionRange::Trim(const SelectionRange& range) { +bool SelectionRange::Trim(SelectionRange range) { const SelectionPosition startRange = range.Start(); const SelectionPosition endRange = range.End(); SelectionPosition start = Start(); @@ -362,7 +362,7 @@ void Selection::DropAdditionalRanges() { SetSelection(RangeMain()); } -void Selection::TentativeSelection(const SelectionRange& range) { +void Selection::TentativeSelection(SelectionRange range) { if (!tentativeMain) { rangesSaved = ranges; } diff --git a/scintilla/src/Selection.h b/scintilla/src/Selection.h index 3fc1af545..82fc4aa48 100644 --- a/scintilla/src/Selection.h +++ b/scintilla/src/Selection.h @@ -125,7 +125,7 @@ struct SelectionRange { return (anchor < caret) ? caret : anchor; } void Swap(); - bool Trim(const SelectionRange &range); + bool Trim(SelectionRange range); // If range is all virtual collapse to start of virtual space void MinimizeVirtualSpace(); }; @@ -173,7 +173,7 @@ public: void AddSelectionWithoutTrim(SelectionRange range); void DropSelection(size_t r); void DropAdditionalRanges(); - void TentativeSelection(const SelectionRange &range); + void TentativeSelection(SelectionRange range); void CommitTentative(); int CharacterInSelection(Sci::Position posCharacter) const; int InSelectionForEOL(Sci::Position pos) const; diff --git a/scintilla/src/UniConversion.cxx b/scintilla/src/UniConversion.cxx index 58475687b..44eceeda6 100644 --- a/scintilla/src/UniConversion.cxx +++ b/scintilla/src/UniConversion.cxx @@ -17,7 +17,7 @@ using namespace Scintilla; namespace Scintilla { -size_t UTF8Length(std::wstring_view wsv) { +size_t UTF8Length(std::wstring_view wsv) noexcept { size_t len = 0; for (size_t i = 0; i < wsv.length() && wsv[i];) { const unsigned int uch = wsv[i]; @@ -78,7 +78,7 @@ void UTF8FromUTF16(std::wstring_view wsv, char *putf, size_t len) { putf[k] = '\0'; } -void UTF8FromUTF32Character(int uch, char *putf) { +void UTF8FromUTF32Character(int uch, char *putf) noexcept { size_t k = 0; if (uch < 0x80) { putf[k++] = static_cast(uch); @@ -98,14 +98,14 @@ void UTF8FromUTF32Character(int uch, char *putf) { putf[k] = '\0'; } -size_t UTF16Length(std::string_view sv) { +size_t UTF16Length(std::string_view svu8) noexcept { size_t ulen = 0; - for (size_t i = 0; i sv.length()) ? 1 : utf16Len; + ulen += (i > svu8.length()) ? 1 : utf16Len; } return ulen; } @@ -116,14 +116,14 @@ constexpr unsigned char TrailByteValue(unsigned char c) { return c & 0b0011'1111; } -size_t UTF16FromUTF8(std::string_view sv, wchar_t *tbuf, size_t tlen) { +size_t UTF16FromUTF8(std::string_view svu8, wchar_t *tbuf, size_t tlen) { size_t ui = 0; - for (size_t i = 0; i < sv.length();) { - unsigned char ch = sv[i]; + for (size_t i = 0; i < svu8.length();) { + unsigned char ch = svu8[i]; const unsigned int byteCount = UTF8BytesOfLead[ch]; unsigned int value; - if (i + byteCount > sv.length()) { + if (i + byteCount > svu8.length()) { // Trying to read past end but still have space to write if (ui < tlen) { tbuf[ui] = ch; @@ -144,26 +144,26 @@ size_t UTF16FromUTF8(std::string_view sv, wchar_t *tbuf, size_t tlen) { break; case 2: value = (ch & 0x1F) << 6; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch); tbuf[ui] = static_cast(value); break; case 3: value = (ch & 0xF) << 12; - ch = sv[i++]; + ch = svu8[i++]; value += (TrailByteValue(ch) << 6); - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch); tbuf[ui] = static_cast(value); break; default: // Outside the BMP so need two surrogates value = (ch & 0x7) << 18; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch) << 12; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch) << 6; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch); tbuf[ui] = static_cast(((value - 0x10000) >> 10) + SURROGATE_LEAD_FIRST); ui++; @@ -175,14 +175,25 @@ size_t UTF16FromUTF8(std::string_view sv, wchar_t *tbuf, size_t tlen) { return ui; } -size_t UTF32FromUTF8(std::string_view sv, unsigned int *tbuf, size_t tlen) { +size_t UTF32Length(std::string_view svu8) noexcept { + size_t ulen = 0; + for (size_t i = 0; i < svu8.length();) { + const unsigned char ch = svu8[i]; + const unsigned int byteCount = UTF8BytesOfLead[ch]; + i += byteCount; + ulen++; + } + return ulen; +} + +size_t UTF32FromUTF8(std::string_view svu8, unsigned int *tbuf, size_t tlen) { size_t ui = 0; - for (size_t i = 0; i < sv.length();) { - unsigned char ch = sv[i]; + for (size_t i = 0; i < svu8.length();) { + unsigned char ch = svu8[i]; const unsigned int byteCount = UTF8BytesOfLead[ch]; unsigned int value; - if (i + byteCount > sv.length()) { + if (i + byteCount > svu8.length()) { // Trying to read past end but still have space to write if (ui < tlen) { tbuf[ui] = ch; @@ -202,23 +213,23 @@ size_t UTF32FromUTF8(std::string_view sv, unsigned int *tbuf, size_t tlen) { break; case 2: value = (ch & 0x1F) << 6; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch); break; case 3: value = (ch & 0xF) << 12; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch) << 6; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch); break; default: value = (ch & 0x7) << 18; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch) << 12; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch) << 6; - ch = sv[i++]; + ch = svu8[i++]; value += TrailByteValue(ch); break; } @@ -228,6 +239,20 @@ size_t UTF32FromUTF8(std::string_view sv, unsigned int *tbuf, size_t tlen) { return ui; } +std::wstring WStringFromUTF8(std::string_view svu8) { + if constexpr (sizeof(wchar_t) == 2) { + const size_t len16 = UTF16Length(svu8); + std::wstring ws(len16, 0); + UTF16FromUTF8(svu8, &ws[0], len16); + return ws; + } else { + const size_t len32 = UTF32Length(svu8); + std::wstring ws(len32, 0); + UTF32FromUTF8(svu8, reinterpret_cast(&ws[0]), len32); + return ws; + } +} + unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept { if (val < SUPPLEMENTAL_PLANE_FIRST) { tbuf[0] = static_cast(val); @@ -340,9 +365,9 @@ int UTF8DrawBytes(const unsigned char *us, int len) noexcept { return (utf8StatusNext & UTF8MaskInvalid) ? 1 : (utf8StatusNext & UTF8MaskWidth); } -bool UTF8IsValid(std::string_view sv) noexcept { - const unsigned char *us = reinterpret_cast(sv.data()); - size_t remaining = sv.length(); +bool UTF8IsValid(std::string_view svu8) noexcept { + const unsigned char *us = reinterpret_cast(svu8.data()); + size_t remaining = svu8.length(); while (remaining > 0) { const int utf8Status = UTF8Classify(us, remaining); if (utf8Status & UTF8MaskInvalid) { diff --git a/scintilla/src/UniConversion.h b/scintilla/src/UniConversion.h index c676230da..836e1e621 100644 --- a/scintilla/src/UniConversion.h +++ b/scintilla/src/UniConversion.h @@ -14,15 +14,19 @@ const int UTF8MaxBytes = 4; const int unicodeReplacementChar = 0xFFFD; -size_t UTF8Length(std::wstring_view wsv); +size_t UTF8Length(std::wstring_view wsv) noexcept; size_t UTF8PositionFromUTF16Position(std::string_view u8Text, size_t positionUTF16) noexcept; void UTF8FromUTF16(std::wstring_view wsv, char *putf, size_t len); -void UTF8FromUTF32Character(int uch, char *putf); -size_t UTF16Length(std::string_view sv); -size_t UTF16FromUTF8(std::string_view sv, wchar_t *tbuf, size_t tlen); -size_t UTF32FromUTF8(std::string_view sv, unsigned int *tbuf, size_t tlen); +void UTF8FromUTF32Character(int uch, char *putf) noexcept; +size_t UTF16Length(std::string_view svu8) noexcept; +size_t UTF16FromUTF8(std::string_view svu8, wchar_t *tbuf, size_t tlen); +size_t UTF32Length(std::string_view svu8) noexcept; +size_t UTF32FromUTF8(std::string_view svu8, unsigned int *tbuf, size_t tlen); +// WStringFromUTF8 does the right thing when wchar_t is 2 or 4 bytes so +// works on both Windows and Unix. +std::wstring WStringFromUTF8(std::string_view svu8); unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept; -bool UTF8IsValid(std::string_view sv) noexcept; +bool UTF8IsValid(std::string_view svu8) noexcept; std::string FixInvalidUTF8(const std::string &text); extern const unsigned char UTF8BytesOfLead[256]; diff --git a/scintilla/src/ViewStyle.cxx b/scintilla/src/ViewStyle.cxx index e650b1062..bc7f3a814 100644 --- a/scintilla/src/ViewStyle.cxx +++ b/scintilla/src/ViewStyle.cxx @@ -398,10 +398,10 @@ void ViewStyle::EnsureStyle(size_t index) { void ViewStyle::ResetDefaultStyle() { styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0), - ColourDesired(0xff,0xff,0xff), - Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, fontNames.Save(Platform::DefaultFont()), - SC_CHARSET_DEFAULT, - SC_WEIGHT_NORMAL, false, false, false, Style::caseMixed, true, true, false); + ColourDesired(0xff,0xff,0xff), + Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, fontNames.Save(Platform::DefaultFont()), + SC_CHARSET_DEFAULT, + SC_WEIGHT_NORMAL, false, false, false, Style::caseMixed, true, true, false); } void ViewStyle::ClearStyles() { diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 810cf8787..10f2513de 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -278,7 +278,7 @@ constexpr D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) noexc void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) { lf = LOGFONTW(); // The negative is to allow for leading - lf.lfHeight = -(abs(lround(size))); + lf.lfHeight = -(std::abs(std::lround(size))); lf.lfWeight = weight; lf.lfItalic = italic ? 1 : 0; lf.lfCharSet = static_cast(characterSet); @@ -296,12 +296,10 @@ FontID CreateFontFromParameters(const FontParameters &fp) { } else { #if defined(USE_D2D) IDWriteTextFormat *pTextFormat = nullptr; - const int faceSize = 200; - WCHAR wszFace[faceSize] = L""; - UTF16FromUTF8(fp.faceName, wszFace, faceSize); + const std::wstring wsFace = WStringFromUTF8(fp.faceName); const FLOAT fHeight = fp.size; const DWRITE_FONT_STYLE style = fp.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; - HRESULT hr = pIDWriteFactory->CreateTextFormat(wszFace, nullptr, + HRESULT hr = pIDWriteFactory->CreateTextFormat(wsFace.c_str(), nullptr, static_cast(fp.weight), style, DWRITE_FONT_STRETCH_NORMAL, fHeight, L"en-us", &pTextFormat); @@ -728,7 +726,9 @@ void SurfaceGDI::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fil const BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> GdiAlphaBlend(hdc, rcw.left, rcw.top, width, height, hMemDC, 0, 0, width, height, merge); + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< SelectBitmap(hMemDC, hbmOld); ::DeleteObject(hbmMem); @@ -751,10 +751,10 @@ void SurfaceGDI::DrawRGBAImage(PRectangle rc, int width, int height, const unsig if (rc.Width() > 0) { HDC hMemDC = ::CreateCompatibleDC(hdc); if (rc.Width() > width) - rc.left += floor((rc.Width() - width) / 2); + rc.left += std::floor((rc.Width() - width) / 2); rc.right = rc.left + width; if (rc.Height() > height) - rc.top += floor((rc.Height() - height) / 2); + rc.top += std::floor((rc.Height() - height) / 2); rc.bottom = rc.top + height; const BITMAPINFO bpih = {{sizeof(BITMAPINFOHEADER), width, height, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, @@ -779,8 +779,10 @@ void SurfaceGDI::DrawRGBAImage(PRectangle rc, int width, int height, const unsig const BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> GdiAlphaBlend(hdc, static_cast(rc.left), static_cast(rc.top), static_cast(rc.Width()), static_cast(rc.Height()), hMemDC, 0, 0, width, height, merge); + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< SelectBitmap(hMemDC, hbmOld); ::DeleteObject(hbmMem); @@ -1232,14 +1234,14 @@ void SurfaceD2D::LineTo(int x_, int y_) { // Horizontal or vertical lines can be more precisely drawn as a filled rectangle const int xEnd = x_ - xDelta; const int left = std::min(x, xEnd); - const int width = abs(x - xEnd) + 1; + const int width = std::abs(x - xEnd) + 1; const int yEnd = y_ - yDelta; const int top = std::min(y, yEnd); - const int height = abs(y - yEnd) + 1; + const int height = std::abs(y - yEnd) + 1; const D2D1_RECT_F rectangle1 = D2D1::RectF(static_cast(left), static_cast(top), static_cast(left+width), static_cast(top+height)); pRenderTarget->FillRectangle(&rectangle1, pBrush); - } else if ((abs(xDiff) == abs(yDiff))) { + } else if ((std::abs(xDiff) == std::abs(yDiff))) { // 45 degree slope pRenderTarget->DrawLine(D2D1::Point2F(x + 0.5f, y + 0.5f), D2D1::Point2F(x_ + 0.5f - xDelta, y_ + 0.5f - yDelta), pBrush); @@ -1284,7 +1286,7 @@ void SurfaceD2D::Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesi void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) { if (pRenderTarget) { - const D2D1_RECT_F rectangle1 = D2D1::RectF(round(rc.left) + 0.5f, rc.top+0.5f, round(rc.right) - 0.5f, rc.bottom-0.5f); + const D2D1_RECT_F rectangle1 = D2D1::RectF(std::round(rc.left) + 0.5f, rc.top+0.5f, std::round(rc.right) - 0.5f, rc.bottom-0.5f); D2DPenColour(back); pRenderTarget->FillRectangle(&rectangle1, pBrush); D2DPenColour(fore); @@ -1295,7 +1297,7 @@ void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired void SurfaceD2D::FillRectangle(PRectangle rc, ColourDesired back) { if (pRenderTarget) { D2DPenColour(back); - const D2D1_RECT_F rectangle1 = D2D1::RectF(round(rc.left), rc.top, round(rc.right), rc.bottom); + const D2D1_RECT_F rectangle1 = D2D1::RectF(std::round(rc.left), rc.top, std::round(rc.right), rc.bottom); pRenderTarget->FillRectangle(&rectangle1, pBrush); } } @@ -1345,23 +1347,23 @@ void SurfaceD2D::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fil if (pRenderTarget) { if (cornerSize == 0) { // When corner size is zero, draw square rectangle to prevent blurry pixels at corners - const D2D1_RECT_F rectFill = D2D1::RectF(round(rc.left) + 1.0f, rc.top + 1.0f, round(rc.right) - 1.0f, rc.bottom - 1.0f); + const D2D1_RECT_F rectFill = D2D1::RectF(std::round(rc.left) + 1.0f, rc.top + 1.0f, std::round(rc.right) - 1.0f, rc.bottom - 1.0f); D2DPenColour(fill, alphaFill); pRenderTarget->FillRectangle(rectFill, pBrush); - const D2D1_RECT_F rectOutline = D2D1::RectF(round(rc.left) + 0.5f, rc.top + 0.5f, round(rc.right) - 0.5f, rc.bottom - 0.5f); + const D2D1_RECT_F rectOutline = D2D1::RectF(std::round(rc.left) + 0.5f, rc.top + 0.5f, std::round(rc.right) - 0.5f, rc.bottom - 0.5f); D2DPenColour(outline, alphaOutline); pRenderTarget->DrawRectangle(rectOutline, pBrush); } else { const float cornerSizeF = static_cast(cornerSize); D2D1_ROUNDED_RECT roundedRectFill = { - D2D1::RectF(round(rc.left) + 1.0f, rc.top + 1.0f, round(rc.right) - 1.0f, rc.bottom - 1.0f), + D2D1::RectF(std::round(rc.left) + 1.0f, rc.top + 1.0f, std::round(rc.right) - 1.0f, rc.bottom - 1.0f), cornerSizeF, cornerSizeF}; D2DPenColour(fill, alphaFill); pRenderTarget->FillRoundedRectangle(roundedRectFill, pBrush); D2D1_ROUNDED_RECT roundedRect = { - D2D1::RectF(round(rc.left) + 0.5f, rc.top + 0.5f, round(rc.right) - 0.5f, rc.bottom - 0.5f), + D2D1::RectF(std::round(rc.left) + 0.5f, rc.top + 0.5f, std::round(rc.right) - 0.5f, rc.bottom - 0.5f), cornerSizeF, cornerSizeF}; D2DPenColour(outline, alphaOutline); pRenderTarget->DrawRoundedRectangle(roundedRect, pBrush); @@ -1410,7 +1412,7 @@ void SurfaceD2D::GradientRectangle(PRectangle rc, const std::vector hr = pRenderTarget->CreateLinearGradientBrush( lgbp, pGradientStops, &pBrushLinear); if (SUCCEEDED(hr)) { - const D2D1_RECT_F rectangle = D2D1::RectF(round(rc.left), rc.top, round(rc.right), rc.bottom); + const D2D1_RECT_F rectangle = D2D1::RectF(std::round(rc.left), rc.top, std::round(rc.right), rc.bottom); pRenderTarget->FillRectangle(&rectangle, pBrushLinear); pBrushLinear->Release(); } @@ -1421,10 +1423,10 @@ void SurfaceD2D::GradientRectangle(PRectangle rc, const std::vector void SurfaceD2D::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) { if (pRenderTarget) { if (rc.Width() > width) - rc.left += floor((rc.Width() - width) / 2); + rc.left += std::floor((rc.Width() - width) / 2); rc.right = rc.left + width; if (rc.Height() > height) - rc.top += floor((rc.Height() - height) / 2); + rc.top += std::floor((rc.Height() - height) / 2); rc.bottom = rc.top + height; std::vector image(height * width * 4); @@ -2039,17 +2041,17 @@ void SurfaceD2D::MeasureWidths(Font &font_, std::string_view text, XYPOSITION *p XYPOSITION SurfaceD2D::Ascent(Font &font_) { SetFont(font_); - return ceil(yAscent); + return std::ceil(yAscent); } XYPOSITION SurfaceD2D::Descent(Font &font_) { SetFont(font_); - return ceil(yDescent); + return std::ceil(yDescent); } XYPOSITION SurfaceD2D::InternalLeading(Font &font_) { SetFont(font_); - return floor(yInternalLeading); + return std::floor(yInternalLeading); } XYPOSITION SurfaceD2D::Height(Font &font_) { @@ -3141,7 +3143,7 @@ LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam return ::DefWindowProc(hWnd, iMessage, wParam, lParam); case WM_MOUSEWHEEL: wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam); - if (abs(wheelDelta) >= WHEEL_DELTA) { + if (std::abs(wheelDelta) >= WHEEL_DELTA) { const int nRows = GetVisibleRows(); int linesToScroll = 1; if (nRows > 1) { diff --git a/scintilla/win32/ScintillaWin.cxx b/scintilla/win32/ScintillaWin.cxx index 672e47891..06ee43483 100644 --- a/scintilla/win32/ScintillaWin.cxx +++ b/scintilla/win32/ScintillaWin.cxx @@ -1479,7 +1479,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam // Either SCROLL or ZOOM. We handle the wheel steppings calculation wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam); - if (abs(wheelDelta) >= WHEEL_DELTA && linesPerScroll > 0) { + if (std::abs(wheelDelta) >= WHEEL_DELTA && linesPerScroll > 0) { Sci::Line linesToScroll = linesPerScroll; if (linesPerScroll == WHEEL_PAGESCROLL) linesToScroll = LinesOnScreen() - 1; @@ -2782,7 +2782,7 @@ void ScintillaWin::ImeStartComposition() { deviceHeight = (sizeZoomed * surface->LogPixelsY()) / 72; } // The negative is to allow for leading - lf.lfHeight = -(abs(deviceHeight / SC_FONT_SIZE_MULTIPLIER)); + lf.lfHeight = -(std::abs(deviceHeight / SC_FONT_SIZE_MULTIPLIER)); lf.lfWeight = vs.styles[styleHere].weight; lf.lfItalic = static_cast(vs.styles[styleHere].italic ? 1 : 0); lf.lfCharSet = DEFAULT_CHARSET; From 48211d7f8e36f4e3161407a1d61c4c980ec0e3ce Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 26 Mar 2019 10:38:48 +0100 Subject: [PATCH 3/3] + upd: VS2017 version string --- src/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Version.h b/src/Version.h index 24f1aaccc..b279c7a4d 100644 --- a/src/Version.h +++ b/src/Version.h @@ -74,7 +74,7 @@ #endif #elif (_MSC_VER >= 1916) #if(_MSC_FULL_VER >= 191627027) - #define VER_CPL MS Visual C++ 2017 v15.9.(7-9) + #define VER_CPL MS Visual C++ 2017 v15.9.(7-10) #elif(_MSC_FULL_VER >= 191627026) #define VER_CPL MS Visual C++ 2017 v15.9.(5-6) #elif(_MSC_FULL_VER >= 191627025)