diff options
| author | Artur Malabarba | 2015-11-28 15:31:43 +0000 |
|---|---|---|
| committer | Artur Malabarba | 2015-11-28 16:21:54 +0000 |
| commit | 19141a9be607cf88641c8b90cf494cf5913de49f (patch) | |
| tree | 052fab897ef5b38f0b1d1999389a4c7de88e0afe | |
| parent | 5c5997002b0b0aded744d5828158243fd546b3ec (diff) | |
| download | emacs-19141a9be607cf88641c8b90cf494cf5913de49f.tar.gz emacs-19141a9be607cf88641c8b90cf494cf5913de49f.zip | |
* lisp/character-fold.el: Also play nice with case-folding
(character-fold-to-regexp): Take `case-fold-search' into account.
| -rw-r--r-- | lisp/character-fold.el | 30 | ||||
| -rw-r--r-- | test/automated/character-fold-tests.el | 9 |
2 files changed, 29 insertions, 10 deletions
diff --git a/lisp/character-fold.el b/lisp/character-fold.el index 0086345cccb..49d75bd24ee 100644 --- a/lisp/character-fold.el +++ b/lisp/character-fold.el | |||
| @@ -152,11 +152,13 @@ regexp) and other characters are `regexp-quote'd. | |||
| 152 | 152 | ||
| 153 | FROM is for internal use. It specifies an index in the STRING | 153 | FROM is for internal use. It specifies an index in the STRING |
| 154 | from which to start." | 154 | from which to start." |
| 155 | (let ((spaces 0) | 155 | (let* ((spaces 0) |
| 156 | (multi-char-table (char-table-extra-slot character-fold-table 0)) | 156 | (multi-char-table (char-table-extra-slot character-fold-table 0)) |
| 157 | (i (or from 0)) | 157 | (lower-case-table (current-case-table)) |
| 158 | (end (length string)) | 158 | (upper-case-table (char-table-extra-slot lower-case-table 0)) |
| 159 | (out nil)) | 159 | (i (or from 0)) |
| 160 | (end (length string)) | ||
| 161 | (out nil)) | ||
| 160 | ;; When the user types a space, we want to match the table entry | 162 | ;; When the user types a space, we want to match the table entry |
| 161 | ;; for ?\s, which is generally a regexp like "[ ...]". However, | 163 | ;; for ?\s, which is generally a regexp like "[ ...]". However, |
| 162 | ;; the `search-spaces-regexp' variable doesn't "see" spaces inside | 164 | ;; the `search-spaces-regexp' variable doesn't "see" spaces inside |
| @@ -173,9 +175,21 @@ from which to start." | |||
| 173 | (setq spaces 0)) | 175 | (setq spaces 0)) |
| 174 | (let ((regexp (or (aref character-fold-table c) | 176 | (let ((regexp (or (aref character-fold-table c) |
| 175 | (regexp-quote (string c)))) | 177 | (regexp-quote (string c)))) |
| 176 | ;; Long string. The regexp would probably be too long. | 178 | (alist nil)) |
| 177 | (alist (unless (> end 60) | 179 | ;; Long string. The regexp would probably be too long. |
| 178 | (aref multi-char-table c)))) | 180 | (unless (> end 50) |
| 181 | (setq alist (aref multi-char-table c)) | ||
| 182 | (when case-fold-search | ||
| 183 | (let ((other-c (aref lower-case-table c))) | ||
| 184 | (when (or (not other-c) | ||
| 185 | (eq other-c c)) | ||
| 186 | (setq other-c (aref upper-case-table c))) | ||
| 187 | (when other-c | ||
| 188 | (setq alist (append alist (aref multi-char-table other-c))) | ||
| 189 | (setq regexp (concat "\\(?:" regexp "\\|" | ||
| 190 | (or (aref character-fold-table other-c) | ||
| 191 | (regexp-quote (string other-c))) | ||
| 192 | "\\)")))))) | ||
| 179 | (push (let ((alist-out '("\\)"))) | 193 | (push (let ((alist-out '("\\)"))) |
| 180 | (pcase-dolist (`(,suffix . ,out-regexp) alist) | 194 | (pcase-dolist (`(,suffix . ,out-regexp) alist) |
| 181 | (let ((len-suf (length suffix))) | 195 | (let ((len-suf (length suffix))) |
diff --git a/test/automated/character-fold-tests.el b/test/automated/character-fold-tests.el index aa2ee96a7a4..3a288b9071c 100644 --- a/test/automated/character-fold-tests.el +++ b/test/automated/character-fold-tests.el | |||
| @@ -37,7 +37,7 @@ | |||
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | (ert-deftest character-fold--test-consistency () | 39 | (ert-deftest character-fold--test-consistency () |
| 40 | (dotimes (n 100) | 40 | (dotimes (n 50) |
| 41 | (let ((w (character-fold--random-word n))) | 41 | (let ((w (character-fold--random-word n))) |
| 42 | ;; A folded string should always match the original string. | 42 | ;; A folded string should always match the original string. |
| 43 | (character-fold--test-search-with-contents w w)))) | 43 | (character-fold--test-search-with-contents w w)))) |
| @@ -57,7 +57,12 @@ | |||
| 57 | (defun character-fold--test-match-exactly (string &rest strings-to-match) | 57 | (defun character-fold--test-match-exactly (string &rest strings-to-match) |
| 58 | (let ((re (concat "\\`" (character-fold-to-regexp string) "\\'"))) | 58 | (let ((re (concat "\\`" (character-fold-to-regexp string) "\\'"))) |
| 59 | (dolist (it strings-to-match) | 59 | (dolist (it strings-to-match) |
| 60 | (should (string-match re it))))) | 60 | (should (string-match re it))) |
| 61 | ;; Case folding | ||
| 62 | (let ((case-fold-search t)) | ||
| 63 | (dolist (it strings-to-match) | ||
| 64 | (should (string-match (upcase re) (downcase it))) | ||
| 65 | (should (string-match (downcase re) (upcase it))))))) | ||
| 61 | 66 | ||
| 62 | (ert-deftest character-fold--test-some-defaults () | 67 | (ert-deftest character-fold--test-some-defaults () |
| 63 | (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi") | 68 | (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi") |