From 0f9c80fd6b543725303173eac93561aeeb85d905 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Tue, 9 Jul 2024 00:22:36 +0200 Subject: [PATCH] =?UTF-8?q?Improve=20the=20name=20=5Fbuffer=20=E2=86=92=20?= =?UTF-8?q?=5Fdigit=5Fbuffer=20for=20Code128=20charset=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- barcode/codex.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/barcode/codex.py b/barcode/codex.py index b18fe8b..bd4b803 100755 --- a/barcode/codex.py +++ b/barcode/codex.py @@ -152,7 +152,7 @@ def __init__(self, code: str, writer=None) -> None: self.code = code self.writer = writer or self.default_writer() self._charset = "B" - self._buffer = "" + self._digit_buffer = "" # Accumulate pairs of digits for charset C check_code(self.code, self.name, code128.ALL) def __str__(self) -> str: @@ -196,9 +196,9 @@ def look_next() -> bool: codes = self._new_charset("B") elif char in code128.A: codes = self._new_charset("A") - if len(self._buffer) == 1: - codes.append(self._convert(self._buffer[0])) - self._buffer = "" + if len(self._digit_buffer) == 1: + codes.append(self._convert(self._digit_buffer[0])) + self._digit_buffer = "" elif self._charset == "B": if look_next(): codes = self._new_charset("C") @@ -240,13 +240,13 @@ def _convert_or_buffer(self, char: str) -> int | None: if char in code128.C: return code128.C[char] if char.isdigit(): - self._buffer += char - if len(self._buffer) == 1: + self._digit_buffer += char + if len(self._digit_buffer) == 1: # Wait for the second digit to group in pairs return None - assert len(self._buffer) == 2 - value = int(self._buffer) - self._buffer = "" + assert len(self._digit_buffer) == 2 + value = int(self._digit_buffer) + self._digit_buffer = "" return value raise RuntimeError(f"Character {char} could not be converted in charset C.") @@ -269,10 +269,10 @@ def _build(self) -> list[int]: if code_num is not None: encoded.append(code_num) # Finally look in the buffer - if len(self._buffer) == 1: + if len(self._digit_buffer) == 1: encoded.extend(self._new_charset("B")) - encoded.append(self._convert(self._buffer[0])) - self._buffer = "" + encoded.append(self._convert(self._digit_buffer[0])) + self._digit_buffer = "" return self._try_to_optimize(encoded) def build(self) -> list[str]: