OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Utilies and constants specific to Chromium C++ code. | 5 """Utilies and constants specific to Chromium C++ code. |
6 """ | 6 """ |
7 | 7 |
8 from code import Code | 8 from code import Code |
9 from datetime import datetime | 9 from datetime import datetime |
10 from model import PropertyType | 10 from model import PropertyType |
11 import os | 11 import os |
12 import re | 12 import re |
13 | 13 |
14 CHROMIUM_LICENSE = ( | 14 CHROMIUM_LICENSE = ( |
15 """// Copyright (c) %d The Chromium Authors. All rights reserved. | 15 """// Copyright (c) %d The Chromium Authors. All rights reserved. |
16 // Use of this source code is governed by a BSD-style license that can be | 16 // Use of this source code is governed by a BSD-style license that can be |
17 // found in the LICENSE file.""" % datetime.now().year | 17 // found in the LICENSE file.""" % datetime.now().year |
18 ) | 18 ) |
19 GENERATED_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITION IN | 19 GENERATED_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITION IN |
20 // %s | 20 // %s |
21 // DO NOT EDIT. | 21 // DO NOT EDIT. |
22 """ | 22 """ |
23 GENERATED_BUNDLE_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITIONS IN | 23 GENERATED_BUNDLE_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITIONS IN |
24 // %s | 24 // %s |
25 // DO NOT EDIT. | 25 // DO NOT EDIT. |
26 """ | 26 """ |
27 GENERATED_FEATURE_MESSAGE = """// GENERATED FROM THE FEATURE DEFINITIONS IN | |
28 // %s | |
29 // DO NOT EDIT. | |
30 """ | |
31 | 27 |
32 def Classname(s): | 28 def Classname(s): |
33 """Translates a namespace name or function name into something more | 29 """Translates a namespace name or function name into something more |
34 suited to C++. | 30 suited to C++. |
35 | 31 |
36 eg experimental.downloads -> Experimental_Downloads | 32 eg experimental.downloads -> Experimental_Downloads |
37 updateAll -> UpdateAll. | 33 updateAll -> UpdateAll. |
38 """ | 34 """ |
39 return '_'.join([x[0].upper() + x[1:] for x in re.split('\W', s)]) | 35 return '_'.join([x[0].upper() + x[1:] for x in re.split('\W', s)]) |
40 | 36 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return c | 111 return c |
116 | 112 |
117 | 113 |
118 def CloseNamespace(namespace): | 114 def CloseNamespace(namespace): |
119 """Get closing root namespace declarations. | 115 """Get closing root namespace declarations. |
120 """ | 116 """ |
121 c = Code() | 117 c = Code() |
122 for component in reversed(namespace.split('::')): | 118 for component in reversed(namespace.split('::')): |
123 c.Append('} // namespace %s' % component) | 119 c.Append('} // namespace %s' % component) |
124 return c | 120 return c |
125 | |
126 | |
127 def ConstantName(feature_name): | |
128 """Returns a kName for a feature's name. | |
129 """ | |
130 return ('k' + ''.join(word[0].upper() + word[1:] | |
131 for word in feature_name.replace('.', ' ').split())) | |
132 | |
133 | |
134 def CamelCase(unix_name): | |
135 return ''.join(word.capitalize() for word in unix_name.split('_')) | |
136 | |
137 | |
138 def ClassName(filepath): | |
139 return CamelCase(os.path.split(filepath)[1]) | |
OLD | NEW |