emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regexp case sensitivity bug


From: Kim F. Storm
Subject: Re: regexp case sensitivity bug
Date: 10 Dec 2002 01:45:17 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Dean Herington <address@hidden> writes:

> Richard Stallman wrote:
> 
> >     In Emacs 21.1.1, when I do isearch-forward-regexp with input "\bP",
> >     Emacs matches 'p's case insensitively.
> >
> > Does this patch fix it?
> >
> > *** isearch.el.~1.215.~ Sun Nov 10 13:13:37 2002
> > --- isearch.el  Mon Dec  9 11:20:37 2002
> > ***************
> > *** 1871,1877 ****
> >         (if (and regexp-flag (eq char ?\\))
> >             (setq quote-flag (not quote-flag))
> >           (if (and (not quote-flag) (not (eq char (downcase char))))
> > !             (setq found t))))
> >         (setq i (1+ i)))
> >       (not found)))
> >
> > --- 1871,1878 ----
> >         (if (and regexp-flag (eq char ?\\))
> >             (setq quote-flag (not quote-flag))
> >           (if (and (not quote-flag) (not (eq char (downcase char))))
> > !             (setq found t))
> > !         (setq quote-flag nil)))
> >         (setq i (1+ i)))
> >       (not found)))
> 
> That patch fixes the bug I saw.
> 
> How about the following, which I find simpler?
> 
> (defun isearch-no-upper-case-p (string regexp-flag)
>   "Return t if there are no upper case chars in STRING.
> If REGEXP-FLAG is non-nil, disregard letters quoted by `\\'
> since they have special meaning in a regexp."
>   (let ((i 0) (len (length string)) found)
>     (while (and (not found) (< i len))
>       (let ((char (aref string i)))
>         (if (and regexp-flag (eq char ?\\))
>             (setq i (1+ i))
>           (if (not (eq char (downcase char)))
>               (setq found t))))
>       (setq i (1+ i)))
>     (not found)))
> 

Or we can use a completely different approach:

(defun isearch-no-upper-case-p (string regexp-flag)
  "..."
  (let ((case-fold-search nil))
    (save-match-data
      (null (string-match 
              (if regexp-flag "\\(^\\|[^\\]\\)[[:upper:]]" "[[:upper:]]")
              string)))))


-- 
Kim F. Storm <address@hidden> http://www.cua.dk




reply via email to

[Prev in Thread] Current Thread [Next in Thread]