Skip to content

Commit bdb9f2e

Browse files
committed
Add some comments explaining buffer flush
1 parent 4e59fdd commit bdb9f2e

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
@@ -184,7 +184,9 @@ def look_next():
184184
codes = self._new_charset("B")
185185
elif char in code128.A:
186186
codes = self._new_charset("A")
187+
assert self._charset != "C"
187188
if len(self._digit_buffer) == 1:
189+
# Flush the remaining single digit from the buffer
188190
codes.append(self._convert(self._digit_buffer[0]))
189191
self._digit_buffer = ""
190192
elif self._charset == "B":
@@ -256,7 +258,8 @@ def _build(self):
256258
code_num = self._convert_or_buffer(char)
257259
if code_num is not None:
258260
encoded.append(code_num)
259-
# Finally look in the buffer
261+
# If we finish in charset C with a single digit remaining in the buffer,
262+
# switch to charset B and flush out the buffer.
260263
if len(self._digit_buffer) == 1:
261264
encoded.extend(self._new_charset("B"))
262265
encoded.append(self._convert(self._digit_buffer[0]))

0 commit comments

Comments
 (0)