Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Unified Diff: tools/json_schema_compiler/model.py

Issue 13599004: Fix some low hanging inefficiencies in the docs server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/memoize.py ('k') | tools/json_to_struct/json_to_struct.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/model.py
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 3dfc3b2422208d8309d6f65a25e8ff15a1ba5dc9..d6b6efc1a12f3519777d08b4995fa43d27e8c8ea 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -2,11 +2,10 @@
# 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
from json_parse import OrderedDict
+from memoize import memoize
class ParseException(Exception):
"""Thrown when data in the model is invalid.
@@ -373,15 +372,26 @@ class PropertyType(object):
BINARY = _PropertyTypeInfo(False, "binary")
ANY = _PropertyTypeInfo(False, "any")
+@memoize
def UnixName(name):
- """Returns the unix_style name for a given lowerCamelCase string.
- """
- # 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()
+ '''Returns the unix_style name for a given lowerCamelCase string.
+ '''
+ unix_name = []
+ for i, c in enumerate(name):
+ if c.isupper() and i > 0:
+ # Replace lowerUpper with lower_Upper.
+ if name[i - 1].islower():
+ unix_name.append('_')
+ # Replace ACMEWidgets with ACME_Widgets
+ elif i + 1 < len(name) and name[i + 1].islower():
+ unix_name.append('_')
+ if c == '.':
+ # Replace hello.world with hello_world.
+ unix_name.append('_')
+ else:
+ # Everything is lowercase.
+ unix_name.append(c.lower())
+ return ''.join(unix_name)
def _StripNamespace(name, namespace):
if name.startswith(namespace.name + '.'):
« no previous file with comments | « tools/json_schema_compiler/memoize.py ('k') | tools/json_to_struct/json_to_struct.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698