diff options
author | Neil <nyamatongwe@gmail.com> | 2025-04-03 10:07:20 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-04-03 10:07:20 +1100 |
commit | edb7369a2c6a19393dc413a9595a234969fc2731 (patch) | |
tree | 1dd7de2ad759c58d48606bd8a204503944feec12 | |
parent | f40a7ce87a20e830a4959e33238d2caadef0ea04 (diff) | |
download | scintilla-mirror-edb7369a2c6a19393dc413a9595a234969fc2731.tar.gz |
Silence 'magic' number clang-tidy warning where there is intense use of literal
constants for processing character encodings or similar and where declaring
constants would make the code more obscure, not less.
-rw-r--r-- | src/CharacterCategoryMap.cxx | 6 | ||||
-rw-r--r-- | src/DBCS.cxx | 8 | ||||
-rw-r--r-- | src/Document.cxx | 8 | ||||
-rw-r--r-- | src/UniConversion.cxx | 6 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 6 |
5 files changed, 34 insertions, 0 deletions
diff --git a/src/CharacterCategoryMap.cxx b/src/CharacterCategoryMap.cxx index 5bf6394ba..10218b3af 100644 --- a/src/CharacterCategoryMap.cxx +++ b/src/CharacterCategoryMap.cxx @@ -4072,6 +4072,10 @@ namespace { enum class OtherID { oidNone, oidStart, oidContinue }; +// Silence 'magic' number warning as these character values are not used in multiple places. + +// NOLINTBEGIN(*-magic-numbers) + // Some characters are treated as valid for identifiers even // though most characters from their category are not. // Values copied from http://www.unicode.org/Public/9.0.0/ucd/PropList.txt @@ -4161,6 +4165,8 @@ bool OmitXidContinue(int character) noexcept { } } +// NOLINTEND(*-magic-numbers) + } // UAX #31 defines ID_Start as diff --git a/src/DBCS.cxx b/src/DBCS.cxx index 0f22a705a..f53b8e9ed 100644 --- a/src/DBCS.cxx +++ b/src/DBCS.cxx @@ -16,6 +16,12 @@ using namespace Scintilla::Internal; namespace Scintilla::Internal { +// Silence 'magic' number use since the set of DBCS lead and trail bytes differ +// between encodings and would require many constant declarations that would just +// obscure the behaviour. + +// NOLINTBEGIN(*-magic-numbers) + bool DBCSIsLeadByte(int codePage, char ch) noexcept { // Byte ranges found in Wikipedia articles with relevant search strings in each case const unsigned char uch = ch; @@ -91,6 +97,8 @@ bool IsDBCSValidSingleByte(int codePage, int ch) noexcept { } } +// NOLINTEND(*-magic-numbers) + using CodePageToFoldMap = std::map<int, FoldMap>; CodePageToFoldMap cpToFoldMap; diff --git a/src/Document.cxx b/src/Document.cxx index 5dd64eed9..ddcf43276 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1109,6 +1109,12 @@ bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const { return IsDBCSLeadByteNoExcept(ch); } +// Silence 'magic' number use since the set of DBCS lead and trail bytes differ +// between encodings and would require many constant declarations that would just +// obscure the behaviour. + +// NOLINTBEGIN(*-magic-numbers) + bool Document::IsDBCSLeadByteNoExcept(char ch) const noexcept { // Used inside core Scintilla // Byte ranges found in Wikipedia articles with relevant search strings in each case @@ -1192,6 +1198,8 @@ unsigned char Document::DBCSMinTrailByte() const noexcept { } } +// NOLINTEND(*-magic-numbers) + int Document::DBCSDrawBytes(std::string_view text) const noexcept { if (text.length() <= 1) { return static_cast<int>(text.length()); diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx index 4cf51c2b9..7183018f7 100644 --- a/src/UniConversion.cxx +++ b/src/UniConversion.cxx @@ -326,6 +326,10 @@ const unsigned char UTF8BytesOfLead[256] = { 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // F0 - FF }; +// Silence 'magic' number warning as UTF-8 needs to distinguish byte values and byte value ranges. + +// NOLINTBEGIN(*-magic-numbers) + // Return both the width of the first character in the string and a status // saying whether it is valid or invalid. // Most invalid sequences return a width of 1 so are treated as isolated bytes but @@ -403,6 +407,8 @@ int UTF8Classify(const unsigned char *us, size_t len) noexcept { return UTF8MaskInvalid | 1; } +// NOLINTEND(*-magic-numbers) + int UTF8Classify(const char *s, size_t len) noexcept { return UTF8Classify(reinterpret_cast<const unsigned char *>(s), len); } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 5b88b715c..d6ae32736 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -1614,6 +1614,10 @@ constexpr bool IsVisualCharacter(wchar_t charCode) noexcept { namespace Scintilla::Internal { +// Removing 'magic' numbers here would not help here. + +// NOLINTBEGIN(*-magic-numbers) + UINT CodePageFromCharSet(CharacterSet characterSet, UINT documentCodePage) noexcept { if (documentCodePage == CpUtf8) { return CpUtf8; @@ -1646,6 +1650,8 @@ UINT CodePageFromCharSet(CharacterSet characterSet, UINT documentCodePage) noexc return documentCodePage; } +// NOLINTEND(*-magic-numbers) + } UINT ScintillaWin::CodePageOfDocument() const noexcept { |