Searches the case folding tables and returns the CaseFold* that contains r. If there isn't one, returns the CaseFold* with smallest f->lo bigger than r. If there isn't one, returns NULL.
| 270 | // If there isn't one, returns the CaseFold* with smallest f->lo bigger than r. |
| 271 | // If there isn't one, returns NULL. |
| 272 | const CaseFold* LookupCaseFold(const CaseFold *f, int n, Rune r) { |
| 273 | const CaseFold* ef = f + n; |
| 274 | |
| 275 | // Binary search for entry containing r. |
| 276 | while (n > 0) { |
| 277 | int m = n/2; |
| 278 | if (f[m].lo <= r && r <= f[m].hi) |
| 279 | return &f[m]; |
| 280 | if (r < f[m].lo) { |
| 281 | n = m; |
| 282 | } else { |
| 283 | f += m+1; |
| 284 | n -= m+1; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // There is no entry that contains r, but f points |
| 289 | // where it would have been. Unless f points at |
| 290 | // the end of the array, it points at the next entry |
| 291 | // after r. |
| 292 | if (f < ef) |
| 293 | return f; |
| 294 | |
| 295 | // No entry contains r; no entry contains runes > r. |
| 296 | return NULL; |
| 297 | } |
| 298 | |
| 299 | // Returns the result of applying the fold f to the rune r. |
| 300 | Rune ApplyFold(const CaseFold *f, Rune r) { |
no outgoing calls
no test coverage detected