Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: PCRE support for embedded NUL characters



On 2012-09-17 at 09:57 +0100, Peter Stephenson wrote:
> You can just do a pre-scan of the whole string for backslashes.  If
> there's a backslash followed by a non-NULL, skip checking that next
> character (which may itself be a backslash that's escaped); if there's a
> backslash followed by a NULL the backslash can go.  It's such an unusual
> case it hardly seems worth it, though.

I'm inclined to document it as a limitation, rather than add complexity,
wherein will lurk bugs.

> They are characters.  If the string is unmetafied you can skip the
> MB_METACHARLEN() stuff and use the mbrtowc()/WCWIDTH() library calls
> directly (WCWIDTH() is only defined in order to be able to replace an
> unusable wcwidth()), but a null probably needs to be a special case
> since I think the libraries assume it's a terminator.  It looks like the
> existing pattern code uses metafied strings.

Yeah, but correlating offsets in unmetafied strings to the metafied
strings for then counting is non-trivial (or so it seems to me).

And wcwidth() tells how many display cells are needed for a given
character, assuming a monospace layout.  For this, instead, mblen() is
needed, on a character-by-character basis.  Given that mblen() is C99, I
opted to avoid it, and implement this just for UTF-8 with bit-pattern
examination to quickly count past characters.  We only initialise PCRE
for wide characters with UTF-8.  I've no idea how much effort we want to
put into supporting non-UTF-8 wide-character PCRE across multiple OSes.

Thoughts?

(Code not finished yesterday, will be a little bit before I get back to
it).

-Phil



Messages sorted by: Reverse Date, Date, Thread, Author