| 105 | } |
| 106 | |
| 107 | static void add_suffix(struct suffix_tree **prior, char ltr, const char *str) |
| 108 | { |
| 109 | struct suffix_tree *node, *newnode; |
| 110 | |
| 111 | if (ltr == '[') { |
| 112 | const char *after = strchr(str, ']'); |
| 113 | /* Treat "[foo" and "[]" as having a literal '['. */ |
| 114 | if (after && after++ != str+1) { |
| 115 | while ((ltr = *str++) != ']') |
| 116 | add_suffix(prior, ltr, after); |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | for (node = *prior; node; prior = &node->sibling, node = node->sibling) { |
| 122 | if (node->letter == ltr) { |
| 123 | if (*str) |
| 124 | add_suffix(&node->child, *str, str+1); |
| 125 | else |
| 126 | node->word_end = 1; |
| 127 | return; |
| 128 | } |
| 129 | if (node->letter > ltr) |
| 130 | break; |
| 131 | } |
| 132 | newnode = new(struct suffix_tree); |
| 133 | newnode->sibling = node; |
| 134 | newnode->child = NULL; |
| 135 | newnode->letter = ltr; |
| 136 | *prior = newnode; |
| 137 | if (*str) { |
| 138 | add_suffix(&newnode->child, *str, str+1); |
| 139 | newnode->word_end = 0; |
| 140 | } else |
| 141 | newnode->word_end = 1; |
| 142 | } |
| 143 | |
| 144 | static void add_nocompress_suffixes(const char *str) |
| 145 | { |
no outgoing calls
no test coverage detected