From 7bdc40e8d10488745355376981793a4d1e823f19 Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Fri, 4 Dec 2020 18:37:21 +0100 Subject: Speed up match-substitute-replacement * lisp/subr.el (match-substitute-replacement): Use match-data--translate. * src/search.c (Fmatch_data__translate): Remove string restriction. * test/lisp/subr-tests.el (subr-match-substitute-replacement): New test. --- test/lisp/subr-tests.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/lisp/subr-tests.el') diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 019441d9a39..e275e4b1c89 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -551,6 +551,30 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350." (should (equal (replace-regexp-in-string "\\`\\|x" "z" "--xx--") "z--zz--"))) +(ert-deftest subr-match-substitute-replacement () + (with-temp-buffer + (insert "Alpha Beta Gamma Delta Epsilon") + (goto-char (point-min)) + (re-search-forward "B\\(..\\)a") + (should (equal (match-substitute-replacement "carrot") + "Carrot")) + (should (equal (match-substitute-replacement "<\\&>") + "")) + (should (equal (match-substitute-replacement "m\\1a") + "Meta")) + (should (equal (match-substitute-replacement "ernin" nil nil nil 1) + "Bernina"))) + (let ((s "Tau Beta Gamma Delta Epsilon")) + (string-match "B\\(..\\)a" s) + (should (equal (match-substitute-replacement "carrot" nil nil s) + "Carrot")) + (should (equal (match-substitute-replacement "<\\&>" nil nil s) + "")) + (should (equal (match-substitute-replacement "m\\1a" nil nil s) + "Meta")) + (should (equal (match-substitute-replacement "ernin" nil nil s 1) + "Bernina")))) + (ert-deftest subr-tests--change-group-33341 () (with-temp-buffer (buffer-enable-undo) -- cgit v1.2.3