File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
33import argparse
4- import re
54from pathlib import Path
65
76
87def normalize_path (value ):
98 return str (value ).strip ().strip ('"' )
109
1110
12- DIRECTIVE_PREFIX = re .compile (r'^\s*\ufeff?#' )
11+ def decode_source (raw ):
12+ for encoding in ('utf-8-sig' , 'utf-16' , 'latin-1' ):
13+ try :
14+ return raw .decode (encoding )
15+ except UnicodeDecodeError :
16+ continue
17+ return raw .decode ('latin-1' , errors = 'replace' )
1318
1419
1520def sanitize_asm (input_path , output_path ):
16- source = Path (normalize_path (input_path )).read_text (encoding = 'utf-8' )
21+ source = decode_source (Path (normalize_path (input_path )).read_bytes ())
22+ source = source .replace ('\x00 ' , '' )
23+
1724 lines = []
1825 for line in source .splitlines (keepends = True ):
19- if DIRECTIVE_PREFIX . match ( line ):
26+ if line . lstrip (). startswith ( '#' ):
2027 continue
2128 lines .append (line )
2229
23- Path (normalize_path (output_path )).write_text ('' .join (lines ), encoding = 'utf-8' )
30+ Path (normalize_path (output_path )).write_text ('' .join (lines ), encoding = 'utf-8' , newline = '' )
2431
2532
2633def main (argv = None ):
You can’t perform that action at this time.
0 commit comments