MCPcopy Index your code
hub / github.com/WhyNotHugo/python-barcode / _maybe_switch_charset

Method _maybe_switch_charset

barcode/codex.py:189–223  ·  view source on GitHub ↗
(self, pos: int)

Source from the content-addressed store, hash-verified

187 return False
188
189 def _maybe_switch_charset(self, pos: int) -> list[int]:
190 char = self.code[pos]
191 next_ = self.code[pos : pos + 10]
192
193 def look_next() -> bool:
194 digits = 0
195 for c in next_:
196 if c.isdigit():
197 digits += 1
198 else:
199 break
200 return digits > 3
201
202 codes: list[int] = []
203 if self._charset == "C" and not char.isdigit():
204 if self._is_char_fnc1_char(char) and not self._buffer:
205 return codes
206 if char in code128.B:
207 codes = self._new_charset("B")
208 elif char in code128.A:
209 codes = self._new_charset("A")
210 if len(self._buffer) == 1:
211 codes.append(self._convert(self._buffer[0]))
212 self._buffer = ""
213 elif self._charset == "B":
214 if look_next():
215 codes = self._new_charset("C")
216 elif char not in code128.B and char in code128.A:
217 codes = self._new_charset("A")
218 elif self._charset == "A":
219 if look_next():
220 codes = self._new_charset("C")
221 elif char not in code128.A and char in code128.B:
222 codes = self._new_charset("B")
223 return codes
224
225 def _convert(self, char: str):
226 if self._charset == "A":

Callers 1

_buildMethod · 0.95

Calls 3

_is_char_fnc1_charMethod · 0.95
_new_charsetMethod · 0.95
_convertMethod · 0.95

Tested by

no test coverage detected