mirror of
https://github.com/openharmony/third_party_rust_encoding_rs.git
synced 2026-07-21 02:05:23 -04:00
Make generate-encoding-data.py write to lib.rs.
This commit is contained in:
+22
-12
@@ -109,18 +109,29 @@ def is_single_byte(name):
|
||||
return True
|
||||
return False
|
||||
|
||||
label_file = open("src/labels.rs", "w")
|
||||
label_file = open("src/lib.rs", "r")
|
||||
lib_rs_full = label_file.read()
|
||||
label_file.close()
|
||||
|
||||
label_file.write("""// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
generated_begin = "// BEGIN GENERATED CODE. PLEASE DO NOT EDIT."
|
||||
generated_end = "// END GENERATED CODE"
|
||||
|
||||
// BEGIN GENERATED CODE. PLEASE DO NOT EDIT.
|
||||
generated_begin_index = lib_rs_full.find(generated_begin)
|
||||
if generated_begin_index < 0:
|
||||
print "Can't find generated code start marker in lib.rs. Exiting."
|
||||
sys.exit(-1)
|
||||
generated_end_index = lib_rs_full.find(generated_end)
|
||||
if generated_end_index < 0:
|
||||
print "Can't find generated code end marker in lib.rs. Exiting."
|
||||
sys.exit(-1)
|
||||
|
||||
lib_rs_begin = lib_rs_full[0:generated_begin_index + len(generated_begin)]
|
||||
lib_rs_end = lib_rs_full[generated_end_index:]
|
||||
|
||||
label_file = open("src/lib.rs", "w")
|
||||
|
||||
label_file.write(lib_rs_begin)
|
||||
label_file.write("""
|
||||
// Instead, please regenerate using generate-encoding-data.py
|
||||
|
||||
const LONGEST_LABEL_LENGTH: usize = %d; // %s
|
||||
@@ -167,9 +178,8 @@ for label in labels:
|
||||
|
||||
label_file.write('''];
|
||||
|
||||
// END GENERATED CODE
|
||||
''')
|
||||
|
||||
label_file.write(lib_rs_end)
|
||||
label_file.close()
|
||||
|
||||
def null_to_zero(code_point):
|
||||
|
||||
Reference in New Issue
Block a user