| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import os.path | 29 import os.path |
| 30 import re | 30 import re |
| 31 | 31 |
| 32 | 32 |
| 33 # Acronyms are kept as all caps. |
| 33 ACRONYMS = [ | 34 ACRONYMS = [ |
| 35 '3D', |
| 34 'CSSOM', | 36 'CSSOM', |
| 35 'CSS', | 37 'CSS', |
| 36 'DNS', | 38 'DNS', |
| 37 'FE', | 39 'FE', |
| 38 'FTP', | 40 'FTP', |
| 39 'HTML', | 41 'HTML', |
| 40 'JS', | 42 'JS', |
| 41 'SMIL', | 43 'SMIL', |
| 42 'SVG', | 44 'SVG', |
| 43 'URL', | 45 'URL', |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 return 'CSSPropertyAlias' + upper_camel_case(property_name) | 121 return 'CSSPropertyAlias' + upper_camel_case(property_name) |
| 120 | 122 |
| 121 # TODO(shend): Merge these with the above methods. | 123 # TODO(shend): Merge these with the above methods. |
| 122 # and update all the generators to use these ones. | 124 # and update all the generators to use these ones. |
| 123 # TODO(shend): Switch external callers of these methods to use the high level | 125 # TODO(shend): Switch external callers of these methods to use the high level |
| 124 # API below instead. | 126 # API below instead. |
| 125 | 127 |
| 126 | 128 |
| 127 def split_name(name): | 129 def split_name(name): |
| 128 """Splits a name in some format to a list of words""" | 130 """Splits a name in some format to a list of words""" |
| 129 return re.findall(r'(?:[A-Z][a-z]*)|[a-z]+|(?:\d+[a-z]*)', upper_first_lette
r(name)) | 131 return re.findall('|'.join(ACRONYMS) + r'|(?:[A-Z][a-z]*)|[a-z]+|(?:\d+[a-z]
*)', |
| 132 upper_first_letter(name)) |
| 130 | 133 |
| 131 | 134 |
| 132 def upper_camel_case(name): | 135 def upper_camel_case(name): |
| 133 return ''.join(upper_first_letter(word) for word in split_name(name)) | 136 return ''.join(upper_first_letter(word) for word in split_name(name)) |
| 134 | 137 |
| 135 | 138 |
| 136 def lower_camel_case(name): | 139 def lower_camel_case(name): |
| 137 return lower_first_letter(upper_camel_case(name)) | 140 return lower_first_letter(upper_camel_case(name)) |
| 138 | 141 |
| 139 | 142 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 164 def method_name(name): | 167 def method_name(name): |
| 165 return upper_camel_case(name) | 168 return upper_camel_case(name) |
| 166 | 169 |
| 167 | 170 |
| 168 def join_name(*names): | 171 def join_name(*names): |
| 169 """Given a list of names, join them into a single space-separated name.""" | 172 """Given a list of names, join them into a single space-separated name.""" |
| 170 result = [] | 173 result = [] |
| 171 for name in names: | 174 for name in names: |
| 172 result.extend(split_name(name)) | 175 result.extend(split_name(name)) |
| 173 return ' '.join(result) | 176 return ' '.join(result) |
| OLD | NEW |