Skip to content

Commit 2814211

Browse files
maresbWhyNotHugo
authored andcommitted
Improve the name _buffer → _digit_buffer for Code128 charset C
1 parent 1aa5068 commit 2814211

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

barcode/codex.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(self, code: str, writer=None) -> None:
154154
self.code = code
155155
self.writer = writer or self.default_writer()
156156
self._charset = "C"
157-
self._buffer = ""
157+
self._digit_buffer = "" # Accumulate pairs of digits for charset C
158158
check_code(self.code, self.name, code128.ALL)
159159

160160
def __str__(self) -> str:
@@ -204,15 +204,15 @@ def look_next() -> bool:
204204

205205
codes: list[int] = []
206206
if self._charset == "C" and not char.isdigit():
207-
if self._is_char_fnc1_char(char) and not self._buffer:
207+
if self._is_char_fnc1_char(char) and not self._digit_buffer:
208208
return codes
209209
if char in code128.B:
210210
codes = self._new_charset("B")
211211
elif char in code128.A:
212212
codes = self._new_charset("A")
213-
if len(self._buffer) == 1:
214-
codes.append(self._convert(self._buffer[0]))
215-
self._buffer = ""
213+
if len(self._digit_buffer) == 1:
214+
codes.append(self._convert(self._digit_buffer[0]))
215+
self._digit_buffer = ""
216216
elif self._charset == "B":
217217
if look_next():
218218
codes = self._new_charset("C")
@@ -254,13 +254,13 @@ def _convert_or_buffer(self, char: str) -> int | None:
254254
if char in code128.C:
255255
return code128.C[char]
256256
if char.isdigit():
257-
self._buffer += char
258-
if len(self._buffer) == 1:
257+
self._digit_buffer += char
258+
if len(self._digit_buffer) == 1:
259259
# Wait for the second digit to group in pairs
260260
return None
261-
assert len(self._buffer) == 2
262-
value = int(self._buffer)
263-
self._buffer = ""
261+
assert len(self._digit_buffer) == 2
262+
value = int(self._digit_buffer)
263+
self._digit_buffer = ""
264264
return value
265265
raise RuntimeError(f"Character {char} could not be converted in charset C.")
266266

@@ -283,10 +283,10 @@ def _build(self) -> list[int]:
283283
if code_num is not None:
284284
encoded.append(code_num)
285285
# Finally look in the buffer
286-
if len(self._buffer) == 1:
286+
if len(self._digit_buffer) == 1:
287287
encoded.extend(self._new_charset("B"))
288-
encoded.append(self._convert(self._buffer[0]))
289-
self._buffer = ""
288+
encoded.append(self._convert(self._digit_buffer[0]))
289+
self._digit_buffer = ""
290290
return self._try_to_optimize(encoded)
291291

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

0 commit comments

Comments
 (0)