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 9, 2024
1 parent 4e59fdd commit bdb9f2e
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 @@ -184,7 +184,9 @@ def look_next():
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 @@ -256,7 +258,8 @@ def _build(self):
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 bdb9f2e

Please sign in to comment.