OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import os |
| 7 import sys |
| 8 import hashlib |
| 9 |
| 10 in_file = sys.argv[1] |
| 11 out_file = sys.argv[2] |
| 12 |
| 13 out_dir = os.path.dirname(out_file) |
| 14 |
| 15 data = None |
| 16 with open(in_file, "rb") as f: |
| 17 data = f.read() |
| 18 |
| 19 if not os.path.exists(out_dir): |
| 20 os.makedirs(out_dir) |
| 21 |
| 22 sha1hash = hashlib.sha1(data).hexdigest() |
| 23 |
| 24 values = ["0x%02x" % ord(c) for c in data] |
| 25 lines = [] |
| 26 chunk_size = 16 |
| 27 for i in range(0, len(values), chunk_size): |
| 28 lines.append(", ".join(values[i: i + chunk_size])) |
| 29 |
| 30 with open(out_file, "w") as f: |
| 31 f.write('#include "services/icu_data/data.h"\n') |
| 32 f.write("namespace icu_data {\n") |
| 33 f.write("const char kICUDataTable[] = {\n") |
| 34 f.write(",\n".join(lines)) |
| 35 f.write("\n};\n") |
| 36 f.write("const size_t kICUDataTableSize = sizeof(kICUDataTable);\n") |
| 37 f.write("const char kICUDataTableHash[] = \"%s\";\n" % sha1hash) |
| 38 f.write("}\n") |
OLD | NEW |