11 Commits

Author SHA1 Message Date
Jonas Berlin
ac2d0e1b33
impl: optimize replacen loop
The previous implementation didn't bail out of the replace
loop when the limit was reached until one more than the
total number of 'find' operations had completed. By moving
the limit check to the end of the loop body, we execute only
the number of 'find' operations that is necessary, instead of
one extra.

This optimization only applies to 'replacen' calls with a limit
not equal to '0'. That includes 'replace' but not 'replace_all'.

PR #930
2022-11-28 13:37:22 -05:00
Andrew Gallant
94ce242913 edition: more 2018 migration (idioms) 2021-04-30 20:02:56 -04:00
tom
2bab987149
api: Replacer for more string types
And do the same for the bytes oriented APIs.

This results in some small quality of life improvements
when using the Replacer trait with a string type that
isn't &str.

PR #728
2021-01-12 07:30:51 -05:00
Andrew Gallant
1e7efa4180 regex: add unicode and perf features
This commit sets up the infrastructure for supporting various `unicode`
and `perf` features, which permit decreasing binary size, compile times
and the size of the dependency tree.

Most of the work here is in modifying the regex tests to make them
work in concert with the available Unicode features. In cases where
Unicode is irrelevant, we just turn it off. In other cases, we require
the Unicode features to run the tests.

This also introduces a new error in the compiler where by if a Unicode
word boundary is used, but the `unicode-perl` feature is disabled, then
the regex will fail to compile. (Because the necessary data to match
Unicode word boundaries isn't available.)
2019-09-03 12:35:17 -04:00
Andrew Gallant
0e96af4166
style: start using rustfmt 2019-08-03 14:20:22 -04:00
Andrew Gallant
3f7a603176
tests: fix lifetime warning
Apparently we were hitting a bug in borrowck that was fixed, but now
emits a warning. It doesn't appear necessary for us to return a borrow,
so we just copy.
2019-06-09 08:55:52 -04:00
Eli Dupree
53385d7847 api: generalize Replacer impls
This causes the `Replacer` impls for closures to accept functions
that return any AsRef<str>/AsRef<[u8]> instead of String/Vec<u8>
specifically.

PR #509
2018-09-06 13:47:06 -04:00
fulara
9694f256df tests: added test for demoing capture names
See also: #399
2017-12-30 15:37:41 -05:00
Lapinot
408add0f36
Fix Regex::replacen when replacing an empty match.
Fixes #393, #394.
2017-10-15 17:49:52 +02:00
Utkarsh Kukreti
a9f9c9ca53 Fix replace_all when only match is at start and replacement is empty.
Fixes #314.
2017-01-02 20:39:50 +05:30
Andrew Gallant
d98ec1b1a5 Add regex matching for &[u8].
This commit enables support for compiling regular expressions that can
match on arbitrary byte slices. In particular, we add a new sub-module
called `bytes` that duplicates the API of the top-level module, except
`&str` for subjects is replaced by `&[u8]`. Additionally, Unicode
support in the regular expression is disabled by default but can be
selectively re-enabled with the `u` flag. (Unicode support cannot be
selectively disabled in the standard top-level API.)

Most of the interesting changes occurred in the `regex-syntax` crate,
where the AST now explicitly distinguishes between "ASCII compatible"
expressions and Unicode aware expressions.

This PR makes a few other changes out of convenience:

1. The DFA now knows how to "give up" if it's flushing its cache too
often. When the DFA gives up, either backtracking or the NFA algorithm
take over, which provides better performance.
2. Benchmarks were added for Oniguruma.
3. The benchmarks in general were overhauled to be defined in one place
by using conditional compilation.
4. The tests have been completely reorganized to make it easier to split
up the tests depending on which regex engine we're using. For example,
we occasionally need to be able to write tests specifically for
`regex::Regex` or specifically for `regex::bytes::Regex`.
5. Fixes a bug where NUL bytes weren't represented correctly in the byte
class optimization for the DFA.

Closes #85.
2016-03-09 21:23:29 -05:00