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 """Utilies for the processing of schema python structures. | 4 """Utilies for the processing of schema python structures. |
| 5 """ | 5 """ |
| 6 | 6 |
| 7 import json_parse | 7 import json_parse |
| 8 | 8 |
| 9 def CapitalizeFirstLetter(value): | 9 def CapitalizeFirstLetter(value): |
| 10 return value[0].capitalize() + value[1:] | 10 return value[0].capitalize() + value[1:] |
| 11 | 11 |
| 12 def GetNamespace(ref_type): | 12 def GetNamespace(ref): |
| 13 if '.' in ref_type: | 13 return SplitNamespace(ref)[0] |
| 14 return ref_type[:ref_type.rindex('.')] | |
| 15 | 14 |
| 16 def StripSchemaNamespace(s): | 15 def StripNamespace(ref): |
| 17 last_dot = s.rfind('.') | 16 return SplitNamespace(ref)[1] |
| 18 if not last_dot == -1: | 17 |
| 19 return s[last_dot + 1:] | 18 def SplitNamespace(ref): |
| 20 return s | 19 """Returns (namespace, thing) from |ref|. If |ref| isn't qualified then |
|
Yoyo Zhou
2013/01/26 01:43:02
Surely there's a better word than 'thing'.
not at google - send to devlin
2013/01/26 04:35:31
probably
| |
| 20 returns (None, ref). | |
| 21 """ | |
| 22 if '.' in ref: | |
| 23 return tuple(ref.rsplit('.', 1)) | |
| 24 return (None, ref) | |
| 21 | 25 |
| 22 def JsFunctionNameToClassName(namespace_name, function_name): | 26 def JsFunctionNameToClassName(namespace_name, function_name): |
| 23 """Transform a fully qualified function name like foo.bar.baz into FooBarBaz | 27 """Transform a fully qualified function name like foo.bar.baz into FooBarBaz |
| 24 | 28 |
| 25 Also strips any leading 'Experimental' prefix.""" | 29 Also strips any leading 'Experimental' prefix.""" |
| 26 parts = [] | 30 parts = [] |
| 27 full_name = namespace_name + "." + function_name | 31 full_name = namespace_name + "." + function_name |
| 28 for part in full_name.split("."): | 32 for part in full_name.split("."): |
| 29 parts.append(CapitalizeFirstLetter(part)) | 33 parts.append(CapitalizeFirstLetter(part)) |
| 30 if parts[0] == "Experimental": | 34 if parts[0] == "Experimental": |
| 31 del parts[0] | 35 del parts[0] |
| 32 class_name = "".join(parts) | 36 class_name = "".join(parts) |
| 33 return class_name | 37 return class_name |
| OLD | NEW |