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

Side by Side Diff: grit/format/c_format.py

Issue 1413193006: Write newlines at the end of C files. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Formats as a .C file for compilation. 6 """Formats as a .C file for compilation.
7 """ 7 """
8 8
9 import os 9 import os
10 import re 10 import re
(...skipping 27 matching lines...) Expand all
38 38
39 yield _FormatHeader(root, output_dir) 39 yield _FormatHeader(root, output_dir)
40 40
41 yield 'const char* GetString(int id) {\n switch (id) {' 41 yield 'const char* GetString(int id) {\n switch (id) {'
42 42
43 for item in root.ActiveDescendants(): 43 for item in root.ActiveDescendants():
44 with item: 44 with item:
45 if isinstance(item, message.MessageNode): 45 if isinstance(item, message.MessageNode):
46 yield _FormatMessage(item, lang) 46 yield _FormatMessage(item, lang)
47 47
48 yield '\n default:\n return 0;\n }\n}' 48 yield '\n default:\n return 0;\n }\n}\n'
49 49
50 50
51 def _HexToOct(match): 51 def _HexToOct(match):
52 "Return the octal form of the hex numbers" 52 "Return the octal form of the hex numbers"
53 hex = match.group("hex") 53 hex = match.group("hex")
54 result = "" 54 result = ""
55 while len(hex): 55 while len(hex):
56 next_num = int(hex[2:4], 16) 56 next_num = int(hex[2:4], 16)
57 result += "\\" + '%03d' % int(oct(next_num), 10) 57 result += "\\" + '%03d' % int(oct(next_num), 10)
58 hex = hex[4:] 58 hex = hex[4:]
(...skipping 18 matching lines...) Expand all
77 % (escaped_backslashes, hex_digits)) 77 % (escaped_backslashes, hex_digits))
78 message = two_digit_hex_num.sub(_HexToOct, message) 78 message = two_digit_hex_num.sub(_HexToOct, message)
79 # unescape \ (convert \\ back to \) 79 # unescape \ (convert \\ back to \)
80 message = message.replace('\\\\', '\\') 80 message = message.replace('\\\\', '\\')
81 message = message.replace('"', '\\"') 81 message = message.replace('"', '\\"')
82 message = util.LINEBREAKS.sub(r'\\n', message) 82 message = util.LINEBREAKS.sub(r'\\n', message)
83 83
84 name_attr = item.GetTextualIds()[0] 84 name_attr = item.GetTextualIds()[0]
85 85
86 return '\n case %s:\n return "%s";' % (name_attr, message) 86 return '\n case %s:\n return "%s";' % (name_attr, message)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698