Skip to content

Commit 85acbda

Browse files
maresbWhyNotHugo
authored andcommitted
Add some comments explaining buffer flush
1 parent 2814211 commit 85acbda

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
@@ -210,7 +210,9 @@ def look_next() -> bool:
210210
codes = self._new_charset("B")
211211
elif char in code128.A:
212212
codes = self._new_charset("A")
213+
assert self._charset != "C"
213214
if len(self._digit_buffer) == 1:
215+
# Flush the remaining single digit from the buffer
214216
codes.append(self._convert(self._digit_buffer[0]))
215217
self._digit_buffer = ""
216218
elif self._charset == "B":
@@ -282,7 +284,8 @@ def _build(self) -> list[int]:
282284
code_num = self._convert_or_buffer(char)
283285
if code_num is not None:
284286
encoded.append(code_num)
285-
# Finally look in the buffer
287+
# If we finish in charset C with a single digit remaining in the buffer,
288+
# switch to charset B and flush out the buffer.
286289
if len(self._digit_buffer) == 1:
287290
encoded.extend(self._new_charset("B"))
288291
encoded.append(self._convert(self._digit_buffer[0]))

0 commit comments

Comments
 (0)