Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1371)

Unified Diff: services/icu_data/embed_icu_data.py

Issue 826093004: Support ICU on Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address review comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/icu_data/embed_icu_data.py
diff --git a/services/icu_data/embed_icu_data.py b/services/icu_data/embed_icu_data.py
new file mode 100755
index 0000000000000000000000000000000000000000..0ffbacee8288d6114b438fd3c87ee3ca65537358
--- /dev/null
+++ b/services/icu_data/embed_icu_data.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import sys
+import hashlib
+
+in_file = sys.argv[1]
+out_file = sys.argv[2]
+
+out_dir = os.path.dirname(out_file)
+
+data = None
+with open(in_file, "rb") as f:
+ data = f.read()
+
+if not os.path.exists(out_dir):
+ os.makedirs(out_dir)
+
+sha1hash = hashlib.sha1(data).hexdigest()
+
+values = ["0x%02x" % ord(c) for c in data]
+lines = []
+chunk_size = 16
+for i in range(0, len(values), chunk_size):
+ lines.append(", ".join(values[i: i + chunk_size]))
+
+with open(out_file, "w") as f:
+ f.write('#include "services/icu_data/data.h"\n')
+ f.write("namespace icu_data {\n")
+ f.write("const char kICUDataTable[] = {\n")
+ f.write(",\n".join(lines))
+ f.write("\n};\n")
+ f.write("const size_t kICUDataTableSize = sizeof(kICUDataTable);\n")
+ f.write("const char kICUDataTableHash[] = \"%s\";\n" % sha1hash)
+ f.write("}\n")

Powered by Google App Engine
This is Rietveld 408576698