From 58c1443c64fb3c42b22e6184c81ee3d6fa42edab Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 15 May 2025 09:38:52 +1000 Subject: Remove else after return when that clarifies code. --- src/Document.cxx | 194 ++++++++++++++++++++++++++----------------------------- 1 file changed, 90 insertions(+), 104 deletions(-) (limited to 'src/Document.cxx') diff --git a/src/Document.cxx b/src/Document.cxx index 027790303..8be87dca1 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -260,8 +260,7 @@ LineAnnotation *Document::EOLAnnotations() const noexcept { LineEndType Document::LineEndTypesSupported() const { if ((CpUtf8 == dbcsCodePage) && pli) return pli->LineEndTypesSupported(); - else - return LineEndType::Default; + return LineEndType::Default; } bool Document::SetDBCSCodePage(int dbcsCodePage_) { @@ -272,9 +271,8 @@ bool Document::SetDBCSCodePage(int dbcsCodePage_) { cb.SetUTF8Substance(CpUtf8 == dbcsCodePage); ModifiedAt(0); // Need to restyle whole document return true; - } else { - return false; } + return false; } bool Document::SetLineEndTypesAllowed(LineEndType lineEndBitSet_) { @@ -285,12 +283,9 @@ bool Document::SetLineEndTypesAllowed(LineEndType lineEndBitSet_) { ModifiedAt(0); cb.SetLineEndTypes(lineEndBitSetActive); return true; - } else { - return false; } - } else { - return false; } + return false; } void Document::SetSavePoint() { @@ -453,9 +448,8 @@ int Document::AddMark(Sci::Line line, int markerNum) { const DocModification mh(ModificationFlags::ChangeMarker, LineStart(line), 0, 0, nullptr, line); NotifyModified(mh); return prev; - } else { - return -1; } + return -1; } void Document::AddMarkSet(Sci::Line line, int valueSet) { @@ -763,15 +757,13 @@ int Document::LenChar(Sci::Position pos) const noexcept { if (utf8status & UTF8MaskInvalid) { // Treat as invalid and use up just one byte return 1; - } else { - return utf8status & UTF8MaskWidth; } + return utf8status & UTF8MaskWidth; + } + if (IsDBCSLeadByteNoExcept(leadByte) && IsDBCSTrailByteNoExcept(cb.CharAt(pos + 1))) { + return 2; } else { - if (IsDBCSLeadByteNoExcept(leadByte) && IsDBCSTrailByteNoExcept(cb.CharAt(pos + 1))) { - return 2; - } else { - return 1; - } + return 1; } } @@ -785,21 +777,20 @@ bool Document::InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position const int widthCharBytes = UTF8BytesOfLead[leadByte]; if (widthCharBytes == 1) { return false; - } else { - const int trailBytes = widthCharBytes - 1; - const Sci::Position len = pos - start; - if (len > trailBytes) - // pos too far from lead - return false; - unsigned char charBytes[UTF8MaxBytes] = {leadByte,0,0,0}; - for (Sci::Position b=1; b trailBytes) + // pos too far from lead + return false; + unsigned char charBytes[UTF8MaxBytes] = {leadByte,0,0,0}; + for (Sci::Position b=1; bSubstituteByPosition(this, text, length); - else - return nullptr; + } + return nullptr; } LineCharacterIndexType Document::LineCharacterIndex() const noexcept { @@ -2573,46 +2561,44 @@ void SCI_METHOD Document::StartStyling(Sci_Position position) { bool SCI_METHOD Document::SetStyleFor(Sci_Position length, char style) { if (enteredStyling != 0) { return false; - } else { - enteredStyling++; - const Sci::Position prevEndStyled = endStyled; - if (cb.SetStyleFor(endStyled, length, style)) { - const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User, - prevEndStyled, length); - NotifyModified(mh); - } - endStyled += length; - enteredStyling--; - return true; } + enteredStyling++; + const Sci::Position prevEndStyled = endStyled; + if (cb.SetStyleFor(endStyled, length, style)) { + const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User, + prevEndStyled, length); + NotifyModified(mh); + } + endStyled += length; + enteredStyling--; + return true; } bool SCI_METHOD Document::SetStyles(Sci_Position length, const char *styles) { if (enteredStyling != 0) { return false; - } else { - enteredStyling++; - bool didChange = false; - Sci::Position startMod = 0; - Sci::Position endMod = 0; - for (int iPos = 0; iPos < length; iPos++, endStyled++) { - PLATFORM_ASSERT(endStyled < Length()); - if (cb.SetStyleAt(endStyled, styles[iPos])) { - if (!didChange) { - startMod = endStyled; - } - didChange = true; - endMod = endStyled; + } + enteredStyling++; + bool didChange = false; + Sci::Position startMod = 0; + Sci::Position endMod = 0; + for (int iPos = 0; iPos < length; iPos++, endStyled++) { + PLATFORM_ASSERT(endStyled < Length()); + if (cb.SetStyleAt(endStyled, styles[iPos])) { + if (!didChange) { + startMod = endStyled; } + didChange = true; + endMod = endStyled; } - if (didChange) { - const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User, - startMod, endMod - startMod + 1); - NotifyModified(mh); - } - enteredStyling--; - return true; } + if (didChange) { + const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User, + startMod, endMod - startMod + 1); + NotifyModified(mh); + } + enteredStyling--; + return true; } void Document::EnsureStyledTo(Sci::Position pos) { @@ -3123,10 +3109,10 @@ public: } [[nodiscard]] char CharAt(Sci::Position index) const noexcept override { - if (index < 0 || index >= end) + if (index < 0 || index >= end) { return 0; - else - return pdoc->CharAt(index); + } + return pdoc->CharAt(index); } [[nodiscard]] Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir) const noexcept override { return pdoc->MovePositionOutsideChar(pos, moveDir, false); -- cgit v1.2.3