Merge branch 'fix-data-to-c-line-endings' into 'master'

data-to-c.py: autodetect line endings

Closes #2340

See merge request GNOME/glib!1974
This commit is contained in:
Philip Withnall 2021-03-18 14:00:05 +00:00
commit bdea78295c

View File

@ -1,12 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
if len(sys.argv) < 4:
print("Usage: {0} <filename> <variable> <output>")
with open(sys.argv[1], "rb") as f:
in_data = f.read().decode("utf-8", "backslashreplace")
with open(sys.argv[1], "r", encoding="utf-8", errors="backslashreplace") as f:
in_data = f.read()
b = [r"\x{:02x}".format(ord(c)) for c in in_data]
out_data = 'const char {0}[] = "'.format(sys.argv[2])