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

Unified Diff: runtime/tools/create_string_literal.py

Issue 9348112: Make gen files more human-readable by using a string initializer (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 | « runtime/bin/io_in.cc ('k') | runtime/vm/corelib_impl_in.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/tools/create_string_literal.py
===================================================================
--- runtime/tools/create_string_literal.py (revision 4233)
+++ runtime/tools/create_string_literal.py (working copy)
@@ -13,21 +13,32 @@
def makeString(input_files):
+ printable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\
+!#$%&'()*+,-./:;<=>?@[]^_`{|}~ "
result = ' '
+ lineNumber = 1
for string_file in input_files:
if string_file.endswith('dart'):
fileHandle = open(string_file, 'rb')
- lineCounter = 0
- result += ' // ' + string_file + '\n '
+ quoted = False
+ result += '\n // ----- ' + string_file + ' -----\n\n'
for byte in fileHandle.read():
- result += ' %d,' % ord(byte)
- lineCounter += 1
- if lineCounter == 10:
- result += '\n '
- lineCounter = 0
- if lineCounter != 0:
- result += '\n '
- result += ' // Terminating null character.\n 0'
+ if not quoted:
+ result += ' "'
+ quoted = True
+ if byte in printable:
+ result += byte
+ elif byte == '\n':
+ if lineNumber % 10 == 0:
+ result += '\\n" /* L%d */\n' % lineNumber
+ else:
+ result += '\\n"\n'
+ lineNumber += 1
+ quoted = False
+ elif byte == '\"':
+ result += '\\"'
+ else:
+ result += '\\x%02x' % ord(byte)
return result
« no previous file with comments | « runtime/bin/io_in.cc ('k') | runtime/vm/corelib_impl_in.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698