Chromium Code Reviews| Index: tools/json_schema_compiler/model.py |
| diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py |
| index 967e9abec0041ef9d2d7c7de6378d7abbd7ee1e3..5c1247075ba95517cf34e81e6d2460062ad6b513 100644 |
| --- a/tools/json_schema_compiler/model.py |
| +++ b/tools/json_schema_compiler/model.py |
| @@ -410,6 +410,10 @@ class EnumValue(object): |
| self.name = json |
| self.description = None |
| + |
|
not at google - send to devlin
2014/05/13 23:45:47
only 1 blank line
David Tseng
2014/05/14 02:16:14
Done.
|
| + def CamelName(self): |
| + return SnakeToCamel(self.name) |
| + |
| class _Enum(object): |
| """Superclass for enum types with a "name" field, setting up repr/eq/ne. |
| Enums need to do this so that equality/non-equality work over pickling. |
| @@ -484,6 +488,20 @@ def UnixName(name): |
| return ''.join(unix_name) |
| +def SnakeToCamel(snake): |
|
not at google - send to devlin
2014/05/13 23:45:47
could you write some unit tests? see model_test.py
David Tseng
2014/05/14 02:16:14
Done.
|
| + ''' Converts a snake_cased_string to a camelCasedOne. ''' |
| + camel = [] |
| + i = 0 |
| + while i < len(snake): |
| + if snake[i] == "_" and (i + 1) < len(snake): |
|
not at google - send to devlin
2014/05/13 23:45:47
single quotes
David Tseng
2014/05/14 02:16:14
Done.
|
| + camel.append(snake[i + 1].upper()) |
| + i = i + 2 |
|
not at google - send to devlin
2014/05/13 23:45:47
+= 2
David Tseng
2014/05/14 02:16:14
Done.
|
| + else: |
| + camel.append(snake[i]) |
| + i = i + 1 |
|
not at google - send to devlin
2014/05/13 23:45:47
+= 1
David Tseng
2014/05/14 02:16:14
Done.
|
| + return ''.join(camel) |
|
not at google - send to devlin
2014/05/13 23:45:47
the above said, it might be simpler (and more effi
David Tseng
2014/05/14 02:16:14
Sounds like you'd still end up with some kind of l
not at google - send to devlin
2014/05/14 16:18:14
Actually split is likely to be much faster. Iterat
David Tseng
2014/05/14 18:11:31
Thanks; good to know.
|
| + |
| + |
| def _StripNamespace(name, namespace): |
| if name.startswith(namespace.name + '.'): |
| return name[len(namespace.name + '.'):] |