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

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

@smashwilson

Description

@smashwilson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions