Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Explicitly specify PCRE line-ending mode in TextBuffer::find() methods #64

Open
smashwilson opened this issue Mar 29, 2018 · 0 comments

Comments

@smashwilson
Copy link
Contributor

In #60, PCRE was configured to default to using PCRE2_NEWLINE_ANY when compiling regular expressions. This is consistent with the way that native JavaScript regular expressions work when the m flag is provided:

> /^aaa/m.exec('\naaa')
[ 'aaa', index: 1, input: '\naaa' ]
> /^aaa/m.exec('\raaa')
[ 'aaa', index: 1, input: '\raaa' ]
> /^aaa/m.exec('\r\naaa')
[ 'aaa', index: 2, input: '\r\naaa' ]
> /./.exec('\r')
null
> /./.exec('\n')
null

However, the results can be counter-intuitive when running against a TextBuffer that has CRLF line endings - for example, ^$ will match between the /r and /n:

> "\r\n".match(/^$/mg)
["", "", ""]

It would be ideal if we could allow callers to explicitly pass a newline setting to use for a specific find operation and default it to the preferred line ending for a TextBuffer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant