Merge the list of literals and the list of substitutions alternatively using 'bytes_build_op'.
(
builder: IRBuilder, literals: list[str], substitutions: list[Value], line: int
)
| 237 | |
| 238 | |
| 239 | def join_formatted_bytes( |
| 240 | builder: IRBuilder, literals: list[str], substitutions: list[Value], line: int |
| 241 | ) -> Value: |
| 242 | """Merge the list of literals and the list of substitutions |
| 243 | alternatively using 'bytes_build_op'.""" |
| 244 | result_list: list[Value] = [Integer(0, c_pyssize_t_rprimitive)] |
| 245 | |
| 246 | for a, b in zip(literals, substitutions): |
| 247 | if a: |
| 248 | result_list.append(builder.load_bytes_from_str_literal(a)) |
| 249 | result_list.append(b) |
| 250 | if literals[-1]: |
| 251 | result_list.append(builder.load_bytes_from_str_literal(literals[-1])) |
| 252 | |
| 253 | # Special case for empty bytes and literal |
| 254 | if len(result_list) == 1: |
| 255 | return builder.load_bytes_from_str_literal("") |
| 256 | if not substitutions and len(result_list) == 2: |
| 257 | return result_list[1] |
| 258 | |
| 259 | result_list[0] = Integer(len(result_list) - 1, c_pyssize_t_rprimitive) |
| 260 | return builder.call_c(bytes_build_op, result_list, line) |
no test coverage detected
searching dependent graphs…