| 350 | } |
| 351 | |
| 352 | static void url_cache_run(const uint32_t *t, int n, int p, url_cache_t *uc) { |
| 353 | if (p >= uc->run_start && p < uc->run_end) { |
| 354 | return; /* the run is known: validity of an '@' does not depend on p */ |
| 355 | } |
| 356 | /* the scan enters a run at its start (every earlier position of a run |
| 357 | * filled this cache); scanning back is only for a caller that did not */ |
| 358 | int rs = p; |
| 359 | while (rs > 0 && !pdf_u_space(t[rs - 1])) { |
| 360 | rs--; |
| 361 | } |
| 362 | uc->run_start = rs; |
| 363 | uc->run_end = run_end_from(t, n, p); |
| 364 | uc->at = -1; |
| 365 | uc->at_end = -1; |
| 366 | int re = uc->run_end; |
| 367 | /* the largest '.' followed by two ASCII letters, scanning from the right; |
| 368 | * for each '@' (right to left) the domain is the largest such '.' >= at+2 */ |
| 369 | int best_dot = -1; |
| 370 | for (int a = re - 1; a > rs; a--) { |
| 371 | if (a + 2 < re && t[a] == '.' && is_alpha_ascii(t[a + 1]) && is_alpha_ascii(t[a + 2])) { |
| 372 | if (best_dot < 0) { |
| 373 | best_dot = a; |
| 374 | } |
| 375 | } |
| 376 | if (t[a] == '@' && best_dot >= a + 2) { |
| 377 | int e = best_dot + 1; |
| 378 | while (e < re && is_alpha_ascii(t[e])) { |
| 379 | e++; |
| 380 | } |
| 381 | uc->at = a; |
| 382 | uc->at_end = e; |
| 383 | return; |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | static int url_at(const uint32_t *t, int n, int p, url_cache_t *uc) { |
| 389 | if (lit_at(t, n, p, "https://") || lit_at(t, n, p, "http://") || lit_at(t, n, p, "ftp://") || |
no test coverage detected