Skip to content

Commit

Permalink
Add some comments explaining buffer flush
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb committed Jul 31, 2024
1 parent df5fb19 commit e72b03d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion barcode/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def look_next() -> bool:
codes = self._new_charset("B")
elif char in code128.A:
codes = self._new_charset("A")
assert self._charset != "C"
if len(self._digit_buffer) == 1:
# Flush the remaining single digit from the buffer
codes.append(self._convert(self._digit_buffer[0]))
self._digit_buffer = ""
elif self._charset == "B":
Expand Down Expand Up @@ -268,7 +270,8 @@ def _build(self) -> list[int]:
code_num = self._convert_or_buffer(char)
if code_num is not None:
encoded.append(code_num)
# Finally look in the buffer
# If we finish in charset C with a single digit remaining in the buffer,
# switch to charset B and flush out the buffer.
if len(self._digit_buffer) == 1:
encoded.extend(self._new_charset("B"))
encoded.append(self._convert(self._digit_buffer[0]))
Expand Down

0 comments on commit e72b03d

Please sign in to comment.