Chromium Code Reviews| 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 datetime import datetime | 8 from datetime import datetime |
| 9 from model import Property, PropertyType, Type | 9 from model import Property, PropertyType, Type |
| 10 import os | 10 import os |
| 11 import re | |
| 11 | 12 |
| 12 CHROMIUM_LICENSE = ( | 13 CHROMIUM_LICENSE = ( |
| 13 """// Copyright (c) %d The Chromium Authors. All rights reserved. | 14 """// Copyright (c) %d The Chromium Authors. All rights reserved. |
| 14 // Use of this source code is governed by a BSD-style license that can be | 15 // Use of this source code is governed by a BSD-style license that can be |
| 15 // found in the LICENSE file.""" % datetime.now().year | 16 // found in the LICENSE file.""" % datetime.now().year |
| 16 ) | 17 ) |
| 17 GENERATED_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITION IN | 18 GENERATED_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITION IN |
| 18 // %s | 19 // %s |
| 19 // DO NOT EDIT. | 20 // DO NOT EDIT. |
| 20 """ | 21 """ |
| 21 GENERATED_BUNDLE_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITIONS IN | 22 GENERATED_BUNDLE_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITIONS IN |
| 22 // %s | 23 // %s |
| 23 // DO NOT EDIT. | 24 // DO NOT EDIT. |
| 24 """ | 25 """ |
| 25 | 26 |
| 26 def Classname(s): | 27 def Classname(s): |
| 27 """Translates a namespace name or function name into something more | 28 """Translates a namespace name or function name into something more |
| 28 suited to C++. | 29 suited to C++. |
| 29 | 30 |
| 30 eg experimental.downloads -> Experimental_Downloads | 31 eg experimental.downloads -> Experimental_Downloads |
| 31 updateAll -> UpdateAll. | 32 updateAll -> UpdateAll. |
| 32 """ | 33 """ |
| 33 return '_'.join([x[0].upper() + x[1:] for x in s.split('.')]) | 34 new_s = re.sub(r'[^a-zA-Z0-9]', '.',s) |
| 35 return '_'.join([x[0].upper() + x[1:] for x in re.split('\.', new_s)]) | |
|
Yoyo Zhou
2013/02/05 23:42:13
No, the point of using re.split is that you don't
SanjoyPal
2013/02/06 00:47:21
Done.
| |
| 34 | 36 |
| 35 def GetAsFundamentalValue(type_, src, dst): | 37 def GetAsFundamentalValue(type_, src, dst): |
| 36 """Returns the C++ code for retrieving a fundamental type from a | 38 """Returns the C++ code for retrieving a fundamental type from a |
| 37 Value into a variable. | 39 Value into a variable. |
| 38 | 40 |
| 39 src: Value* | 41 src: Value* |
| 40 dst: Property* | 42 dst: Property* |
| 41 """ | 43 """ |
| 42 return { | 44 return { |
| 43 PropertyType.STRING: '%s->GetAsString(%s)', | 45 PropertyType.STRING: '%s->GetAsString(%s)', |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. | 86 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. |
| 85 """ | 87 """ |
| 86 return (('%s_%s_H__' % (path, filename)) | 88 return (('%s_%s_H__' % (path, filename)) |
| 87 .upper().replace(os.sep, '_').replace('/', '_')) | 89 .upper().replace(os.sep, '_').replace('/', '_')) |
| 88 | 90 |
| 89 def PadForGenerics(var): | 91 def PadForGenerics(var): |
| 90 """Appends a space to |var| if it ends with a >, so that it can be compiled | 92 """Appends a space to |var| if it ends with a >, so that it can be compiled |
| 91 within generic types. | 93 within generic types. |
| 92 """ | 94 """ |
| 93 return ('%s ' % var) if var.endswith('>') else var | 95 return ('%s ' % var) if var.endswith('>') else var |
| OLD | NEW |