bin2v: replace hyphens for const names (#7937)

pull/7952/head
Lukas Neubert 2021-01-07 21:37:36 +01:00 committed by GitHub
parent 653121bad9
commit 2820139216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 8 deletions

View File

@ -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) {
fname := os.file_name(file)
fname_no_dots := fname.replace('.', '_')
byte_name := '$context.prefix$fname_no_dots'.to_lower()
fbytes := os.read_bytes(file) or {
return error('Error: $err')
}
fname_escpaed := fname.replace_each(['.', '_', '-', '_'])
byte_name := '$context.prefix$fname_escpaed'.to_lower()
fbytes := os.read_bytes(file) or { return error('Error: $err') }
return byte_name, fbytes
}
@ -131,9 +129,7 @@ fn main() {
}
max_bname := context.max_bname_len(file_byte_map.keys())
if context.write_file.len > 0 {
mut out_file := os.create(context.write_file) or {
panic(err)
}
mut out_file := os.create(context.write_file) or { panic(err) }
out_file.write_str(context.header())
for bname, fbytes in file_byte_map {
out_file.write_str(context.file2v(bname, fbytes, max_bname))