Construct an initializer for a C array variable. Components are C expressions valid in an initializer. For example, if components are ["1", "2"], the result would be "{1, 2}", which can be used like this: int a[] = {1, 2}; If the result is long, split it into multiple lin
(components: list[str], *, indented: bool = False)
| 1449 | |
| 1450 | |
| 1451 | def c_array_initializer(components: list[str], *, indented: bool = False) -> str: |
| 1452 | """Construct an initializer for a C array variable. |
| 1453 | |
| 1454 | Components are C expressions valid in an initializer. |
| 1455 | |
| 1456 | For example, if components are ["1", "2"], the result |
| 1457 | would be "{1, 2}", which can be used like this: |
| 1458 | |
| 1459 | int a[] = {1, 2}; |
| 1460 | |
| 1461 | If the result is long, split it into multiple lines. |
| 1462 | """ |
| 1463 | indent = " " * 4 if indented else "" |
| 1464 | res = [] |
| 1465 | current: list[str] = [] |
| 1466 | cur_len = 0 |
| 1467 | for c in components: |
| 1468 | if not current or cur_len + 2 + len(indent) + len(c) < 70: |
| 1469 | current.append(c) |
| 1470 | cur_len += len(c) + 2 |
| 1471 | else: |
| 1472 | res.append(indent + ", ".join(current)) |
| 1473 | current = [c] |
| 1474 | cur_len = len(c) |
| 1475 | if not res: |
| 1476 | # Result fits on a single line |
| 1477 | return "{%s}" % ", ".join(current) |
| 1478 | # Multi-line result |
| 1479 | res.append(indent + ", ".join(current)) |
| 1480 | return "{\n " + ",\n ".join(res) + "\n" + indent + "}" |
| 1481 | |
| 1482 | |
| 1483 | def native_function_doc_initializer(func: FuncIR) -> str: |
no test coverage detected
searching dependent graphs…