Simplified regular expressions for Python 3.

This commit is contained in:
Project Nayuki 2020-05-08 16:02:06 +00:00
parent 55dd3c881e
commit 9ed47110a5
1 changed files with 2 additions and 2 deletions

View File

@ -856,14 +856,14 @@ class QrSegment:
# (Public) Describes precisely all strings that are encodable in numeric mode. # (Public) Describes precisely all strings that are encodable in numeric mode.
# To test whether a string s is encodable: ok = NUMERIC_REGEX.fullmatch(s) is not None # To test whether a string s is encodable: ok = NUMERIC_REGEX.fullmatch(s) is not None
# A string is encodable iff each character is in the range 0 to 9. # A string is encodable iff each character is in the range 0 to 9.
NUMERIC_REGEX = re.compile(r"[0-9]*\Z") NUMERIC_REGEX = re.compile(r"[0-9]*")
# (Public) Describes precisely all strings that are encodable in alphanumeric mode. # (Public) Describes precisely all strings that are encodable in alphanumeric mode.
# To test whether a string s is encodable: ok = ALPHANUMERIC_REGEX.fullmatch(s) is not None # To test whether a string s is encodable: ok = ALPHANUMERIC_REGEX.fullmatch(s) is not None
# A string is encodable iff each character is in the following set: 0 to 9, A to Z # A string is encodable iff each character is in the following set: 0 to 9, A to Z
# (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. # (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
ALPHANUMERIC_REGEX = re.compile(r"[A-Z0-9 $%*+./:-]*\Z") ALPHANUMERIC_REGEX = re.compile(r"[A-Z0-9 $%*+./:-]*")
# (Private) Dictionary of "0"->0, "A"->10, "$"->37, etc. # (Private) Dictionary of "0"->0, "A"->10, "$"->37, etc.
_ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")} _ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")}