diff --git a/src/rmqrcode/encoder/alphanumeric_encoder.py b/src/rmqrcode/encoder/alphanumeric_encoder.py index 2a0839f..3e30746 100644 --- a/src/rmqrcode/encoder/alphanumeric_encoder.py +++ b/src/rmqrcode/encoder/alphanumeric_encoder.py @@ -89,4 +89,4 @@ def characters_num(cls, data): @classmethod def is_valid_characters(cls, data): - return bool(re.match(r"^[0-9A-Z\s\$\%\*\+\-\.\/\:]*$", data)) + return all((char in cls.CHARACTER_MAP.keys() for char in data)) diff --git a/src/rmqrcode/encoder/kanji_encoder.py b/src/rmqrcode/encoder/kanji_encoder.py index ba5fc65..4b8c464 100644 --- a/src/rmqrcode/encoder/kanji_encoder.py +++ b/src/rmqrcode/encoder/kanji_encoder.py @@ -13,9 +13,9 @@ def _encoded_bits(cls, data): shift_jis = c.encode("shift-jis") hex_value = shift_jis[0] * 256 + shift_jis[1] - if hex_value >= 0x8140 and hex_value <= 0x9FFC: + if 0x8140 <= hex_value <= 0x9FFC: sub = 0x8140 - elif hex_value >= 0xE040 and hex_value <= 0xEBBF: + elif 0xE040 <= hex_value <= 0xEBBF: sub = 0xC140 else: raise IllegalCharacterError() @@ -44,6 +44,6 @@ def is_valid_characters(cls, data): if len(shift_jis) < 2: return False hex_value = shift_jis[0] * 256 + shift_jis[1] - if (0x8140 > hex_value and 0x9FFC < hex_value) or (0xE040 > hex_value and 0xEBBF < hex_value): + if hex_value < 0x8140 or 0x9FFC < hex_value < 0xE040 or 0xEBBF < hex_value: return False return True diff --git a/src/rmqrcode/encoder/numeric_encoder.py b/src/rmqrcode/encoder/numeric_encoder.py index 208e7f5..1830300 100644 --- a/src/rmqrcode/encoder/numeric_encoder.py +++ b/src/rmqrcode/encoder/numeric_encoder.py @@ -45,4 +45,4 @@ def characters_num(cls, data): @classmethod def is_valid_characters(cls, data): - return bool(re.match(r"^[0-9]*$", data)) + return all((char in "0123456789" for char in data))