diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-17 08:34:01 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-17 11:50:24 -0800 |
| commit | 5294ceb312b059709f204300156b732cc78cfaf0 (patch) | |
| tree | 09685724a9180d17619c7904745a2d5e695ceca6 /src/rustllvm/RustWrapper.cpp | |
| parent | 974e17b9ea63b38b4a512742fc877a7e4ee94e03 (diff) | |
| parent | c2b0d7dd8818a0dca9b1fa7af6873375907f05ca (diff) | |
| download | rust-5294ceb312b059709f204300156b732cc78cfaf0.tar.gz rust-5294ceb312b059709f204300156b732cc78cfaf0.zip | |
rollup merge of #19818: emk/regex_at_name_opt
Hello! This is my first Rust patch, and I fear that I've probably skipped at least 7 critical steps. I'd appreciate your feedback and advice about how to contribute to Rust.
This patch is based on a discussion with @BurntSushi in #14602 a while back. I'm happy to revise it as needed to fit into the modern world. :-)
As discussed in that issue, the existing `at` and `name` functions represent two different results with the empty string:
1. Matched the empty string.
2. Did not match anything.
Consider the following example. This regex has two named matched groups, `key` and `value`. `value` is optional:
```rust
// Matches "foo", "foo;v=bar" and "foo;v=".
regex!(r"(?P<key>[a-z]+)(;v=(?P<value>[a-z]*))?");
```
We can access `value` using `caps.name("value")`, but there's no way for us to distinguish between the `"foo"` and `"foo;v="` cases.
Early this year, @BurntSushi recommended modifying the existing `at` and `name` functions to return `Option`, instead of adding new functions to the API.
This is a [breaking-change], but the fix is easy:
- `refs.at(1)` becomes `refs.at(1).unwrap_or("")`.
- `refs.name(name)` becomes `refs.name(name).unwrap_or("")`.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
