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

Unified Diff: build/escape_unicode.py

Issue 7891020: Make autofill regular expressions unicode again. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove extra gyp change Created 9 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/autofill/address_field.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/escape_unicode.py
diff --git a/build/escape_unicode.py b/build/escape_unicode.py
new file mode 100755
index 0000000000000000000000000000000000000000..5d4410eef7bc92852de4a9893d6d860c5807a51c
--- /dev/null
+++ b/build/escape_unicode.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+# Copyright (c) 2011 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.
+
+"""Convert any unicode characters found in the input file to C literals."""
+
+import codecs
+import optparse
+import os
+import sys
+
+def main(argv):
+ parser = optparse.OptionParser()
+ usage = 'Usage: %prog -o <output_dir> <input_file>'
+ parser.set_usage(usage)
+ parser.add_option('-o', dest='output_dir')
+
+ options, arglist = parser.parse_args(argv)
+
+ if not options.output_dir:
+ print "output_dir required"
+ return 1
+
+ if len(arglist) != 2:
+ print "input_file required"
+ return 1
+
+ in_filename = arglist[1]
+
+ if not in_filename.endswith('.utf8'):
+ print "input_file should end in .utf8"
+ return 1
+
+ out_filename = os.path.join(options.output_dir, os.path.basename(
+ os.path.splitext(in_filename)[0]))
+
+ WriteEscapedFile(in_filename, out_filename)
+
+
+def WriteEscapedFile(in_filename, out_filename):
+ input_data = codecs.open(in_filename, 'r', 'utf8').read()
+ with codecs.open(out_filename, 'w', 'ascii') as out_file:
+ for i, char in enumerate(input_data):
+ if ord(char) > 127:
+ out_file.write(repr(char.encode('utf8'))[1:-1])
+ if input_data[i + 1:i + 2] in '0123456789abcdefABCDEF':
+ out_file.write('""')
+ else:
+ out_file.write(char.encode('ascii'))
+
+
+if __name__ == '__main__':
+ exit(main(sys.argv))
« no previous file with comments | « no previous file | chrome/browser/autofill/address_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698