bin2v: replace hyphens for const names (#7937)
parent
653121bad9
commit
2820139216
|
@ -74,11 +74,9 @@ fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string {
|
||||||
|
|
||||||
fn (context Context) bname_and_bytes(file string) ?(string, []byte) {
|
fn (context Context) bname_and_bytes(file string) ?(string, []byte) {
|
||||||
fname := os.file_name(file)
|
fname := os.file_name(file)
|
||||||
fname_no_dots := fname.replace('.', '_')
|
fname_escpaed := fname.replace_each(['.', '_', '-', '_'])
|
||||||
byte_name := '$context.prefix$fname_no_dots'.to_lower()
|
byte_name := '$context.prefix$fname_escpaed'.to_lower()
|
||||||
fbytes := os.read_bytes(file) or {
|
fbytes := os.read_bytes(file) or { return error('Error: $err') }
|
||||||
return error('Error: $err')
|
|
||||||
}
|
|
||||||
return byte_name, fbytes
|
return byte_name, fbytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,9 +129,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
max_bname := context.max_bname_len(file_byte_map.keys())
|
max_bname := context.max_bname_len(file_byte_map.keys())
|
||||||
if context.write_file.len > 0 {
|
if context.write_file.len > 0 {
|
||||||
mut out_file := os.create(context.write_file) or {
|
mut out_file := os.create(context.write_file) or { panic(err) }
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
out_file.write_str(context.header())
|
out_file.write_str(context.header())
|
||||||
for bname, fbytes in file_byte_map {
|
for bname, fbytes in file_byte_map {
|
||||||
out_file.write_str(context.file2v(bname, fbytes, max_bname))
|
out_file.write_str(context.file2v(bname, fbytes, max_bname))
|
||||||
|
|
Loading…
Reference in New Issue