MCPcopy Index your code
hub / github.com/RustPython/RustPython / PyUnicode_DecodeUTF16Stateful

Function PyUnicode_DecodeUTF16Stateful

Lib/_pycodecs.py:1180–1296  ·  view source on GitHub ↗
(s, size, errors, byteorder="native", final=True)

Source from the content-addressed store, hash-verified

1178
1179
1180def PyUnicode_DecodeUTF16Stateful(s, size, errors, byteorder="native", final=True):
1181 bo = 0 # /* assume native ordering by default */
1182 consumed = 0
1183 errmsg = ""
1184
1185 if sys.byteorder == "little":
1186 ihi = 1
1187 ilo = 0
1188 else:
1189 ihi = 0
1190 ilo = 1
1191
1192 # /* Unpack UTF-16 encoded data */
1193
1194 ## /* Check for BOM marks (U+FEFF) in the input and adjust current
1195 ## byte order setting accordingly. In native mode, the leading BOM
1196 ## mark is skipped, in all other modes, it is copied to the output
1197 ## stream as-is (giving a ZWNBSP character). */
1198 q = 0
1199 p = []
1200 if byteorder == "native":
1201 if size >= 2:
1202 bom = (s[ihi] << 8) | s[ilo]
1203 # ifdef BYTEORDER_IS_LITTLE_ENDIAN
1204 if sys.byteorder == "little":
1205 if bom == 0xFEFF:
1206 q += 2
1207 bo = -1
1208 elif bom == 0xFFFE:
1209 q += 2
1210 bo = 1
1211 else:
1212 if bom == 0xFEFF:
1213 q += 2
1214 bo = 1
1215 elif bom == 0xFFFE:
1216 q += 2
1217 bo = -1
1218 elif byteorder == "little":
1219 bo = -1
1220 else:
1221 bo = 1
1222
1223 if size == 0:
1224 return [""], 0, bo
1225
1226 if bo == -1:
1227 # /* force LE */
1228 ihi = 1
1229 ilo = 0
1230
1231 elif bo == 1:
1232 # /* force BE */
1233 ihi = 0
1234 ilo = 1
1235
1236 while q < len(s):
1237 # /* remaining bytes at the end? (size should be even) */

Callers 4

utf_16_decodeFunction · 0.85
utf_16_ex_decodeFunction · 0.85
utf_16_le_decodeFunction · 0.85
utf_16_be_decodeFunction · 0.85

Calls 4

lenFunction · 0.85
chrFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected