9 Commits

Author SHA1 Message Date
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
Daniel Parks
b9d1bb5e98 api: fix for split() not returning last ""
Corrects `/-/.split("a-")` to return `["a", ""]` instead of `["a"]`.
(`/-/` is shorthand for `Regex::new("-").unwrap()`.)

This adds tests for both `split()` and `splitn()` covering a variety of
edge cases. One test is commented out because it is failing due to #521.
A future commit will fix it.

Note that the `split2` and `split3` tests were passing incorrectly
before this change. I have fixed them to expect the correct values.

Fixes #627
2020-01-09 14:26:57 -05: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
Lukas Lueg
264ef3f421 Revert some unwarranted clippy-changes 2017-06-01 19:38:23 +02:00
Lukas Lueg
94f8213def Fix clippy warnings 2017-05-31 22:24:22 +02:00
Andrew Gallant
384e9376a4 find/find_iter now return a Match instead of (usize, usize).
This also removes Captures.{at,pos} and replaces it with Captures.get,
which now returns a Match. Similarly, Captures.name returns a Match as
well.

Fixes #276
2016-12-30 01:05:50 -05:00
Andrew Gallant
ebd26e9bbe Update Replacer trait for Unicode regexes.
This uses the new Replacer trait essentially as defined in the `bytes`
sub-module and described in #151.

Fixes #151
2016-12-30 01:05:50 -05:00
Andrew Gallant
d44a9f94ab Switch bytes::Regex to using Unicode mode by default. 2016-12-30 01:05:43 -05:00
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