Chromium Code Reviews| Index: third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
| diff --git a/third_party/WebKit/Source/build/scripts/templates/macros.tmpl b/third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
| index 064dd985221d257994df2387b101d11eb14a634d..b42639779d028bdb0ad05e7533b74af4ff875fb6 100644 |
| --- a/third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
| +++ b/third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
| @@ -6,3 +6,58 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| {%- endmacro %} |
| + |
| + |
| +{% macro trie_leaf(index, object, return_macro, lowercase_data) %} |
| +{% for name, value in object.items() %} |
| + {% if name|length %} |
| +if ( |
| + {%- for c in name -%} |
| + {%- if lowercase_data -%} |
| + {{ " && " if not loop.first }}toASCIILower(data[{{index + loop.index0}}]) == '{{c}}' |
| + {%- else -%} |
| + {{ " && " if not loop.first }}data[{{index + loop.index0}}] == '{{c}}' |
| + {%- endif -%} |
| + {%- endfor -%} |
| + ) |
| + return {{ return_macro(value) }}; |
| +break; |
| + {% else %} |
| +return {{ return_macro(value) }}; |
| + {% endif %} |
| +{% endfor %} |
| +{% endmacro %} |
| + |
| + |
| +{% macro trie_switch(trie, index, return_macro, lowercase_data) %} |
| +{% if lowercase_data %} |
| +switch (toASCIILower(data[{{index}}])) { |
| +{% else %} |
| +switch (data[{{index}}]) { |
| +{% endif %} |
| +{% for char, value in trie.items()|sort %} |
| +case '{{char}}': |
| + {% if value|length == 1 and value.items()[0][1] is string %} |
| + {{ trie_leaf(index+1, value, return_macro, lowercase_data) | indent(4) }} |
| + {% else %} |
| + {{ trie_switch(value, index + 1, return_macro, lowercase_data) | indent(4) }} |
| + {% endif %} |
| +{% endfor %} |
| +} |
| +break; |
| +{% endmacro %} |
| + |
| + |
| +{% macro trie_length_switch(empty_case_return_value, length_tries, return_macro, default_return_value, lowercase_data) %} |
| +switch(length) { |
| +{% if empty_case_return_value %} |
|
Timothy Loh
2016/05/12 07:03:14
This shouldn't be needed any more due to https://c
meade_UTC10
2016/05/13 03:48:19
Done.
|
| +case 0: |
| + return {{ empty_case_return_value }}; |
| +{% endif %} |
| +{% for length, trie in length_tries %} |
| +case {{ length }}: |
| + {{ trie_switch(trie, 0, return_macro, lowercase_data) | indent(4) }} |
| +{% endfor %} |
| +} |
| +return {{ default_return_value }}; |
|
Timothy Loh
2016/05/12 07:03:14
I think it'd be nicer if the users of the macro ju
meade_UTC10
2016/05/13 03:48:19
Done.
|
| +{% endmacro %} |