summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/json_schema_compiler/model.py11
-rwxr-xr-xtools/json_schema_compiler/model_test.py16
-rw-r--r--tools/json_schema_compiler/schema_bundle_generator.py3
3 files changed, 24 insertions, 6 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 96b2a59..07ead3d 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -2,9 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import copy
import os.path
import re
-import copy
class Model(object):
"""Model of all namespaces that comprise an API.
@@ -306,9 +306,12 @@ class PropertyType(object):
def UnixName(name):
"""Returns the unix_style name for a given lowerCamelCase string.
"""
- name = name.replace('.', '_')
- return '_'.join([x.lower()
- for x in re.findall('[A-Z][a-z_]*', name[0].upper() + name[1:])])
+ # First replace any lowerUpper patterns with lower_Upper.
+ s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name)
+ # Now replace any ACMEWidgets patterns with ACME_Widgets
+ s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1)
+ # Finally, replace any remaining periods, and make lowercase.
+ return s2.replace('.', '_').lower()
class ParseException(Exception):
"""Thrown when data in the model is invalid."""
diff --git a/tools/json_schema_compiler/model_test.py b/tools/json_schema_compiler/model_test.py
index 69062bd..d91acb5 100755
--- a/tools/json_schema_compiler/model_test.py
+++ b/tools/json_schema_compiler/model_test.py
@@ -102,5 +102,21 @@ class ModelTest(unittest.TestCase):
self.assertRaises(AttributeError,
param.choices[model.PropertyType.INTEGER].SetUnixName, 'breakage')
+ def testUnixName(self):
+ expectations = {
+ 'foo': 'foo',
+ 'fooBar': 'foo_bar',
+ 'fooBarBaz': 'foo_bar_baz',
+ 'fooBARBaz': 'foo_bar_baz',
+ 'fooBAR': 'foo_bar',
+ 'FOO': 'foo',
+ 'FOOBar': 'foo_bar',
+ 'foo.bar': 'foo_bar',
+ 'foo.BAR': 'foo_bar',
+ 'foo.barBAZ': 'foo_bar_baz'
+ }
+ for name in expectations:
+ self.assertEquals(expectations[name], model.UnixName(name));
+
if __name__ == '__main__':
unittest.main()
diff --git a/tools/json_schema_compiler/schema_bundle_generator.py b/tools/json_schema_compiler/schema_bundle_generator.py
index 6a842fc7..f5a61bc 100644
--- a/tools/json_schema_compiler/schema_bundle_generator.py
+++ b/tools/json_schema_compiler/schema_bundle_generator.py
@@ -51,8 +51,7 @@ class SchemaBundleGenerator(object):
c.Append('#include "base/basictypes.h"')
for namespace in self._model.namespaces.values():
- namespace_name = namespace.name.replace(
- "experimental.", "")
+ namespace_name = namespace.unix_name.replace("experimental_", "")
c.Append('#include "chrome/browser/extensions/api/%s/%s_api.h"' % (
namespace_name, namespace_name))