diff options
-rw-r--r-- | src/CharClassify.cxx | 2 | ||||
-rw-r--r-- | src/CharacterType.h | 4 | ||||
-rw-r--r-- | test/simpleTests.py | 9 | ||||
-rw-r--r-- | test/unit/testCharClassify.cxx | 2 |
4 files changed, 9 insertions, 8 deletions
diff --git a/src/CharClassify.cxx b/src/CharClassify.cxx index caff785b0..b5eb33700 100644 --- a/src/CharClassify.cxx +++ b/src/CharClassify.cxx @@ -24,7 +24,7 @@ void CharClassify::SetDefaultCharClasses(bool includeWordClass) { for (int ch = 0; ch < maxChar; ch++) { if (ch == '\r' || ch == '\n') charClass[ch] = CharacterClass::newLine; - else if (ch < 0x20 || ch == ' ') + else if (IsControl(ch) || ch == ' ') charClass[ch] = CharacterClass::space; else if (includeWordClass && (ch >= 0x80 || IsAlphaNumeric(ch) || ch == '_')) charClass[ch] = CharacterClass::word; diff --git a/src/CharacterType.h b/src/CharacterType.h index dcef6aa78..70f4cbd05 100644 --- a/src/CharacterType.h +++ b/src/CharacterType.h @@ -20,6 +20,10 @@ constexpr bool IsASpaceOrTab(int ch) noexcept { return (ch == ' ') || (ch == '\t'); } +constexpr bool IsControl(int ch) noexcept { + return ((ch >= 0) && (ch <= 0x1F)) || (ch == 0x7F); +} + constexpr bool IsADigit(int ch) noexcept { return (ch >= '0') && (ch <= '9'); } diff --git a/test/simpleTests.py b/test/simpleTests.py index 5b5ae9c0b..1761b2e07 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -5,7 +5,7 @@ from __future__ import with_statement from __future__ import unicode_literals -import codecs, ctypes, os, sys, unittest +import ctypes, string, sys, unittest if sys.platform == "win32": import XiteWin as Xite @@ -2815,7 +2815,6 @@ class TestWordChars(unittest.TestCase): def testDefaultWordChars(self): # check that the default word chars are as expected - import string data = self.ed.GetWordChars(None) expected = set(string.digits + string.ascii_letters + '_') | \ set(chr(x) for x in range(0x80, 0x100)) @@ -2823,18 +2822,16 @@ class TestWordChars(unittest.TestCase): def testDefaultWhitespaceChars(self): # check that the default whitespace chars are as expected - import string data = self.ed.GetWhitespaceChars(None) - expected = (set(chr(x) for x in (range(0, 0x20))) | set(' ')) - \ + expected = (set(chr(x) for x in (range(0, 0x20))) | set(' ') | set('\x7f')) - \ set(['\r', '\n']) self.assertCharSetsEqual(data, expected) def testDefaultPunctuationChars(self): # check that the default punctuation chars are as expected - import string data = self.ed.GetPunctuationChars(None) expected = set(chr(x) for x in range(0x20, 0x80)) - \ - set(string.ascii_letters + string.digits + "\r\n_ ") + set(string.ascii_letters + string.digits + "\r\n\x7f_ ") self.assertCharSetsEqual(data, expected) def testCustomWordChars(self): diff --git a/test/unit/testCharClassify.cxx b/test/unit/testCharClassify.cxx index 18bf9dc29..8a9279848 100644 --- a/test/unit/testCharClassify.cxx +++ b/test/unit/testCharClassify.cxx @@ -30,7 +30,7 @@ protected: for (int ch = 0; ch < 256; ch++) { if (ch == '\r' || ch == '\n') charClass[ch] = CharacterClass::newLine; - else if (ch < 0x20 || ch == ' ') + else if (ch < 0x20 || ch == ' ' || ch == '\x7f') charClass[ch] = CharacterClass::space; else if (ch >= 0x80 || isalnum(ch) || ch == '_') charClass[ch] = CharacterClass::word; |