Skip to content

Commit 0f9c80f

Browse files
committed
Improve the name _buffer → _digit_buffer for Code128 charset C
1 parent 0ebabf5 commit 0f9c80f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

barcode/codex.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(self, code: str, writer=None) -> None:
152152
self.code = code
153153
self.writer = writer or self.default_writer()
154154
self._charset = "B"
155-
self._buffer = ""
155+
self._digit_buffer = "" # Accumulate pairs of digits for charset C
156156
check_code(self.code, self.name, code128.ALL)
157157

158158
def __str__(self) -> str:
@@ -196,9 +196,9 @@ def look_next() -> bool:
196196
codes = self._new_charset("B")
197197
elif char in code128.A:
198198
codes = self._new_charset("A")
199-
if len(self._buffer) == 1:
200-
codes.append(self._convert(self._buffer[0]))
201-
self._buffer = ""
199+
if len(self._digit_buffer) == 1:
200+
codes.append(self._convert(self._digit_buffer[0]))
201+
self._digit_buffer = ""
202202
elif self._charset == "B":
203203
if look_next():
204204
codes = self._new_charset("C")
@@ -240,13 +240,13 @@ def _convert_or_buffer(self, char: str) -> int | None:
240240
if char in code128.C:
241241
return code128.C[char]
242242
if char.isdigit():
243-
self._buffer += char
244-
if len(self._buffer) == 1:
243+
self._digit_buffer += char
244+
if len(self._digit_buffer) == 1:
245245
# Wait for the second digit to group in pairs
246246
return None
247-
assert len(self._buffer) == 2
248-
value = int(self._buffer)
249-
self._buffer = ""
247+
assert len(self._digit_buffer) == 2
248+
value = int(self._digit_buffer)
249+
self._digit_buffer = ""
250250
return value
251251
raise RuntimeError(f"Character {char} could not be converted in charset C.")
252252

@@ -269,10 +269,10 @@ def _build(self) -> list[int]:
269269
if code_num is not None:
270270
encoded.append(code_num)
271271
# Finally look in the buffer
272-
if len(self._buffer) == 1:
272+
if len(self._digit_buffer) == 1:
273273
encoded.extend(self._new_charset("B"))
274-
encoded.append(self._convert(self._buffer[0]))
275-
self._buffer = ""
274+
encoded.append(self._convert(self._digit_buffer[0]))
275+
self._digit_buffer = ""
276276
return self._try_to_optimize(encoded)
277277

278278
def build(self) -> list[str]:

0 commit comments

Comments
 (0)