Skip to content

Commit 4c607ca

Browse files
authored
Merge pull request #130 from Pennycook/isspace
Replace is_whitespace function with str.isspace
2 parents 03aac84 + ebffc38 commit 4c607ca

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

codebasin/file_source.py

+4-25
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,6 @@
1212

1313
log = logging.getLogger(__name__)
1414

15-
# This string was created by looking at all unicode code points
16-
# and checking to see if they are considered whitespace
17-
# ('\s') by the re module
18-
whitespace_dict = dict.fromkeys(
19-
"".join(
20-
[
21-
" \t\n\r\x0b\x0c\x1c\x1d\x1e",
22-
"\x1f\x85\xa0\u1680\u2000\u2001",
23-
"\u2002\u2003\u2004\u2005\u2006",
24-
"\u2007\u2008\u2009\u200a\u2028",
25-
"\u2029\u202f\u205f\u3000",
26-
],
27-
),
28-
)
29-
30-
31-
def is_whitespace(c):
32-
"""Returns true if the character c is whitespace"""
33-
global whitespace_dict
34-
return c in whitespace_dict
35-
3615

3716
class one_space_line:
3817
"""
@@ -49,7 +28,7 @@ def append_char(self, c):
4928
Append a character of no particular class to the line.
5029
Whitespace will be dropped if the line already ends in space.
5130
"""
52-
if not is_whitespace(c):
31+
if not c.isspace():
5332
self.parts.append(c)
5433
self.trailing_space = False
5534
else:
@@ -354,7 +333,7 @@ def process(self, lineiter):
354333
else:
355334
self.outbuf.append_char(char)
356335
elif self.state[-1] == "CONTINUING_FROM_SOL":
357-
if is_whitespace(char):
336+
if char.isspace():
358337
self.outbuf.append_space()
359338
elif char == "&":
360339
self.state.pop()
@@ -395,13 +374,13 @@ def process(self, lineiter):
395374
if char == "!" and self.state[-2] == "TOPLEVEL":
396375
self.dir_check(inbuffer)
397376
break
398-
elif not is_whitespace(char):
377+
elif not char.isspace():
399378
for tmp in self.verify_continue:
400379
self.outbuf.append_nonspace(tmp)
401380
self.verify_continue = []
402381
self.state.pop()
403382
inbuffer.putback(char)
404-
elif is_whitespace(char):
383+
elif char.isspace():
405384
self.verify_continue.append(char)
406385
else:
407386
raise RuntimeError("Unknown parser state")

0 commit comments

Comments
 (0)