[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#43598: replace-in-string: finishing touches
From: |
Lars Ingebrigtsen |
Subject: |
bug#43598: replace-in-string: finishing touches |
Date: |
Sun, 27 Sep 2020 00:44:38 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Mattias Engdegård <mattiase@acm.org> writes:
> We should also consider the optimisations:
> - If SCHARS(needle)>SCHARS(haystack) then no match is possible.
I've now done this.
> - If either needle or haystack is all-ASCII (all bytes in 0..127),
> then we can use memmem without conversion.
I thought that surely there's be a function like that in Emacs, but I
can't find it?
Instead there's code like
&& (STRING_MULTIBYTE (string)
? (chars == bytes) : string_ascii_p (string))
[...]
/* Whether STRING only contains chars in the 0..127 range. */
static bool
string_ascii_p (Lisp_Object string)
{
ptrdiff_t nbytes = SBYTES (string);
for (ptrdiff_t i = 0; i < nbytes; i++)
if (SREF (string, i) > 127)
return false;
return true;
}
and
unsigned char *p = SDATA (name);
while (*p && ASCII_CHAR_P (*p))
p++;
sprinkled around the code base.
Would it make sense to add a new utility function that does the right
thing for both multibyte and unibyte strings? (The multibyte case is
just chars == bytes, but the unibyte case would be a loop.)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
- bug#43598: replace-in-string: finishing touches, (continued)
- bug#43598: replace-in-string: finishing touches, Mattias Engdegård, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Mattias Engdegård, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Mattias Engdegård, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Eli Zaretskii, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Eli Zaretskii, 2020/09/27
- bug#43598: replace-in-string: finishing touches,
Lars Ingebrigtsen <=
bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/26