Last active
September 13, 2019 20:07
-
-
Save eestrada/390440804116216c25f6cf397b3120eb to your computer and use it in GitHub Desktop.
Small gist for how to compute unicode whitespace (since it doesn't exists as a constant like `string.whitespace` does)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is free and unencumbered software released into the public domain | |
# using the Unlicense. Please refer to <http://unlicense.org/> | |
def _unicode_whitespace(): | |
# Yes, it is bad practice to import modules in a function, | |
# but we are trying to avoid leaving garbage around once we are done generating our values. | |
import re | |
import sys | |
ws_re = re.compile(r'\s') | |
uchars = map(chr, range(sys.maxunicode+1)) | |
uws_matches = map(ws_re.fullmatch, uchars) | |
uws_matches_filt = filter(None, uws_matches) | |
unicode_whitespace = ''.join(m.string for m in uws_matches_filt) | |
return unicode_whitespace | |
unicode_whitespace = _unicode_whitespace() | |
# NOTE: clean up the namespace since we don't need this anymore | |
del _unicode_whitespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment