From e72b03d6a05808f830d8bd8bc0d3ed4b3f9312c0 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Tue, 9 Jul 2024 16:36:38 +0200 Subject: [PATCH] Add some comments explaining buffer flush --- barcode/codex.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/barcode/codex.py b/barcode/codex.py index bd4b803..165fc4b 100755 --- a/barcode/codex.py +++ b/barcode/codex.py @@ -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": @@ -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]))