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

Unified Diff: third_party/WebKit/Source/build/scripts/name_utilities.py

Issue 2756113002: Move naming related code in make_computed_style_base to name_utilities. (Closed)
Patch Set: Rebase Created 3 years, 9 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 | « third_party/WebKit/Source/build/scripts/make_computed_style_base.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/build/scripts/name_utilities.py
diff --git a/third_party/WebKit/Source/build/scripts/name_utilities.py b/third_party/WebKit/Source/build/scripts/name_utilities.py
index c5fdcaac722a1d39ccd16bebda72ad845442deeb..ca3fa3aac820ae7fcef379af04a6c0a29e4d0b64 100644
--- a/third_party/WebKit/Source/build/scripts/name_utilities.py
+++ b/third_party/WebKit/Source/build/scripts/name_utilities.py
@@ -69,6 +69,13 @@ def upper_first(name):
return upper_first_letter(name)
+def lower_first_letter(name):
+ """Return name with first letter lowercased."""
+ if not name:
+ return ''
+ return name[0].lower() + name[1:]
+
+
def upper_first_letter(name):
"""Return name with first letter uppercased."""
if not name:
@@ -76,14 +83,6 @@ def upper_first_letter(name):
return name[0].upper() + name[1:]
-def camel_case(css_name):
- """Convert hyphen-separated-name to UpperCamelCase.
-
- E.g., '-foo-bar' becomes 'FooBar'.
- """
- return ''.join(upper_first_letter(word) for word in css_name.split('-'))
-
-
def to_macro_style(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper()
@@ -108,12 +107,49 @@ def cpp_name(entry):
def enum_for_css_keyword(keyword):
- return 'CSSValue' + ''.join(camel_case(keyword))
+ return 'CSSValue' + upper_camel_case(keyword)
def enum_for_css_property(property_name):
- return 'CSSProperty' + ''.join(camel_case(property_name))
+ return 'CSSProperty' + upper_camel_case(property_name)
def enum_for_css_property_alias(property_name):
- return 'CSSPropertyAlias' + camel_case(property_name)
+ return 'CSSPropertyAlias' + upper_camel_case(property_name)
+
+# TODO(shend): Merge these with the above methods.
+# and update all the generators to use these ones.
+# TODO(shend): Switch external callers of these methods to use the high level
+# API below instead.
+
+
+def split_name(name):
+ """Splits a name in some format to a list of words"""
+ return re.findall(r'(?:[A-Z][a-z]*)|[a-z]+|(?:\d+[a-z]*)', upper_first_letter(name))
+
+
+def upper_camel_case(name):
+ return ''.join(upper_first_letter(word) for word in split_name(name))
+
+
+def lower_camel_case(name):
+ return lower_first_letter(upper_camel_case(name))
+
+# Use these high level naming functions which describe the semantics of the name,
+# rather than a particular style.
+
+
+def enum_type_name(name):
+ return upper_camel_case(name)
+
+
+def enum_value_name(name):
+ return 'k' + upper_camel_case(name)
+
+
+def class_member_name(name):
+ return 'm_' + lower_camel_case(name)
+
+
+def method_name(name):
+ return lower_camel_case(name)
« no previous file with comments | « third_party/WebKit/Source/build/scripts/make_computed_style_base.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698