Skip to content

Commit e72b03d

Browse files
committed
Add some comments explaining buffer flush
1 parent df5fb19 commit e72b03d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

barcode/codex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +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+
assert self._charset != "C"
199200
if len(self._digit_buffer) == 1:
201+
# Flush the remaining single digit from the buffer
200202
codes.append(self._convert(self._digit_buffer[0]))
201203
self._digit_buffer = ""
202204
elif self._charset == "B":
@@ -268,7 +270,8 @@ def _build(self) -> list[int]:
268270
code_num = self._convert_or_buffer(char)
269271
if code_num is not None:
270272
encoded.append(code_num)
271-
# Finally look in the buffer
273+
# If we finish in charset C with a single digit remaining in the buffer,
274+
# switch to charset B and flush out the buffer.
272275
if len(self._digit_buffer) == 1:
273276
encoded.extend(self._new_charset("B"))
274277
encoded.append(self._convert(self._digit_buffer[0]))

0 commit comments

Comments
 (0)