From: "Mattias Engdegård" <mattiase@acm.org>
To: 43598@debbugs.gnu.org
Cc: Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#43598: replace-in-string: finishing touches
Date: Thu, 24 Sep 2020 22:52:06 +0200 [thread overview]
Message-ID: <77CD28C7-77C0-4DED-ACD0-21418489BADE@acm.org> (raw)
The new replace-in-string function is welcome but needs a few tweaks before we can call it done:
1. It doesn't quite work correctly with raw bytes:
(replace-in-string "\377" "x" "a\377b")
=> "axb"
(replace-in-string "\377" "x" "a\377ø")
=> "a\377ø"
The easiest solution is to reimplement it in terms of replace-regexp-in-string for now, and optimise it later (although I feel a bit bad undoing Lars's pretty handiwork...)
We have messy semantics here, because string-equal does not equate "\377" and (string-to-multibyte "\377"), but string-match-p does...
2. It is documented always to return a new string, but that's a tad over-generous nowadays; very few string functions do that. If we drop that guarantee, we get some optimisation opportunities:
- it can return the input string itself if no matches were found (a fairly common case)
- it can be marked pure, not just side-effect-free, so that the byte compiler can constant-propagate through calls to it
3. The name is somewhat unfortunate since a function by that name in XEmacs uses regexp matching.
In fact, the new function probably broke prolog-mode because of that (see prolog-replace-in-string).
While we can fix prolog-mode, we can't easily fix code outside the Emacs tree that may have similar problems.
Perhaps we should rename it to string-replace, in line with the modern naming convention discussed some time ago.
next reply other threads:[~2020-09-24 20:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 20:52 Mattias Engdegård [this message]
2020-09-24 21:12 ` bug#43598: replace-in-string: finishing touches Lars Ingebrigtsen
2020-09-24 21:19 ` Lars Ingebrigtsen
2020-09-24 23:18 ` Lars Ingebrigtsen
2020-09-25 9:21 ` Eli Zaretskii
2020-09-25 10:09 ` Lars Ingebrigtsen
2020-09-24 23:54 ` Lars Ingebrigtsen
2020-09-25 10:42 ` Mattias Engdegård
2020-09-25 11:11 ` Lars Ingebrigtsen
2020-09-25 11:22 ` Mattias Engdegård
2020-09-25 11:32 ` Lars Ingebrigtsen
2020-09-27 0:03 ` Lars Ingebrigtsen
2020-09-27 0:34 ` Lars Ingebrigtsen
2020-09-27 8:45 ` Mattias Engdegård
2020-09-28 3:41 ` Richard Stallman
2020-09-28 9:40 ` Mattias Engdegård
2020-09-29 3:29 ` Richard Stallman
2020-09-29 4:12 ` Eli Zaretskii
2020-09-27 11:12 ` Mattias Engdegård
2020-09-27 11:48 ` Lars Ingebrigtsen
2020-09-27 11:57 ` Mattias Engdegård
2020-09-27 12:02 ` Lars Ingebrigtsen
2020-09-27 16:14 ` Mattias Engdegård
2020-09-27 16:19 ` Eli Zaretskii
2020-09-27 16:41 ` Lars Ingebrigtsen
2020-09-27 16:48 ` Eli Zaretskii
2020-09-26 22:44 ` Lars Ingebrigtsen
2020-09-26 22:25 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=77CD28C7-77C0-4DED-ACD0-21418489BADE@acm.org \
--to=mattiase@acm.org \
--cc=43598@debbugs.gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).