diff options
| author | Kenichi Handa | 2009-02-12 06:01:23 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2009-02-12 06:01:23 +0000 |
| commit | 8b13507ac4236e4e38f44f4cc666c63e7df854bf (patch) | |
| tree | 465bbb7979dc1f7b2c7f3f11002c66233c936934 | |
| parent | 44a5ae4d488735fd0df592843d2145b522915bc6 (diff) | |
| download | emacs-8b13507ac4236e4e38f44f4cc666c63e7df854bf.tar.gz emacs-8b13507ac4236e4e38f44f4cc666c63e7df854bf.zip | |
(fast_looking_at): New function.
| -rw-r--r-- | src/search.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/search.c b/src/search.c index 9d2b95b68fc..cf0e4febf2f 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -557,6 +557,74 @@ fast_string_match_ignore_case (regexp, string) | |||
| 557 | return val; | 557 | return val; |
| 558 | } | 558 | } |
| 559 | 559 | ||
| 560 | /* Match REGEXP atainst the characters after POS to LIMIT, and return | ||
| 561 | the number of matched characters. If STRING is non-nil, match | ||
| 562 | against the characters in it. In that case, POS and LIMIT are | ||
| 563 | indices into the string. This function doesn't modify the match | ||
| 564 | data. */ | ||
| 565 | |||
| 566 | EMACS_INT | ||
| 567 | fast_looking_at (regexp, pos, pos_byte, limit, limit_byte, string) | ||
| 568 | Lisp_Object regexp; | ||
| 569 | EMACS_INT pos, pos_byte, limit, limit_byte; | ||
| 570 | Lisp_Object string; | ||
| 571 | { | ||
| 572 | int multibyte; | ||
| 573 | struct re_pattern_buffer *buf; | ||
| 574 | unsigned char *p1, *p2; | ||
| 575 | int s1, s2; | ||
| 576 | EMACS_INT len; | ||
| 577 | |||
| 578 | if (STRINGP (string)) | ||
| 579 | { | ||
| 580 | if (pos_byte < 0) | ||
| 581 | pos_byte = string_char_to_byte (string, pos); | ||
| 582 | if (limit_byte < 0) | ||
| 583 | limit_byte = string_char_to_byte (string, limit); | ||
| 584 | p1 = NULL; | ||
| 585 | s1 = 0; | ||
| 586 | p2 = SDATA (string); | ||
| 587 | s2 = SBYTES (string); | ||
| 588 | re_match_object = string; | ||
| 589 | multibyte = STRING_MULTIBYTE (string); | ||
| 590 | } | ||
| 591 | else | ||
| 592 | { | ||
| 593 | if (pos_byte < 0) | ||
| 594 | pos_byte = CHAR_TO_BYTE (pos); | ||
| 595 | if (limit_byte < 0) | ||
| 596 | limit_byte = CHAR_TO_BYTE (limit); | ||
| 597 | pos_byte -= BEGV_BYTE; | ||
| 598 | limit_byte -= BEGV_BYTE; | ||
| 599 | p1 = BEGV_ADDR; | ||
| 600 | s1 = GPT_BYTE - BEGV_BYTE; | ||
| 601 | p2 = GAP_END_ADDR; | ||
| 602 | s2 = ZV_BYTE - GPT_BYTE; | ||
| 603 | if (s1 < 0) | ||
| 604 | { | ||
| 605 | p2 = p1; | ||
| 606 | s2 = ZV_BYTE - BEGV_BYTE; | ||
| 607 | s1 = 0; | ||
| 608 | } | ||
| 609 | if (s2 < 0) | ||
| 610 | { | ||
| 611 | s1 = ZV_BYTE - BEGV_BYTE; | ||
| 612 | s2 = 0; | ||
| 613 | } | ||
| 614 | re_match_object = Qnil; | ||
| 615 | multibyte = ! NILP (current_buffer->enable_multibyte_characters); | ||
| 616 | } | ||
| 617 | |||
| 618 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); | ||
| 619 | immediate_quit = 1; | ||
| 620 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, | ||
| 621 | pos_byte, NULL, limit_byte); | ||
| 622 | immediate_quit = 0; | ||
| 623 | |||
| 624 | return len; | ||
| 625 | } | ||
| 626 | |||
| 627 | |||
| 560 | /* The newline cache: remembering which sections of text have no newlines. */ | 628 | /* The newline cache: remembering which sections of text have no newlines. */ |
| 561 | 629 | ||
| 562 | /* If the user has requested newline caching, make sure it's on. | 630 | /* If the user has requested newline caching, make sure it's on. |