aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/CaseConvert.cxx6
-rw-r--r--src/Document.cxx36
-rw-r--r--win32/PlatWin.cxx6
-rw-r--r--win32/ScintillaWin.cxx66
4 files changed, 56 insertions, 58 deletions
diff --git a/src/CaseConvert.cxx b/src/CaseConvert.cxx
index 752fd54e0..560bc8c70 100644
--- a/src/CaseConvert.cxx
+++ b/src/CaseConvert.cxx
@@ -605,7 +605,7 @@ class CaseConverter final : public ICaseConverter {
return character < other.character;
}
};
- typedef std::vector<CharacterConversion> CharacterToConversion;
+ using CharacterToConversion = std::vector<CharacterConversion>;
CharacterToConversion characterToConversion;
// The parallel arrays
std::vector<int> characters;
@@ -613,7 +613,7 @@ class CaseConverter final : public ICaseConverter {
public:
CaseConverter() noexcept = default;
- bool Initialised() const noexcept {
+ [[nodiscard]] bool Initialised() const noexcept {
return !characters.empty();
}
void Add(int character, std::string_view conversion_) {
@@ -787,7 +787,7 @@ size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixe
std::string CaseConvertString(const std::string &s, CaseConversion conversion) {
std::string retMapped(s.length() * maxExpansionCaseConversion, 0);
- const size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(),
+ const size_t lenMapped = CaseConvertString(retMapped.data(), retMapped.length(), s.c_str(), s.length(),
conversion);
retMapped.resize(lenMapped);
return retMapped;
diff --git a/src/Document.cxx b/src/Document.cxx
index 05f80640c..5dd64eed9 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -2373,7 +2373,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
constexpr size_t maxFoldingExpansion = 4;
std::vector<char> searchThing((lengthFind+1) * UTF8MaxBytes * maxFoldingExpansion + 1);
const size_t lenSearch =
- pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind);
+ pcf->Fold(searchThing.data(), searchThing.size(), search, lengthFind);
while (forward ? (pos < endPos) : (pos >= endPos)) {
int widthFirstCharacter = 1;
Sci::Position posIndexDocument = pos;
@@ -2406,7 +2406,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
// memcmp may examine lenFlat bytes in both arguments so assert it doesn't read past end of searchThing
assert((indexSearch + lenFlat) <= searchThing.size());
// Does folded match the buffer
- characterMatches = 0 == memcmp(folded, &searchThing[0] + indexSearch, lenFlat);
+ characterMatches = 0 == memcmp(folded, searchThing.data() + indexSearch, lenFlat);
}
if (!characterMatches) {
break;
@@ -2432,7 +2432,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
constexpr size_t maxBytesCharacter = 2;
constexpr size_t maxFoldingExpansion = 4;
std::vector<char> searchThing((lengthFind+1) * maxBytesCharacter * maxFoldingExpansion + 1);
- const size_t lenSearch = pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind);
+ const size_t lenSearch = pcf->Fold(searchThing.data(), searchThing.size(), search, lengthFind);
while (forward ? (pos < endPos) : (pos >= endPos)) {
int widthFirstCharacter = 0;
Sci::Position indexDocument = 0;
@@ -2461,7 +2461,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
// memcmp may examine lenFlat bytes in both arguments so assert it doesn't read past end of searchThing
assert((indexSearch + lenFlat) <= searchThing.size());
// Does folded match the buffer
- characterMatches = 0 == memcmp(folded, &searchThing[0] + indexSearch, lenFlat);
+ characterMatches = 0 == memcmp(folded, searchThing.data() + indexSearch, lenFlat);
}
if (!characterMatches) {
break;
@@ -2486,7 +2486,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con
} else {
const Sci::Position endSearch = (startPos <= endPos) ? endPos - lengthFind + 1 : endPos;
std::vector<char> searchThing(lengthFind + 1);
- pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind);
+ pcf->Fold(searchThing.data(), searchThing.size(), search, lengthFind);
while (forward ? (pos < endSearch) : (pos >= endSearch)) {
bool found = (pos + lengthFind) <= limitPos;
for (int indexSearch = 0; (indexSearch < lengthFind) && found; indexSearch++) {
@@ -3088,7 +3088,7 @@ public:
lineRangeEnd = doc->SciLineFromPosition(endPos);
lineRangeBreak = lineRangeEnd + increment;
}
- Range LineRange(Sci::Line line, Sci::Position lineStartPos, Sci::Position lineEndPos) const noexcept {
+ [[nodiscard]] Range LineRange(Sci::Line line, Sci::Position lineStartPos, Sci::Position lineEndPos) const noexcept {
Range range(lineStartPos, lineEndPos);
if (increment == 1) {
if (line == lineRangeStart)
@@ -3114,13 +3114,13 @@ public:
pdoc(pdoc_), end(end_) {
}
- char CharAt(Sci::Position index) const noexcept override {
+ [[nodiscard]] char CharAt(Sci::Position index) const noexcept override {
if (index < 0 || index >= end)
return 0;
else
return pdoc->CharAt(index);
}
- Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir) const noexcept override {
+ [[nodiscard]] Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir) const noexcept override {
return pdoc->MovePositionOutsideChar(pos, moveDir, false);
}
};
@@ -3163,10 +3163,10 @@ public:
bool operator!=(const ByteIterator &other) const noexcept {
return doc != other.doc || position != other.position;
}
- Sci::Position Pos() const noexcept {
+ [[nodiscard]] Sci::Position Pos() const noexcept {
return position;
}
- Sci::Position PosRoundUp() const noexcept {
+ [[nodiscard]] Sci::Position PosRoundUp() const noexcept {
return position;
}
};
@@ -3191,11 +3191,11 @@ class UTF8Iterator {
// These 3 fields determine the iterator position and are used for comparisons
const Document *doc;
Sci::Position position;
- size_t characterIndex;
+ size_t characterIndex = 0;
// Remaining fields are derived from the determining fields so are excluded in comparisons
- unsigned int lenBytes;
- size_t lenCharacters;
- wchar_t buffered[2];
+ unsigned int lenBytes = 0;
+ size_t lenCharacters = 0;
+ wchar_t buffered[2]{};
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = wchar_t;
@@ -3204,9 +3204,7 @@ public:
using reference = wchar_t&;
explicit UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :
- doc(doc_), position(position_), characterIndex(0), lenBytes(0), lenCharacters(0), buffered{} {
- buffered[0] = 0;
- buffered[1] = 0;
+ doc(doc_), position(position_) {
if (doc) {
ReadCharacter();
}
@@ -3258,10 +3256,10 @@ public:
position != other.position ||
characterIndex != other.characterIndex;
}
- Sci::Position Pos() const noexcept {
+ [[nodiscard]] Sci::Position Pos() const noexcept {
return position;
}
- Sci::Position PosRoundUp() const noexcept {
+ [[nodiscard]] Sci::Position PosRoundUp() const noexcept {
if (characterIndex)
return position + lenBytes; // Force to end of character
else
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 37c33d6ed..7598f9447 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -100,9 +100,9 @@ void LoadD2DOnce() noexcept {
}
}
- typedef HRESULT (WINAPI *D2D1CFSig)(D2D1_FACTORY_TYPE factoryType, REFIID riid,
+ using D2D1CFSig = HRESULT (WINAPI *)(D2D1_FACTORY_TYPE factoryType, REFIID riid,
CONST D2D1_FACTORY_OPTIONS *pFactoryOptions, IUnknown **factory);
- typedef HRESULT (WINAPI *DWriteCFSig)(DWRITE_FACTORY_TYPE factoryType, REFIID iid,
+ using DWriteCFSig = HRESULT (WINAPI *)(DWRITE_FACTORY_TYPE factoryType, REFIID iid,
IUnknown **factory);
hDLLD2D = ::LoadLibraryEx(TEXT("D2D1.DLL"), {}, loadLibraryFlags);
@@ -3212,7 +3212,7 @@ public:
char *SetWords(const char *s) {
words = std::vector<char>(s, s+strlen(s)+1);
- return &words[0];
+ return words.data();
}
};
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index ad3691859..af20467ad 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -124,7 +124,7 @@ constexpr int IndicatorTarget = IndicatorInput + 1;
constexpr int IndicatorConverted = IndicatorInput + 2;
constexpr int IndicatorUnknown = IndicatorInput + 3;
-typedef UINT_PTR (WINAPI *SetCoalescableTimerSig)(HWND hwnd, UINT_PTR nIDEvent,
+using SetCoalescableTimerSig = UINT_PTR (WINAPI *)(HWND hwnd, UINT_PTR nIDEvent,
UINT uElapse, TIMERPROC lpTimerFunc, ULONG uToleranceDelay);
}
@@ -275,26 +275,26 @@ public:
::ImmReleaseContext(hwnd, hIMC);
}
- unsigned int GetImeCaretPos() const noexcept {
+ [[nodiscard]] unsigned int GetImeCaretPos() const noexcept {
return ImmGetCompositionStringW(hIMC, GCS_CURSORPOS, nullptr, 0);
}
- std::vector<BYTE> GetImeAttributes() const {
+ [[nodiscard]] std::vector<BYTE> GetImeAttributes() const {
const int attrLen = ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, nullptr, 0);
std::vector<BYTE> attr(attrLen, 0);
- ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, &attr[0], static_cast<DWORD>(attr.size()));
+ ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, attr.data(), static_cast<DWORD>(attr.size()));
return attr;
}
- LONG GetCompositionStringLength(DWORD dwIndex) const noexcept {
+ [[nodiscard]] LONG GetCompositionStringLength(DWORD dwIndex) const noexcept {
const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, nullptr, 0);
return byteLen / sizeof(wchar_t);
}
- std::wstring GetCompositionString(DWORD dwIndex) const {
+ [[nodiscard]] std::wstring GetCompositionString(DWORD dwIndex) const {
const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, nullptr, 0);
std::wstring wcs(byteLen / 2, 0);
- ::ImmGetCompositionStringW(hIMC, dwIndex, &wcs[0], byteLen);
+ ::ImmGetCompositionStringW(hIMC, dwIndex, wcs.data(), byteLen);
return wcs;
}
};
@@ -480,7 +480,7 @@ class ScintillaWin :
static ATOM callClassAtom;
float deviceScaleFactor = 1.f;
- int GetFirstIntegralMultipleDeviceScaleFactor() const noexcept {
+ [[nodiscard]] int GetFirstIntegralMultipleDeviceScaleFactor() const noexcept {
return static_cast<int>(std::ceil(deviceScaleFactor));
}
@@ -511,7 +511,7 @@ class ScintillaWin :
void EnsureRenderTarget(HDC hdc);
#endif
void DropRenderTarget() noexcept;
- HWND MainHWND() const noexcept;
+ [[nodiscard]] HWND MainHWND() const noexcept;
static sptr_t DirectFunction(
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam);
@@ -541,7 +541,7 @@ class ScintillaWin :
void ImeStartComposition();
void ImeEndComposition();
LRESULT ImeOnReconvert(LPARAM lParam);
- LRESULT ImeOnDocumentFeed(LPARAM lParam) const;
+ [[nodiscard]] LRESULT ImeOnDocumentFeed(LPARAM lParam) const;
sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam);
sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam);
static bool KoreanIME() noexcept;
@@ -553,10 +553,10 @@ class ScintillaWin :
void ToggleHanja();
void AddWString(std::wstring_view wsv, CharacterSource charSource);
- UINT CodePageOfDocument() const noexcept;
- bool ValidCodePage(int codePage) const override;
- std::string UTF8FromEncoded(std::string_view encoded) const override;
- std::string EncodedFromUTF8(std::string_view utf8) const override;
+ [[nodiscard]] UINT CodePageOfDocument() const noexcept;
+ [[nodiscard]] bool ValidCodePage(int codePage) const override;
+ [[nodiscard]] std::string UTF8FromEncoded(std::string_view encoded) const override;
+ [[nodiscard]] std::string EncodedFromUTF8(std::string_view utf8) const override;
std::string EncodeWString(std::wstring_view wsv);
sptr_t DefWndProc(Message iMessage, uptr_t wParam, sptr_t lParam) override;
@@ -579,7 +579,7 @@ class ScintillaWin :
void SetVerticalScrollPos() override;
void SetHorizontalScrollPos() override;
void HorizontalScrollToClamped(int xPos);
- HorizontalScrollRange GetHorizontalScrollRange() const;
+ [[nodiscard]] HorizontalScrollRange GetHorizontalScrollRange() const;
bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) override;
void NotifyChange() override;
void NotifyFocus(bool focus) override;
@@ -604,9 +604,9 @@ class ScintillaWin :
void FullPaint();
void FullPaintDC(HDC hdc);
bool IsCompatibleDC(HDC hOtherDC) noexcept;
- DWORD EffectFromState(DWORD grfKeyState) const noexcept;
+ [[nodiscard]] DWORD EffectFromState(DWORD grfKeyState) const noexcept;
- bool IsVisible() const noexcept;
+ [[nodiscard]] bool IsVisible() const noexcept;
int SetScrollInfo(int nBar, LPCSCROLLINFO lpsi, BOOL bRedraw) noexcept;
bool GetScrollInfo(int nBar, LPSCROLLINFO lpsi) noexcept;
bool ChangeScrollRange(int nBar, int nMin, int nMax, UINT nPage) noexcept;
@@ -615,7 +615,7 @@ class ScintillaWin :
sptr_t GetText(uptr_t wParam, sptr_t lParam);
Window::Cursor ContextCursor(Point pt);
sptr_t ShowContextMenu(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
- PRectangle GetClientRectangle() const override;
+ [[nodiscard]] PRectangle GetClientRectangle() const override;
void SizeWindow();
sptr_t MouseMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
sptr_t KeyMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
@@ -651,13 +651,13 @@ public:
static bool Register(HINSTANCE hInstance_) noexcept;
static bool Unregister() noexcept;
- bool DragIsRectangularOK(CLIPFORMAT fmt) const noexcept {
+ [[nodiscard]] bool DragIsRectangularOK(CLIPFORMAT fmt) const noexcept {
return drag.rectangular && (fmt == cfColumnSelect);
}
private:
// For use in creating a system caret
- bool HasCaretSizeChanged() const noexcept;
+ [[nodiscard]] bool HasCaretSizeChanged() const noexcept;
BOOL CreateSystemCaret();
BOOL DestroySystemCaret() noexcept;
HBITMAP sysCaretBitmap;
@@ -1200,7 +1200,7 @@ Sci::Position ScintillaWin::EncodedFromUTF8(const char *utf8, char *encoded) con
const std::string_view utf8Input(utf8, inputLength);
const int charsLen = WideCharLenFromMultiByte(CpUtf8, utf8Input);
std::wstring characters(charsLen, L'\0');
- WideCharFromMultiByte(CpUtf8, utf8Input, &characters[0], charsLen);
+ WideCharFromMultiByte(CpUtf8, utf8Input, characters.data(), charsLen);
const int encodedLen = MultiByteLenFromWideChar(CodePageOfDocument(), characters);
if (encoded) {
@@ -1378,7 +1378,7 @@ void ScintillaWin::SelectionToHangul() {
if (utf16Len > 0) {
std::string documentStr(documentStrLen, '\0');
- pdoc->GetCharRange(&documentStr[0], selStart, documentStrLen);
+ pdoc->GetCharRange(documentStr.data(), selStart, documentStrLen);
std::wstring uniStr = StringDecode(documentStr, CodePageOfDocument());
const bool converted = HanjaDict::GetHangulOfHanja(uniStr);
@@ -1387,7 +1387,7 @@ void ScintillaWin::SelectionToHangul() {
documentStr = StringEncode(uniStr, CodePageOfDocument());
UndoGroup ug(pdoc);
ClearSelection();
- InsertPaste(&documentStr[0], documentStr.size());
+ InsertPaste(documentStr.data(), documentStr.size());
}
}
}
@@ -1410,7 +1410,7 @@ void ScintillaWin::EscapeHanja() {
// So enlarge it enough to Maximum 4 as in UTF-8.
constexpr size_t safeLength = UTF8MaxBytes + 1;
std::string oneChar(safeLength, '\0');
- pdoc->GetCharRange(&oneChar[0], currentPos, oneCharLen);
+ pdoc->GetCharRange(oneChar.data(), currentPos, oneCharLen);
std::wstring uniChar = StringDecode(oneChar, CodePageOfDocument());
@@ -1419,7 +1419,7 @@ void ScintillaWin::EscapeHanja() {
// Set the candidate box position since IME may show it.
SetCandidateWindowPos();
// IME_ESC_HANJA_MODE appears to receive the first character only.
- if (::ImmEscapeW(GetKeyboardLayout(0), imc.hIMC, IME_ESC_HANJA_MODE, &uniChar[0])) {
+ if (::ImmEscapeW(GetKeyboardLayout(0), imc.hIMC, IME_ESC_HANJA_MODE, uniChar.data())) {
SetSelection(currentPos, currentPos + oneCharLen);
}
}
@@ -1692,7 +1692,7 @@ sptr_t ScintillaWin::GetText(uptr_t wParam, sptr_t lParam) {
sizeRequestedRange = pdoc->Length();
}
std::string docBytes(sizeRequestedRange, '\0');
- pdoc->GetCharRange(&docBytes[0], 0, sizeRequestedRange);
+ pdoc->GetCharRange(docBytes.data(), 0, sizeRequestedRange);
const size_t uLen = UTF16FromUTF8(docBytes, ptr, lengthWanted);
ptr[uLen] = L'\0';
return uLen;
@@ -2811,7 +2811,7 @@ public:
}
const size_t nUtf16Mixed = WideCharFromMultiByte(cp,
std::string_view(mixed, lenMixed),
- &utf16Mixed[0],
+ utf16Mixed.data(),
utf16Mixed.size());
if (nUtf16Mixed == 0) {
@@ -2837,7 +2837,7 @@ public:
}
}
- const std::wstring_view wsvFolded(&utf16Folded[0], lenFlat);
+ const std::wstring_view wsvFolded(utf16Folded.data(), lenFlat);
const size_t lenOut = MultiByteLenFromWideChar(cp, wsvFolded);
if (lenOut < sizeFolded) {
@@ -2973,7 +2973,7 @@ public:
operator bool() const noexcept {
return ptr != nullptr;
}
- SIZE_T Size() const noexcept {
+ [[nodiscard]] SIZE_T Size() const noexcept {
return ::GlobalSize(hand);
}
};
@@ -3136,7 +3136,7 @@ STDMETHODIMP FormatEnumerator::Reset() {
STDMETHODIMP FormatEnumerator::Clone(IEnumFORMATETC **ppenum) {
FormatEnumerator *pfe;
try {
- pfe = new FormatEnumerator(pos, &formats[0], formats.size());
+ pfe = new FormatEnumerator(pos, formats.data(), formats.size());
} catch (...) {
return E_OUTOFMEMORY;
}
@@ -3375,7 +3375,7 @@ LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) {
return rcSize; // Immediately be back with rcSize of memory block.
wchar_t *rcFeedStart = reinterpret_cast<wchar_t*>(rc + 1);
- memcpy(rcFeedStart, &rcFeed[0], rcFeedLen);
+ memcpy(rcFeedStart, rcFeed.data(), rcFeedLen);
std::string rcCompString = RangeText(mainStart, mainEnd);
std::wstring rcCompWstring = StringDecode(rcCompString, codePage);
@@ -3453,7 +3453,7 @@ LRESULT ScintillaWin::ImeOnDocumentFeed(LPARAM lParam) const {
return rcSize;
wchar_t *rcFeedStart = reinterpret_cast<wchar_t*>(rc + 1);
- memcpy(rcFeedStart, &rcFeed[0], rcFeedLen);
+ memcpy(rcFeedStart, rcFeed.data(), rcFeedLen);
IMContext imc(MainHWND());
if (!imc.hIMC)
@@ -3886,7 +3886,7 @@ BOOL ScintillaWin::CreateSystemCaret() {
sysCaretHeight;
std::vector<BYTE> bits(bitmapSize);
sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,
- 1, &bits[0]);
+ 1, bits.data());
const BOOL retval = ::CreateCaret(
MainHWND(), sysCaretBitmap,
sysCaretWidth, sysCaretHeight);