| 161 | */ |
| 162 | |
| 163 | static sp_reason spdist(const char *s, const char *t) |
| 164 | { |
| 165 | for (; apr_tolower(*s) == apr_tolower(*t); t++, s++) { |
| 166 | if (*t == '\0') { |
| 167 | return SP_MISCAPITALIZED; /* exact match (sans case) */ |
| 168 | } |
| 169 | } |
| 170 | if (*s) { |
| 171 | if (*t) { |
| 172 | if (s[1] && t[1] && apr_tolower(*s) == apr_tolower(t[1]) |
| 173 | && apr_tolower(*t) == apr_tolower(s[1]) |
| 174 | && strcasecmp(s + 2, t + 2) == 0) { |
| 175 | return SP_TRANSPOSITION; /* transposition */ |
| 176 | } |
| 177 | if (strcasecmp(s + 1, t + 1) == 0) { |
| 178 | return SP_SIMPLETYPO; /* 1 char mismatch */ |
| 179 | } |
| 180 | } |
| 181 | if (strcasecmp(s + 1, t) == 0) { |
| 182 | return SP_EXTRACHAR; /* extra character */ |
| 183 | } |
| 184 | } |
| 185 | if (*t && strcasecmp(s, t + 1) == 0) { |
| 186 | return SP_MISSINGCHAR; /* missing character */ |
| 187 | } |
| 188 | return SP_VERYDIFFERENT; /* distance too large to fix. */ |
| 189 | } |
| 190 | |
| 191 | static int sort_by_quality(const void *left, const void *rite) |
| 192 | { |