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 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 """Appends a space to |var| if it ends with a >, so that it can be compiled | 103 """Appends a space to |var| if it ends with a >, so that it can be compiled |
104 within generic types. | 104 within generic types. |
105 """ | 105 """ |
106 return ('%s ' % var) if var.endswith('>') else var | 106 return ('%s ' % var) if var.endswith('>') else var |
107 | 107 |
108 | 108 |
109 def OpenNamespace(namespace): | 109 def OpenNamespace(namespace): |
110 """Get opening root namespace declarations. | 110 """Get opening root namespace declarations. |
111 """ | 111 """ |
112 c = Code() | 112 c = Code() |
| 113 # In lieu of GYP supporting None for the namespace variable the '' namespace |
| 114 # implies there is no root namespace. |
| 115 if namespace == '': |
| 116 return c |
113 for component in namespace.split('::'): | 117 for component in namespace.split('::'): |
114 c.Append('namespace %s {' % component) | 118 c.Append('namespace %s {' % component) |
115 return c | 119 return c |
116 | 120 |
117 | 121 |
118 def CloseNamespace(namespace): | 122 def CloseNamespace(namespace): |
119 """Get closing root namespace declarations. | 123 """Get closing root namespace declarations. |
120 """ | 124 """ |
121 c = Code() | 125 c = Code() |
| 126 # In lieu of GYP supporting None for the namespace variable the '' namespace |
| 127 # implies there is no root namespace. |
| 128 if namespace == '': |
| 129 return c |
122 for component in reversed(namespace.split('::')): | 130 for component in reversed(namespace.split('::')): |
123 c.Append('} // namespace %s' % component) | 131 c.Append('} // namespace %s' % component) |
124 return c | 132 return c |
125 | 133 |
126 | 134 |
127 def ConstantName(feature_name): | 135 def ConstantName(feature_name): |
128 """Returns a kName for a feature's name. | 136 """Returns a kName for a feature's name. |
129 """ | 137 """ |
130 return ('k' + ''.join(word[0].upper() + word[1:] | 138 return ('k' + ''.join(word[0].upper() + word[1:] |
131 for word in feature_name.replace('.', ' ').split())) | 139 for word in feature_name.replace('.', ' ').split())) |
132 | 140 |
133 | 141 |
134 def CamelCase(unix_name): | 142 def CamelCase(unix_name): |
135 return ''.join(word.capitalize() for word in unix_name.split('_')) | 143 return ''.join(word.capitalize() for word in unix_name.split('_')) |
136 | 144 |
137 | 145 |
138 def ClassName(filepath): | 146 def ClassName(filepath): |
139 return CamelCase(os.path.split(filepath)[1]) | 147 return CamelCase(os.path.split(filepath)[1]) |
OLD | NEW |