diff options
| author | Neil <nyamatongwe@gmail.com> | 2026-04-13 11:31:36 +1000 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2026-04-13 11:31:36 +1000 |
| commit | 4db72474ccc799b6f39bb37604154cbcf33e08be (patch) | |
| tree | 6b9f00c323fb287b1f00bb27d2e5e581d9a2d9e2 | |
| parent | 59d707bee0292d434513b28bcbfa7257c56a910c (diff) | |
| download | scintilla-mirror-4db72474ccc799b6f39bb37604154cbcf33e08be.tar.gz | |
Copy AnyOf from Lexilla to clarify code checking if a value is in a set.
| -rw-r--r-- | src/CharacterType.h | 14 | ||||
| -rw-r--r-- | src/Document.cxx | 4 | ||||
| -rw-r--r-- | src/EditView.cxx | 6 | ||||
| -rw-r--r-- | src/Editor.cxx | 14 |
4 files changed, 26 insertions, 12 deletions
diff --git a/src/CharacterType.h b/src/CharacterType.h index 8564e138d..a7732cec9 100644 --- a/src/CharacterType.h +++ b/src/CharacterType.h @@ -12,6 +12,20 @@ namespace Scintilla::Internal { // Functions for classifying characters +template <typename T, typename... Args> +constexpr bool AnyOf(T t, Args... args) noexcept { +#if defined(__clang__) + static_assert(__is_integral(T) || __is_enum(T)); +#endif + return ((t == args) || ...); +} + +// prevent pointer without <type_traits> +template <typename T, typename... Args> +constexpr void AnyOf([[maybe_unused]] T *t, [[maybe_unused]] Args... args) noexcept {} +template <typename T, typename... Args> +constexpr void AnyOf([[maybe_unused]] const T *t, [[maybe_unused]] Args... args) noexcept {} + /** * Check if a character is a space. * This is ASCII specific but is safe with chars >= 0x80. diff --git a/src/Document.cxx b/src/Document.cxx index d4754233e..8e9c7d8c4 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -3010,7 +3010,7 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe return -1; const int styBrace = StyleIndexAt(position); int direction = -1; - if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') + if (AnyOf(chBrace, '(', '[', '{', '<')) direction = 1; int depth = 1; position = useStartPos ? startPos : position + direction; @@ -3023,7 +3023,7 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe while ((position >= 0) && (position < LengthNoExcept())) { const unsigned char chAtPos = CharAt(position); - if (chAtPos == chBrace || chAtPos == chSeek) { + if (AnyOf(chAtPos, chBrace, chSeek)) { if (((position > GetEndStyled()) || (StyleIndexAt(position) == styBrace)) && (chAtPos <= maxSafeChar || position == MovePositionOutsideChar(position, direction, false))) { depth += (chAtPos == chBrace) ? 1 : -1; diff --git a/src/EditView.cxx b/src/EditView.cxx index d1e9c4103..154954c70 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1347,7 +1347,7 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c namespace { constexpr bool AnnotationBoxedOrIndented(AnnotationVisible annotationVisible) noexcept { - return annotationVisible == AnnotationVisible::Boxed || annotationVisible == AnnotationVisible::Indented; + return AnyOf(annotationVisible, AnnotationVisible::Boxed, AnnotationVisible::Indented); } } @@ -2317,7 +2317,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi void EditView::DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line line, int xStart, PRectangle rcLine, int subLine, Sci::Line lineVisible) { - if ((vsDraw.viewIndentationGuides == IndentView::LookForward || vsDraw.viewIndentationGuides == IndentView::LookBoth) + if (AnyOf(vsDraw.viewIndentationGuides, IndentView::LookForward, IndentView::LookBoth) && (subLine == 0)) { const Sci::Position posLineStart = model.pdoc->LineStart(line); int indentSpace = model.pdoc->GetLineIndentation(line); @@ -2711,7 +2711,7 @@ Sci::Position EditView::FormatRange(bool draw, CharacterRangeFull chrg, Rectangl } else if (colourMode == PrintOption::BlackOnWhite) { it->fore = black; it->back = white; - } else if (colourMode == PrintOption::ColourOnWhite || colourMode == PrintOption::ColourOnWhiteDefaultBG) { + } else if (AnyOf(colourMode, PrintOption::ColourOnWhite, PrintOption::ColourOnWhiteDefaultBG)) { it->back = white; } } diff --git a/src/Editor.cxx b/src/Editor.cxx index 500373a8a..d946c7bd2 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -3818,7 +3818,7 @@ int Editor::DelWordOrLine(Message iMessage) { // Rightwards and leftwards deletions differ in treatment of virtual space. // Clear virtual space for leftwards, realise for rightwards. - const bool leftwards = (iMessage == Message::DelWordLeft) || (iMessage == Message::DelLineLeft); + const bool leftwards = AnyOf(iMessage, Message::DelWordLeft, Message::DelLineLeft); if (!additionalSelectionTyping) { InvalidateWholeSelection(); @@ -4029,14 +4029,14 @@ int Editor::KeyCommand(Message iMessage) { break; case Message::DeleteBack: DelCharBack(true); - if ((caretSticky == CaretSticky::Off) || (caretSticky == CaretSticky::WhiteSpace)) { + if (AnyOf(caretSticky, CaretSticky::Off, CaretSticky::WhiteSpace)) { SetLastXChosen(); } EnsureCaretVisible(); break; case Message::DeleteBackNotLine: DelCharBack(false); - if ((caretSticky == CaretSticky::Off) || (caretSticky == CaretSticky::WhiteSpace)) { + if (AnyOf(caretSticky, CaretSticky::Off, CaretSticky::WhiteSpace)) { SetLastXChosen(); } EnsureCaretVisible(); @@ -4053,7 +4053,7 @@ int Editor::KeyCommand(Message iMessage) { case Message::BackTab: case Message::LineDedent: Indent(false, iMessage == Message::LineDedent); - if ((caretSticky == CaretSticky::Off) || (caretSticky == CaretSticky::WhiteSpace)) { + if (AnyOf(caretSticky, CaretSticky::Off, CaretSticky::WhiteSpace)) { SetLastXChosen(); } EnsureCaretVisible(); @@ -4859,7 +4859,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, KeyMod modi wordSelectAnchorEndPos = endWord; wordSelectInitialCaretPos = sel.MainCaret(); WordSelection(wordSelectInitialCaretPos); - } else if (selectionUnit == TextUnit::subLine || selectionUnit == TextUnit::wholeLine) { + } else if (AnyOf(selectionUnit, TextUnit::subLine, TextUnit::wholeLine)) { lineAnchorPos = newPos.Position(); LineSelection(lineAnchorPos, lineAnchorPos, selectionUnit == TextUnit::wholeLine); //Platform::DebugPrintf("Triple click: %d - %d\n", anchor, currentPos); @@ -5395,7 +5395,7 @@ Sci::Position Editor::PositionAfterMaxStyling(Sci::Position posMax, bool scrolli } void Editor::StartIdleStyling(bool truncatedLastStyling) { - if ((idleStyling == IdleStyling::All) || (idleStyling == IdleStyling::AfterVisible)) { + if (AnyOf(idleStyling, IdleStyling::All, IdleStyling::AfterVisible)) { if (pdoc->GetEndStyled() < pdoc->Length()) { // Style remainder of document in idle time needIdleStyling = true; @@ -6344,7 +6344,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::Paste: Paste(); - if ((caretSticky == CaretSticky::Off) || (caretSticky == CaretSticky::WhiteSpace)) { + if (AnyOf(caretSticky, CaretSticky::Off, CaretSticky::WhiteSpace)) { SetLastXChosen(); } EnsureCaretVisible(); |
