Make a 'C' string.
(string: Union[str, bytes])
| 679 | |
| 680 | |
| 681 | def _make_c_string(string: Union[str, bytes]) -> bytes: |
| 682 | """Make a 'C' string.""" |
| 683 | if isinstance(string, bytes): |
| 684 | try: |
| 685 | _utf_8_decode(string, None, True) |
| 686 | return string + b"\x00" |
| 687 | except UnicodeError: |
| 688 | raise InvalidStringData( |
| 689 | "strings in documents must be valid UTF-8: %r" % string |
| 690 | ) from None |
| 691 | else: |
| 692 | return _utf_8_encode(string)[0] + b"\x00" |
| 693 | |
| 694 | |
| 695 | def _make_name(string: str) -> bytes: |
no test coverage detected