OLD | NEW |
---|---|
1 {# | 1 {# |
2 FIXME: Do we need to put license blocks in generated files? | 2 FIXME: Do we need to put license blocks in generated files? |
3 #} | 3 #} |
4 {% macro license() %} | 4 {% macro license() %} |
5 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 5 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
6 // Use of this source code is governed by a BSD-style license that can be | 6 // Use of this source code is governed by a BSD-style license that can be |
7 // found in the LICENSE file. | 7 // found in the LICENSE file. |
8 {%- endmacro %} | 8 {%- endmacro %} |
9 | |
10 | |
11 {% macro trie_leaf(index, object, return_macro, lowercase_data) %} | |
12 {% for name, value in object.items() %} | |
13 {% if name|length %} | |
14 if ( | |
15 {%- for c in name -%} | |
16 {%- if lowercase_data -%} | |
17 {{ " && " if not loop.first }}toASCIILower(data[{{index + loop.index0}}]) == '{{c}}' | |
18 {%- else -%} | |
19 {{ " && " if not loop.first }}data[{{index + loop.index0}}] == '{{c}}' | |
20 {%- endif -%} | |
21 {%- endfor -%} | |
22 ) | |
23 return {{ return_macro(value) }}; | |
24 break; | |
25 {% else %} | |
26 return {{ return_macro(value) }}; | |
27 {% endif %} | |
28 {% endfor %} | |
29 {% endmacro %} | |
30 | |
31 | |
32 {% macro trie_switch(trie, index, return_macro, lowercase_data) %} | |
Timothy Loh
2016/05/13 04:49:17
Do you think it would be clearer to merge the macr
meade_UTC10
2016/05/13 06:48:20
Hmm, I think it's clearer to have the trie_leaf ma
| |
33 {% if lowercase_data %} | |
34 switch (toASCIILower(data[{{index}}])) { | |
35 {% else %} | |
36 switch (data[{{index}}]) { | |
37 {% endif %} | |
38 {% for char, value in trie.items()|sort %} | |
39 case '{{char}}': | |
40 {% if value|length == 1 and value.items()[0][1] is string %} | |
41 {{ trie_leaf(index+1, value, return_macro, lowercase_data) | indent(4) }} | |
42 {% else %} | |
43 {{ trie_switch(value, index + 1, return_macro, lowercase_data) | indent(4) } } | |
44 {% endif %} | |
45 {% endfor %} | |
46 } | |
47 break; | |
48 {% endmacro %} | |
49 | |
50 | |
51 {% macro trie_length_switch(length_tries, return_macro, default_return_value, lo wercase_data) %} | |
Timothy Loh
2016/05/13 05:41:33
default_return_value isn't used any more
meade_UTC10
2016/05/13 06:48:20
Done.
| |
52 switch(length) { | |
Timothy Loh
2016/05/13 04:49:17
Space after switch
meade_UTC10
2016/05/13 06:48:20
Done.
| |
53 {% for length, trie in length_tries %} | |
54 case {{ length }}: | |
55 {{ trie_switch(trie, 0, return_macro, lowercase_data) | indent(4) }} | |
56 {% endfor %} | |
57 } | |
58 {% endmacro %} | |
OLD | NEW |