File: process.py

package info (click to toggle)
basis-universal 2.0.2-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 216,436 kB
  • sloc: cpp: 163,224; ansic: 51,368; python: 2,824; javascript: 2,637; lisp: 1,026; sh: 161; makefile: 17
file content (12 lines) | stat: -rw-r--r-- 388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
# convert_to_c_string.py
def to_c_string(path):
    with open(path, "r", encoding="utf-8") as f:
        text = f.read()
    # escape backslashes and quotes
    text = text.replace("\\", "\\\\").replace("\"", "\\\"")
    # replace newlines with \n
    text = text.replace("\n", "\\n\"\n\"")
    return "\"" + text + "\""

if __name__ == "__main__":
    print(to_c_string("cmd_help.txt"))