-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C escapes #174
C escapes #174
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
quiet_level = 0 | ||
encodings = ['utf-8', 'iso-8859-1'] | ||
word_regex = re.compile(r"[\w\-']+") | ||
c_escape_regex = re.compile(r'\\\w') | ||
# Users might want to link this file into /usr/local/bin, so we resolve the | ||
# symbolic link path to the real path if necessary. | ||
default_dictionary = os.path.join(os.path.dirname(os.path.realpath(__file__)), | ||
|
@@ -281,6 +282,12 @@ def parse_options(args): | |
action='store_true', default=False, | ||
help='Check file names as well.') | ||
|
||
parser.add_option('--c-escapes', | ||
action='store_true', default=False, | ||
help='Treats files as if they contain C-style character ' | ||
'escapes. So for example "\\nHello" is parsed as ' | ||
'"hello" instead of "nhallo".') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nhallo -> nhello also And maybe |
||
|
||
(o, args) = parser.parse_args(list(args)) | ||
|
||
if not args: | ||
|
@@ -473,6 +480,9 @@ def parse_file(filename, colors, summary): | |
fixed_words = set() | ||
asked_for = set() | ||
|
||
if options.c_escapes: | ||
line = c_escape_regex.sub(' ', line) | ||
|
||
for word in word_regex.findall(line): | ||
lword = word.lower() | ||
if lword in misspellings: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,6 +256,15 @@ def test_check_filename(): | |
assert_equal(cs.main('-f', d), 1) | ||
|
||
|
||
def test_c_escapes(): | ||
"""Test c-esacpes option""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meta spelling error, it should be c-escapes! 😄 |
||
with TemporaryDirectory() as d: | ||
with open(op.join(d, 'test.txt'), 'w') as f: | ||
f.write('\\nabandonned') | ||
assert_equal(cs.main(d), 0) | ||
assert_equal(cs.main('--c-escapes', d), 1) | ||
|
||
|
||
class TemporaryDirectory(object): | ||
"""Backport for 2.7""" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to use the standard set of escape sequences?