Skip to content

Commit

Permalink
Merge pull request #130 from Pennycook/isspace
Browse files Browse the repository at this point in the history
Replace is_whitespace function with str.isspace
  • Loading branch information
Pennycook authored Nov 26, 2024
2 parents 03aac84 + ebffc38 commit 4c607ca
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions codebasin/file_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@

log = logging.getLogger(__name__)

# This string was created by looking at all unicode code points
# and checking to see if they are considered whitespace
# ('\s') by the re module
whitespace_dict = dict.fromkeys(
"".join(
[
" \t\n\r\x0b\x0c\x1c\x1d\x1e",
"\x1f\x85\xa0\u1680\u2000\u2001",
"\u2002\u2003\u2004\u2005\u2006",
"\u2007\u2008\u2009\u200a\u2028",
"\u2029\u202f\u205f\u3000",
],
),
)


def is_whitespace(c):
"""Returns true if the character c is whitespace"""
global whitespace_dict
return c in whitespace_dict


class one_space_line:
"""
Expand All @@ -49,7 +28,7 @@ def append_char(self, c):
Append a character of no particular class to the line.
Whitespace will be dropped if the line already ends in space.
"""
if not is_whitespace(c):
if not c.isspace():
self.parts.append(c)
self.trailing_space = False
else:
Expand Down Expand Up @@ -354,7 +333,7 @@ def process(self, lineiter):
else:
self.outbuf.append_char(char)
elif self.state[-1] == "CONTINUING_FROM_SOL":
if is_whitespace(char):
if char.isspace():
self.outbuf.append_space()
elif char == "&":
self.state.pop()
Expand Down Expand Up @@ -395,13 +374,13 @@ def process(self, lineiter):
if char == "!" and self.state[-2] == "TOPLEVEL":
self.dir_check(inbuffer)
break
elif not is_whitespace(char):
elif not char.isspace():
for tmp in self.verify_continue:
self.outbuf.append_nonspace(tmp)
self.verify_continue = []
self.state.pop()
inbuffer.putback(char)
elif is_whitespace(char):
elif char.isspace():
self.verify_continue.append(char)
else:
raise RuntimeError("Unknown parser state")
Expand Down

0 comments on commit 4c607ca

Please sign in to comment.