Chromium Code Reviews| 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 {% macro trie_leaf(index, entry, return_macro, default_return_value) %} | |
|
Timothy Loh
2016/05/03 07:40:25
We'll need a flag should_lower since unlike the ta
| |
| 11 {% if entry.conditions %} | |
| 12 if ({{entry.conditions | join(' && ')}}) | |
| 13 {{return_macro(entry.value)}} | |
| 14 {% else %} | |
| 15 if (data[{{index}}] == '{{entry.char}}') | |
| 16 {{return_macro(entry.value)}} | |
| 17 {% endif %} | |
| 18 return {{default_return_value}}; | |
|
Timothy Loh
2016/05/03 07:40:25
It might be possible to make this a "break" so we
meade_UTC10
2016/05/04 07:24:54
Done.
| |
| 19 {% endmacro %} | |
| 20 | |
| 21 {% macro trie_switch(trie, index, return_macro, default_return_value) %} | |
| 22 switch (data[{{index}}]) { | |
| 23 {% for entry in trie %} | |
| 24 case '{{entry.char}}': | |
| 25 {% if entry.subtrie %} | |
| 26 {{trie_switch(entry.subtrie, index + 1, return_macro, default_return_value) | indent}} | |
| 27 {% elif entry.conditions %}{# Check suffix #} | |
| 28 {{trie_leaf(index, entry, return_macro, default_return_value)}} | |
| 29 {% else %}{# Terminal node (no suffix) #} | |
| 30 {{return_macro(entry.value)}} | |
| 31 {% endif %} | |
| 32 {% endfor %} | |
| 33 } | |
| 34 return {{default_return_value}}; | |
| 35 {% endmacro %} | |
| 36 | |
| 37 {% macro trie_length_switch(empty_case_return_value, length_tries, return_macro, default_return_value) %} | |
| 38 switch (length) { | |
| 39 {% if empty_case_return_value %} | |
| 40 case 0: | |
| 41 {{return_macro(empty_case_return_value)}} | |
| 42 {% endif %} | |
| 43 {% for length, trie in length_tries %} | |
| 44 case {{length}}: | |
| 45 {% if trie|length > 1 or trie[0].subtrie %} | |
| 46 {{trie_switch(trie, 0, return_macro, default_return_value) | indent(8)}} | |
| 47 {% else %} | |
| 48 {{trie_leaf(0, trie[0], return_macro, default_return_value) | indent(8)} } | |
| 49 {% endif %} | |
| 50 {% endfor %} | |
| 51 } | |
| 52 return {{default_return_value}}; | |
| 53 {% endmacro %} | |
| OLD | NEW |