mirror of
https://github.com/openharmony/third_party_rust_regex.git
synced 2026-06-30 21:37:57 -04:00
edition: manual fixups to code
This commit does a number of manual fixups to the code after the previous two commits were done via 'cargo fix' automatically. Actually, this contains more 'cargo fix' annotations, since I had forgotten to add 'edition = "2018"' to all sub-crates.
This commit is contained in:
+1
-3
@@ -62,9 +62,7 @@ on how your program is structured. Thankfully, the
|
||||
[`lazy_static`](https://crates.io/crates/lazy_static)
|
||||
crate provides an answer that works well:
|
||||
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate regex;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
fn some_helper_function(text: &str) -> bool {
|
||||
|
||||
@@ -27,13 +27,7 @@ Add this to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
regex = "1"
|
||||
```
|
||||
|
||||
and this to your crate root (if you're using Rust 2015):
|
||||
|
||||
```rust
|
||||
extern crate regex;
|
||||
regex = "1.5"
|
||||
```
|
||||
|
||||
Here's a simple example that matches a date in YYYY-MM-DD format and prints the
|
||||
|
||||
+2
-2
@@ -10,6 +10,7 @@ homepage = "https://github.com/rust-lang/regex"
|
||||
description = "Regex benchmarks for Rust's and other engines."
|
||||
build = "build.rs"
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
docopt = "1"
|
||||
@@ -20,8 +21,7 @@ libpcre-sys = { version = "0.2", optional = true }
|
||||
memmap = "0.6.2"
|
||||
regex = { version = "1", path = ".." }
|
||||
regex-syntax = { version = "0.6", path = "../regex-syntax" }
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
cfg-if = "0.1"
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
extern crate cc;
|
||||
extern crate pkg_config;
|
||||
|
||||
use std::env;
|
||||
use std::process;
|
||||
|
||||
|
||||
+14
-15
@@ -1,29 +1,21 @@
|
||||
// Enable the benchmarking harness.
|
||||
#![feature(test)]
|
||||
// It's too annoying to carefully define macros based on which regex engines
|
||||
// have which benchmarks, so just ignore these warnings.
|
||||
#![allow(unused_macros)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
|
||||
#[cfg(not(any(feature = "re-rust", feature = "re-rust-bytes")))]
|
||||
extern crate libc;
|
||||
|
||||
extern crate regex_syntax;
|
||||
extern crate test;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "re-pcre1")] {
|
||||
extern crate libpcre_sys;
|
||||
pub use ffi::pcre1::Regex;
|
||||
} else if #[cfg(feature = "re-onig")] {
|
||||
extern crate onig;
|
||||
pub use ffi::onig::Regex;
|
||||
} else if #[cfg(any(feature = "re-rust"))] {
|
||||
extern crate regex;
|
||||
pub use regex::{Regex, RegexSet};
|
||||
} else if #[cfg(feature = "re-rust-bytes")] {
|
||||
extern crate regex;
|
||||
pub use regex::bytes::{Regex, RegexSet};
|
||||
} else if #[cfg(feature = "re-re2")] {
|
||||
pub use ffi::re2::Regex;
|
||||
@@ -51,7 +43,7 @@ cfg_if! {
|
||||
// native and dynamic regexes.
|
||||
macro_rules! regex {
|
||||
($re:expr) => {
|
||||
::Regex::new(&$re.to_owned()).unwrap()
|
||||
crate::Regex::new(&$re.to_owned()).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -72,7 +64,7 @@ cfg_if! {
|
||||
// regex accepts in its `is_match` and `find_iter` methods.
|
||||
macro_rules! text {
|
||||
($text:expr) => {{
|
||||
use ffi::tcl::Text;
|
||||
use crate::ffi::tcl::Text;
|
||||
Text::new($text)
|
||||
}}
|
||||
}
|
||||
@@ -148,6 +140,7 @@ macro_rules! bench_is_match {
|
||||
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
|
||||
#[bench]
|
||||
fn $name(b: &mut Bencher) {
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
// Why do we use lazy_static here? It seems sensible to just
|
||||
@@ -192,6 +185,7 @@ macro_rules! bench_find {
|
||||
($name:ident, $pattern:expr, $count:expr, $haystack:expr) => {
|
||||
#[bench]
|
||||
fn $name(b: &mut Bencher) {
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
@@ -224,6 +218,7 @@ macro_rules! bench_captures {
|
||||
#[cfg(feature = "re-rust")]
|
||||
#[bench]
|
||||
fn $name(b: &mut Bencher) {
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
@@ -246,7 +241,9 @@ macro_rules! bench_is_match_set {
|
||||
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
|
||||
#[bench]
|
||||
fn $name(b: &mut Bencher) {
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
static ref RE: Mutex<RegexSet> = Mutex::new($re);
|
||||
static ref TEXT: Mutex<Text> = Mutex::new(text!($haystack));
|
||||
@@ -272,7 +269,9 @@ macro_rules! bench_matches_set {
|
||||
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
|
||||
#[bench]
|
||||
fn $name(b: &mut Bencher) {
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
static ref RE: Mutex<RegexSet> = Mutex::new($re);
|
||||
static ref TEXT: Mutex<Text> = Mutex::new(text!($haystack));
|
||||
|
||||
+11
-11
@@ -4,7 +4,7 @@ use std::fmt;
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
|
||||
use libc::{c_int, c_void, size_t, uint32_t, uint8_t};
|
||||
use libc::{c_int, c_void, size_t};
|
||||
|
||||
pub struct Regex {
|
||||
code: *mut code,
|
||||
@@ -142,10 +142,10 @@ impl fmt::Debug for Error {
|
||||
|
||||
// PCRE2 FFI. We only wrap the bits we need.
|
||||
|
||||
const PCRE2_UCP: uint32_t = 0x00020000;
|
||||
const PCRE2_UTF: uint32_t = 0x00080000;
|
||||
const PCRE2_NO_UTF_CHECK: uint32_t = 0x40000000;
|
||||
const PCRE2_JIT_COMPLETE: uint32_t = 0x00000001;
|
||||
const PCRE2_UCP: u32 = 0x00020000;
|
||||
const PCRE2_UTF: u32 = 0x00080000;
|
||||
const PCRE2_NO_UTF_CHECK: u32 = 0x40000000;
|
||||
const PCRE2_JIT_COMPLETE: u32 = 0x00000001;
|
||||
const PCRE2_ERROR_NOMATCH: c_int = -1;
|
||||
|
||||
type code = c_void;
|
||||
@@ -160,9 +160,9 @@ type match_context = c_void; // unused
|
||||
|
||||
extern "C" {
|
||||
fn pcre2_compile_8(
|
||||
pattern: *const uint8_t,
|
||||
pattern: *const u8,
|
||||
len: size_t,
|
||||
options: uint32_t,
|
||||
options: u32,
|
||||
error_code: *mut c_int,
|
||||
error_offset: *mut size_t,
|
||||
context: *mut compile_context,
|
||||
@@ -180,21 +180,21 @@ extern "C" {
|
||||
fn pcre2_get_ovector_pointer_8(match_data: *mut match_data)
|
||||
-> *mut size_t;
|
||||
|
||||
fn pcre2_jit_compile_8(code: *const code, options: uint32_t) -> c_int;
|
||||
fn pcre2_jit_compile_8(code: *const code, options: u32) -> c_int;
|
||||
|
||||
fn pcre2_jit_match_8(
|
||||
code: *const code,
|
||||
subject: *const uint8_t,
|
||||
subject: *const u8,
|
||||
length: size_t,
|
||||
startoffset: size_t,
|
||||
options: uint32_t,
|
||||
options: u32,
|
||||
match_data: *mut match_data,
|
||||
match_context: *mut match_context,
|
||||
) -> c_int;
|
||||
|
||||
fn pcre2_get_error_message_8(
|
||||
error_code: c_int,
|
||||
buf: *mut uint8_t,
|
||||
buf: *mut u8,
|
||||
buflen: size_t,
|
||||
) -> c_int;
|
||||
}
|
||||
|
||||
+1
-16
@@ -1,18 +1,3 @@
|
||||
extern crate docopt;
|
||||
extern crate libc;
|
||||
#[cfg(feature = "re-pcre1")]
|
||||
extern crate libpcre_sys;
|
||||
extern crate memmap;
|
||||
#[cfg(feature = "re-onig")]
|
||||
extern crate onig;
|
||||
#[cfg(any(feature = "re-rust", feature = "re-rust-bytes",))]
|
||||
extern crate regex;
|
||||
#[cfg(feature = "re-rust")]
|
||||
extern crate regex_syntax;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use std::fs::File;
|
||||
use std::str;
|
||||
|
||||
@@ -39,7 +24,7 @@ Options:
|
||||
-h, --help Show this usage message.
|
||||
";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Args {
|
||||
arg_pattern: String,
|
||||
arg_file: String,
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ use std::iter::repeat;
|
||||
use test::Bencher;
|
||||
|
||||
#[cfg(any(feature = "re-rust", feature = "re-rust-bytes"))]
|
||||
use RegexSet;
|
||||
use {Regex, Text};
|
||||
use crate::RegexSet;
|
||||
use crate::{Regex, Text};
|
||||
|
||||
#[cfg(not(feature = "re-onig"))]
|
||||
#[cfg(not(feature = "re-pcre1"))]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use test::Bencher;
|
||||
|
||||
use {Regex, Text};
|
||||
use crate::{Regex, Text};
|
||||
|
||||
// USAGE: dna!(name, pattern, count)
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use test::Bencher;
|
||||
|
||||
use {Regex, Text};
|
||||
use crate::{Regex, Text};
|
||||
|
||||
// USAGE: sherlock!(name, pattern, count)
|
||||
//
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// contributed by TeXitoi
|
||||
// contributed by BurntSushi
|
||||
|
||||
|
||||
|
||||
use std::io::{self, Read};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
// replacing them with a single linear scan. i.e., it re-implements
|
||||
// `replace_all`. As a result, this is around 25% faster. ---AG
|
||||
|
||||
|
||||
|
||||
use std::io::{self, Read};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
use std::io::{self, Read};
|
||||
|
||||
macro_rules! regex {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// contributed by TeXitoi
|
||||
// contributed by BurntSushi
|
||||
|
||||
|
||||
|
||||
use std::io::{self, Read};
|
||||
|
||||
macro_rules! regex {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// contributed by TeXitoi
|
||||
// contributed by BurntSushi
|
||||
|
||||
|
||||
|
||||
use std::io::{self, Read};
|
||||
|
||||
macro_rules! regex {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// contributed by TeXitoi
|
||||
// contributed by BurntSushi
|
||||
|
||||
|
||||
|
||||
use std::io::{self, Read};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
@@ -11,6 +11,7 @@ description = """
|
||||
A C API for Rust's regular expression library.
|
||||
"""
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "rure"
|
||||
|
||||
@@ -36,7 +36,7 @@ impl Error {
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.kind {
|
||||
ErrorKind::None => write!(f, "no error"),
|
||||
ErrorKind::Str(ref e) => e.fmt(f),
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
extern crate libc;
|
||||
extern crate regex;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod error;
|
||||
|
||||
@@ -9,10 +9,10 @@ documentation = "https://docs.rs/regex"
|
||||
homepage = "https://github.com/rust-lang/regex"
|
||||
description = "A tool useful for debugging regular expressions."
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
docopt = "1"
|
||||
regex = { version = "1.1", path = ".." }
|
||||
regex-syntax = { version = "0.6", path = "../regex-syntax" }
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
||||
+12
-19
@@ -1,10 +1,3 @@
|
||||
extern crate docopt;
|
||||
extern crate regex;
|
||||
extern crate regex_syntax as syntax;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use std::error;
|
||||
use std::io::{self, Write};
|
||||
use std::process;
|
||||
@@ -12,8 +5,8 @@ use std::result;
|
||||
|
||||
use docopt::Docopt;
|
||||
use regex::internal::{Compiler, LiteralSearcher};
|
||||
use crate::syntax::hir::literal::Literals;
|
||||
use crate::syntax::hir::Hir;
|
||||
use regex_syntax::hir::literal::Literals;
|
||||
use regex_syntax::hir::Hir;
|
||||
|
||||
const USAGE: &'static str = "
|
||||
Usage:
|
||||
@@ -54,7 +47,7 @@ Options:
|
||||
--quiet Show less output.
|
||||
";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(serde::Deserialize)]
|
||||
struct Args {
|
||||
cmd_ast: bool,
|
||||
cmd_hir: bool,
|
||||
@@ -127,7 +120,7 @@ fn run(args: &Args) -> Result<()> {
|
||||
}
|
||||
|
||||
fn cmd_ast(args: &Args) -> Result<()> {
|
||||
use crate::syntax::ast::parse::Parser;
|
||||
use regex_syntax::ast::parse::Parser;
|
||||
|
||||
let mut parser = Parser::new();
|
||||
let ast = parser.parse(&args.arg_pattern)?;
|
||||
@@ -136,7 +129,7 @@ fn cmd_ast(args: &Args) -> Result<()> {
|
||||
}
|
||||
|
||||
fn cmd_hir(args: &Args) -> Result<()> {
|
||||
use crate::syntax::ParserBuilder;
|
||||
use regex_syntax::ParserBuilder;
|
||||
|
||||
let mut parser = ParserBuilder::new().allow_invalid_utf8(false).build();
|
||||
let hir = parser.parse(&args.arg_pattern)?;
|
||||
@@ -225,9 +218,9 @@ fn cmd_compile(args: &Args) -> Result<()> {
|
||||
}
|
||||
|
||||
fn cmd_utf8_ranges(args: &Args) -> Result<()> {
|
||||
use crate::syntax::hir::{self, HirKind};
|
||||
use crate::syntax::utf8::Utf8Sequences;
|
||||
use crate::syntax::ParserBuilder;
|
||||
use regex_syntax::hir::{self, HirKind};
|
||||
use regex_syntax::utf8::Utf8Sequences;
|
||||
use regex_syntax::ParserBuilder;
|
||||
|
||||
let hir = ParserBuilder::new()
|
||||
.build()
|
||||
@@ -258,9 +251,9 @@ fn cmd_utf8_ranges(args: &Args) -> Result<()> {
|
||||
}
|
||||
|
||||
fn cmd_utf8_ranges_rev(args: &Args) -> Result<()> {
|
||||
use crate::syntax::hir::{self, HirKind};
|
||||
use crate::syntax::utf8::Utf8Sequences;
|
||||
use crate::syntax::ParserBuilder;
|
||||
use regex_syntax::hir::{self, HirKind};
|
||||
use regex_syntax::utf8::Utf8Sequences;
|
||||
use regex_syntax::ParserBuilder;
|
||||
|
||||
let hir = ParserBuilder::new()
|
||||
.build()
|
||||
@@ -334,7 +327,7 @@ impl Args {
|
||||
}
|
||||
|
||||
fn parse(re: &str) -> Result<Hir> {
|
||||
use crate::syntax::ParserBuilder;
|
||||
use regex_syntax::ParserBuilder;
|
||||
ParserBuilder::new()
|
||||
.allow_invalid_utf8(true)
|
||||
.build()
|
||||
|
||||
@@ -8,6 +8,7 @@ documentation = "https://docs.rs/regex-syntax"
|
||||
homepage = "https://github.com/rust-lang/regex"
|
||||
description = "A regular expression parser."
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
# Features are documented in the "Crate features" section of the crate docs:
|
||||
# https://docs.rs/regex-syntax/*/#crate-features
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate regex_syntax;
|
||||
extern crate test;
|
||||
|
||||
use regex_syntax::Parser;
|
||||
|
||||
@@ -220,13 +220,13 @@ impl error::Error for Error {
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
crate::error::Formatter::from(self).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ErrorKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use self::ErrorKind::*;
|
||||
match *self {
|
||||
CaptureLimitExceeded => write!(
|
||||
@@ -328,7 +328,7 @@ pub struct Span {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Span {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Span({:?}, {:?})", self.start, self.end)
|
||||
}
|
||||
}
|
||||
@@ -361,7 +361,7 @@ pub struct Position {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Position {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Position(o: {:?}, l: {:?}, c: {:?})",
|
||||
@@ -542,7 +542,7 @@ impl Ast {
|
||||
/// This implementation uses constant stack space and heap space proportional
|
||||
/// to the size of the `Ast`.
|
||||
impl fmt::Display for Ast {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use crate::ast::print::Printer;
|
||||
Printer::new().print(self, f)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl Primitive {
|
||||
/// then return an error.
|
||||
fn into_class_set_item<P: Borrow<Parser>>(
|
||||
self,
|
||||
p: &ParserI<P>,
|
||||
p: &ParserI<'_, P>,
|
||||
) -> Result<ast::ClassSetItem> {
|
||||
use self::Primitive::*;
|
||||
use crate::ast::ClassSetItem;
|
||||
@@ -79,7 +79,7 @@ impl Primitive {
|
||||
/// dot), then return an error.
|
||||
fn into_class_literal<P: Borrow<Parser>>(
|
||||
self,
|
||||
p: &ParserI<P>,
|
||||
p: &ParserI<'_, P>,
|
||||
) -> Result<ast::Literal> {
|
||||
use self::Primitive::*;
|
||||
|
||||
@@ -2137,7 +2137,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
|
||||
/// A type that traverses a fully parsed Ast and checks whether its depth
|
||||
/// exceeds the specified nesting limit. If it does, then an error is returned.
|
||||
#[derive(Debug)]
|
||||
struct NestLimiter<'p, 's: 'p, P: 'p + 's> {
|
||||
struct NestLimiter<'p, 's, P> {
|
||||
/// The parser that is checking the nest limit.
|
||||
p: &'p ParserI<'s, P>,
|
||||
/// The current depth while walking an Ast.
|
||||
@@ -2357,21 +2357,24 @@ mod tests {
|
||||
str.to_string()
|
||||
}
|
||||
|
||||
fn parser(pattern: &str) -> ParserI<Parser> {
|
||||
fn parser(pattern: &str) -> ParserI<'_, Parser> {
|
||||
ParserI::new(Parser::new(), pattern)
|
||||
}
|
||||
|
||||
fn parser_octal(pattern: &str) -> ParserI<Parser> {
|
||||
fn parser_octal(pattern: &str) -> ParserI<'_, Parser> {
|
||||
let parser = ParserBuilder::new().octal(true).build();
|
||||
ParserI::new(parser, pattern)
|
||||
}
|
||||
|
||||
fn parser_nest_limit(pattern: &str, nest_limit: u32) -> ParserI<Parser> {
|
||||
fn parser_nest_limit(
|
||||
pattern: &str,
|
||||
nest_limit: u32,
|
||||
) -> ParserI<'_, Parser> {
|
||||
let p = ParserBuilder::new().nest_limit(nest_limit).build();
|
||||
ParserI::new(p, pattern)
|
||||
}
|
||||
|
||||
fn parser_ignore_whitespace(pattern: &str) -> ParserI<Parser> {
|
||||
fn parser_ignore_whitespace(pattern: &str) -> ParserI<'_, Parser> {
|
||||
let p = ParserBuilder::new().ignore_whitespace(true).build();
|
||||
ParserI::new(p, pattern)
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@ impl<'a> ClassInduct<'a> {
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for ClassFrame<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let x = match *self {
|
||||
ClassFrame::Union { .. } => "Union",
|
||||
ClassFrame::Binary { .. } => "Binary",
|
||||
@@ -490,7 +490,7 @@ impl<'a> fmt::Debug for ClassFrame<'a> {
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for ClassInduct<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let x = match *self {
|
||||
ClassInduct::Item(it) => match *it {
|
||||
ast::ClassSetItem::Empty(_) => "Item(Empty)",
|
||||
|
||||
@@ -52,7 +52,7 @@ impl error::Error for Error {
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
Error::Parse(ref x) => x.fmt(f),
|
||||
Error::Translate(ref x) => x.fmt(f),
|
||||
@@ -67,7 +67,7 @@ impl fmt::Display for Error {
|
||||
/// readable format. Most of its complexity is from interspersing notational
|
||||
/// markers pointing out the position where an error occurred.
|
||||
#[derive(Debug)]
|
||||
pub struct Formatter<'e, E: 'e> {
|
||||
pub struct Formatter<'e, E> {
|
||||
/// The original regex pattern in which the error occurred.
|
||||
pattern: &'e str,
|
||||
/// The error kind. It must impl fmt::Display.
|
||||
@@ -102,7 +102,7 @@ impl<'e> From<&'e hir::Error> for Formatter<'e, hir::ErrorKind> {
|
||||
}
|
||||
|
||||
impl<'e, E: fmt::Display> fmt::Display for Formatter<'e, E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let spans = Spans::from_formatter(self);
|
||||
if self.pattern.contains('\n') {
|
||||
let divider = repeat_char('~', 79);
|
||||
|
||||
@@ -60,7 +60,7 @@ impl<I: Interval> IntervalSet<I> {
|
||||
/// Return an iterator over all intervals in this set.
|
||||
///
|
||||
/// The iterator yields intervals in ascending order.
|
||||
pub fn iter(&self) -> IntervalSetIter<I> {
|
||||
pub fn iter(&self) -> IntervalSetIter<'_, I> {
|
||||
IntervalSetIter(self.ranges.iter())
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ impl<I: Interval> IntervalSet<I> {
|
||||
|
||||
/// An iterator over intervals.
|
||||
#[derive(Debug)]
|
||||
pub struct IntervalSetIter<'a, I: 'a>(slice::Iter<'a, I>);
|
||||
pub struct IntervalSetIter<'a, I>(slice::Iter<'a, I>);
|
||||
|
||||
impl<'a, I> Iterator for IntervalSetIter<'a, I> {
|
||||
type Item = &'a I;
|
||||
|
||||
@@ -838,7 +838,7 @@ fn alternate_literals<F: FnMut(&Hir, &mut Literals)>(
|
||||
}
|
||||
|
||||
impl fmt::Debug for Literals {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Literals")
|
||||
.field("lits", &self.lits)
|
||||
.field("limit_size", &self.limit_size)
|
||||
@@ -882,7 +882,7 @@ impl PartialOrd for Literal {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Literal {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.is_cut() {
|
||||
write!(f, "Cut({})", escape_unicode(&self.v))
|
||||
} else {
|
||||
@@ -1017,7 +1017,7 @@ mod tests {
|
||||
}
|
||||
|
||||
impl fmt::Debug for ULiteral {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.is_cut() {
|
||||
write!(f, "Cut({})", self.v)
|
||||
} else {
|
||||
|
||||
@@ -123,13 +123,13 @@ impl error::Error for Error {
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
crate::error::Formatter::from(self).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ErrorKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// TODO: Remove this on the next breaking semver release.
|
||||
#[allow(deprecated)]
|
||||
f.write_str(self.description())
|
||||
@@ -727,7 +727,7 @@ impl HirKind {
|
||||
/// This implementation uses constant stack space and heap space proportional
|
||||
/// to the size of the `Hir`.
|
||||
impl fmt::Display for Hir {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use crate::hir::print::Printer;
|
||||
Printer::new().print(self, f)
|
||||
}
|
||||
@@ -859,7 +859,7 @@ impl ClassUnicode {
|
||||
/// Return an iterator over all ranges in this class.
|
||||
///
|
||||
/// The iterator yields ranges in ascending order.
|
||||
pub fn iter(&self) -> ClassUnicodeIter {
|
||||
pub fn iter(&self) -> ClassUnicodeIter<'_> {
|
||||
ClassUnicodeIter(self.set.iter())
|
||||
}
|
||||
|
||||
@@ -972,7 +972,7 @@ pub struct ClassUnicodeRange {
|
||||
}
|
||||
|
||||
impl fmt::Debug for ClassUnicodeRange {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let start = if !self.start.is_whitespace() && !self.start.is_control()
|
||||
{
|
||||
self.start.to_string()
|
||||
@@ -1102,7 +1102,7 @@ impl ClassBytes {
|
||||
/// Return an iterator over all ranges in this class.
|
||||
///
|
||||
/// The iterator yields ranges in ascending order.
|
||||
pub fn iter(&self) -> ClassBytesIter {
|
||||
pub fn iter(&self) -> ClassBytesIter<'_> {
|
||||
ClassBytesIter(self.set.iter())
|
||||
}
|
||||
|
||||
@@ -1258,7 +1258,7 @@ impl ClassBytesRange {
|
||||
}
|
||||
|
||||
impl fmt::Debug for ClassBytesRange {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut debug = f.debug_struct("ClassBytesRange");
|
||||
if self.start <= 0x7F {
|
||||
debug.field("start", &(self.start as char));
|
||||
|
||||
@@ -1256,7 +1256,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn hir_uclass_query(query: ClassQuery) -> Hir {
|
||||
fn hir_uclass_query(query: ClassQuery<'_>) -> Hir {
|
||||
Hir::class(hir::Class::Unicode(unicode::class(query).unwrap()))
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct CaseFoldError(());
|
||||
impl error::Error for CaseFoldError {}
|
||||
|
||||
impl fmt::Display for CaseFoldError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Unicode-aware case folding is not available \
|
||||
@@ -58,7 +58,7 @@ pub struct UnicodeWordError(());
|
||||
impl error::Error for UnicodeWordError {}
|
||||
|
||||
impl fmt::Display for UnicodeWordError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Unicode-aware \\w class is not available \
|
||||
@@ -285,7 +285,7 @@ enum CanonicalClassQuery {
|
||||
|
||||
/// Looks up a Unicode class given a query. If one doesn't exist, then
|
||||
/// `None` is returned.
|
||||
pub fn class(query: ClassQuery) -> Result<hir::ClassUnicode> {
|
||||
pub fn class(query: ClassQuery<'_>) -> Result<hir::ClassUnicode> {
|
||||
use self::CanonicalClassQuery::*;
|
||||
|
||||
match query.canonicalize()? {
|
||||
|
||||
@@ -203,7 +203,7 @@ impl<'a> IntoIterator for &'a Utf8Sequence {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Utf8Sequence {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use self::Utf8Sequence::*;
|
||||
match *self {
|
||||
One(ref r) => write!(f, "{:?}", r),
|
||||
@@ -237,7 +237,7 @@ impl Utf8Range {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Utf8Range {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.start == self.end {
|
||||
write!(f, "[{:X}]", self.start)
|
||||
} else {
|
||||
@@ -331,7 +331,7 @@ struct ScalarRange {
|
||||
}
|
||||
|
||||
impl fmt::Debug for ScalarRange {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "ScalarRange({:X}, {:X})", self.start, self.end)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -4,9 +4,9 @@ use std::iter;
|
||||
use std::result;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::syntax::hir::{self, Hir};
|
||||
use crate::syntax::is_word_byte;
|
||||
use crate::syntax::utf8::{Utf8Range, Utf8Sequence, Utf8Sequences};
|
||||
use regex_syntax::hir::{self, Hir};
|
||||
use regex_syntax::is_word_byte;
|
||||
use regex_syntax::utf8::{Utf8Range, Utf8Sequence, Utf8Sequences};
|
||||
|
||||
use crate::prog::{
|
||||
EmptyLook, Inst, InstBytes, InstChar, InstEmptyLook, InstPtr, InstRanges,
|
||||
@@ -256,7 +256,7 @@ impl Compiler {
|
||||
/// instruction, and so no patch.entry value makes sense.
|
||||
fn c(&mut self, expr: &Hir) -> ResultOrEmpty {
|
||||
use crate::prog;
|
||||
use crate::syntax::hir::HirKind::*;
|
||||
use regex_syntax::hir::HirKind::*;
|
||||
|
||||
self.check_size()?;
|
||||
match *expr.kind() {
|
||||
@@ -554,7 +554,7 @@ impl Compiler {
|
||||
}
|
||||
|
||||
fn c_repeat(&mut self, rep: &hir::Repetition) -> ResultOrEmpty {
|
||||
use crate::syntax::hir::RepetitionKind::*;
|
||||
use regex_syntax::hir::RepetitionKind::*;
|
||||
match rep.kind {
|
||||
ZeroOrOne => self.c_repeat_zero_or_one(&rep.hir, rep.greedy),
|
||||
ZeroOrMore => self.c_repeat_zero_or_more(&rep.hir, rep.greedy),
|
||||
|
||||
+4
-4
@@ -5,9 +5,9 @@ use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "perf-literal")]
|
||||
use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind};
|
||||
use crate::syntax::hir::literal::Literals;
|
||||
use crate::syntax::hir::Hir;
|
||||
use crate::syntax::ParserBuilder;
|
||||
use regex_syntax::hir::literal::Literals;
|
||||
use regex_syntax::hir::Hir;
|
||||
use regex_syntax::ParserBuilder;
|
||||
|
||||
use crate::backtrack;
|
||||
use crate::compile::Compiler;
|
||||
@@ -1550,7 +1550,7 @@ impl ProgramCacheInner {
|
||||
/// literals, and if so, returns them. Otherwise, this returns None.
|
||||
#[cfg(feature = "perf-literal")]
|
||||
fn alternation_literals(expr: &Hir) -> Option<Vec<Vec<u8>>> {
|
||||
use crate::syntax::hir::{HirKind, Literal};
|
||||
use regex_syntax::hir::{HirKind, Literal};
|
||||
|
||||
// This is pretty hacky, but basically, if `is_alternation_literal` is
|
||||
// true, then we can make several assumptions about the structure of our
|
||||
|
||||
+2
-4
@@ -4,8 +4,6 @@ use std::fmt;
|
||||
use std::ops;
|
||||
use std::u32;
|
||||
|
||||
use crate::syntax;
|
||||
|
||||
use crate::literal::LiteralSearcher;
|
||||
use crate::prog::InstEmptyLook;
|
||||
use crate::utf8::{decode_last_utf8, decode_utf8};
|
||||
@@ -379,7 +377,7 @@ impl Char {
|
||||
// available. However, our compiler ensures that if a Unicode word
|
||||
// boundary is used, then the data must also be available. If it isn't,
|
||||
// then the compiler returns an error.
|
||||
char::from_u32(self.0).map_or(false, syntax::is_word_character)
|
||||
char::from_u32(self.0).map_or(false, regex_syntax::is_word_character)
|
||||
}
|
||||
|
||||
/// Returns true iff the byte is a word byte.
|
||||
@@ -387,7 +385,7 @@ impl Char {
|
||||
/// If the byte is absent, then false is returned.
|
||||
pub fn is_word_byte(self) -> bool {
|
||||
match char::from_u32(self.0) {
|
||||
Some(c) if c <= '\u{7F}' => syntax::is_word_byte(c as u8),
|
||||
Some(c) if c <= '\u{7F}' => regex_syntax::is_word_byte(c as u8),
|
||||
None | Some(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
+12
-22
@@ -22,12 +22,6 @@ used by adding `regex` to your dependencies in your project's `Cargo.toml`.
|
||||
regex = "1"
|
||||
```
|
||||
|
||||
If you're using Rust 2015, then you'll also need to add it to your crate root:
|
||||
|
||||
```rust
|
||||
extern crate regex;
|
||||
```
|
||||
|
||||
# Example: find a date
|
||||
|
||||
General use of regular expressions in this package involves compiling an
|
||||
@@ -68,9 +62,7 @@ regular expressions are compiled exactly once.
|
||||
For example:
|
||||
|
||||
```rust
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate regex;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
fn some_helper_function(text: &str) -> bool {
|
||||
@@ -94,7 +86,7 @@ matches. For example, to find all dates in a string and be able to access
|
||||
them by their component pieces:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap();
|
||||
let text = "2012-03-14, 2013-01-01 and 2014-07-05";
|
||||
@@ -119,7 +111,7 @@ clearer, we can *name* our capture groups and use those names as variables
|
||||
in our replacement text:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})").unwrap();
|
||||
let before = "2012-03-14, 2013-01-01 and 2014-07-05";
|
||||
@@ -136,7 +128,7 @@ Note that if your regex gets complicated, you can use the `x` flag to
|
||||
enable insignificant whitespace mode, which also lets you write comments:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"(?x)
|
||||
(?P<y>\d{4}) # the year
|
||||
@@ -217,7 +209,7 @@ Unicode scalar values. This means you can use Unicode characters directly
|
||||
in your expression:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"(?i)Δ+").unwrap();
|
||||
let mat = re.find("ΔδΔ").unwrap();
|
||||
@@ -244,7 +236,7 @@ of boolean properties are available as character classes. For example, you can
|
||||
match a sequence of numerals, Greek or Cherokee letters:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"[\pN\p{Greek}\p{Cherokee}]+").unwrap();
|
||||
let mat = re.find("abcΔᎠβⅠᏴγδⅡxyz").unwrap();
|
||||
@@ -391,7 +383,7 @@ Flags can be toggled within a pattern. Here's an example that matches
|
||||
case-insensitively for the first part but case-sensitively for the second part:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"(?i)a+(?-i)b+").unwrap();
|
||||
let cap = re.captures("AaAaAbbBBBb").unwrap();
|
||||
@@ -425,7 +417,7 @@ Here is an example that uses an ASCII word boundary instead of a Unicode
|
||||
word boundary:
|
||||
|
||||
```rust
|
||||
# extern crate regex; use regex::Regex;
|
||||
# use regex::Regex;
|
||||
# fn main() {
|
||||
let re = Regex::new(r"(?-u:\b).+(?-u:\b)").unwrap();
|
||||
let cap = re.captures("$$abc$$").unwrap();
|
||||
@@ -620,12 +612,10 @@ another matching engine with fixed memory requirements.
|
||||
#[cfg(not(feature = "std"))]
|
||||
compile_error!("`std` feature is currently required to build this crate");
|
||||
|
||||
#[cfg(feature = "perf-literal")]
|
||||
extern crate aho_corasick;
|
||||
|
||||
|
||||
extern crate regex_syntax as syntax;
|
||||
|
||||
// To check README's example
|
||||
// TODO: Re-enable this once the MSRV is 1.43 or greater.
|
||||
// See: https://github.com/rust-lang/regex/issues/684
|
||||
// See: https://github.com/rust-lang/regex/issues/685
|
||||
// #[cfg(doctest)]
|
||||
// doc_comment::doctest!("../README.md");
|
||||
|
||||
|
||||
+1
-2
@@ -1,9 +1,8 @@
|
||||
// use std::cmp;
|
||||
use std::mem;
|
||||
|
||||
use aho_corasick::{self, packed, AhoCorasick, AhoCorasickBuilder};
|
||||
use memchr::{memchr, memchr2, memchr3, memmem};
|
||||
use crate::syntax::hir::literal::{Literal, Literals};
|
||||
use regex_syntax::hir::literal::{Literal, Literals};
|
||||
|
||||
/// A prefix extracted from a compiled regular expression.
|
||||
///
|
||||
|
||||
+14
-14
@@ -133,7 +133,7 @@ impl Regex {
|
||||
/// bytes:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = b"I categorically deny having triskaidekaphobia.";
|
||||
/// assert!(Regex::new(r"\b\w{13}\b").unwrap().is_match(text));
|
||||
@@ -156,7 +156,7 @@ impl Regex {
|
||||
/// ASCII word bytes:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = b"I categorically deny having triskaidekaphobia.";
|
||||
/// let mat = Regex::new(r"\b\w{13}\b").unwrap().find(text).unwrap();
|
||||
@@ -177,7 +177,7 @@ impl Regex {
|
||||
/// word bytes:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = b"Retroactively relinquishing remunerations is reprehensible.";
|
||||
/// for mat in Regex::new(r"\b\w{13}\b").unwrap().find_iter(text) {
|
||||
@@ -205,7 +205,7 @@ impl Regex {
|
||||
/// year separately.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"'([^']+)'\s+\((\d{4})\)").unwrap();
|
||||
/// let text = b"Not my favorite movie: 'Citizen Kane' (1941).";
|
||||
@@ -227,7 +227,7 @@ impl Regex {
|
||||
/// We can make this example a bit clearer by using *named* capture groups:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
|
||||
/// .unwrap();
|
||||
@@ -271,7 +271,7 @@ impl Regex {
|
||||
/// some text, where the movie is formatted like "'Title' (xxxx)":
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use std::str; use regex::bytes::Regex;
|
||||
/// # use std::str; use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
|
||||
/// .unwrap();
|
||||
@@ -305,7 +305,7 @@ impl Regex {
|
||||
/// To split a string delimited by arbitrary amounts of spaces or tabs:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"[ \t]+").unwrap();
|
||||
/// let fields: Vec<&[u8]> = re.split(b"a b \t c\td e").collect();
|
||||
@@ -331,7 +331,7 @@ impl Regex {
|
||||
/// Get the first two words in some text:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"\W+").unwrap();
|
||||
/// let fields: Vec<&[u8]> = re.splitn(b"Hey! How are you?", 3).collect();
|
||||
@@ -379,7 +379,7 @@ impl Regex {
|
||||
/// In typical usage, this can just be a normal byte string:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new("[^01]+").unwrap();
|
||||
/// assert_eq!(re.replace(b"1078910", &b""[..]), &b"1010"[..]);
|
||||
@@ -392,7 +392,7 @@ impl Regex {
|
||||
/// group matches easily:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Captures; fn main() {
|
||||
/// let re = Regex::new(r"([^,\s]+),\s+(\S+)").unwrap();
|
||||
/// let result = re.replace(b"Springsteen, Bruce", |caps: &Captures| {
|
||||
@@ -411,7 +411,7 @@ impl Regex {
|
||||
/// with named capture groups:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)").unwrap();
|
||||
/// let result = re.replace(b"Springsteen, Bruce", &b"$first $last"[..]);
|
||||
@@ -428,7 +428,7 @@ impl Regex {
|
||||
/// underscore:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"(?P<first>\w+)\s+(?P<second>\w+)").unwrap();
|
||||
/// let result = re.replace(b"deep fried", &b"${first}_$second"[..]);
|
||||
@@ -445,7 +445,7 @@ impl Regex {
|
||||
/// byte string with `NoExpand`:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// use regex::bytes::NoExpand;
|
||||
///
|
||||
@@ -546,7 +546,7 @@ impl Regex {
|
||||
/// `a`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::bytes::Regex;
|
||||
/// # use regex::bytes::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = b"aaaaa";
|
||||
/// let pos = Regex::new(r"a+").unwrap().shortest_match(text);
|
||||
|
||||
+15
-16
@@ -7,7 +7,6 @@ use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::find_byte::find_byte;
|
||||
use crate::syntax;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::exec::{Exec, ExecNoSyncStr};
|
||||
@@ -20,7 +19,7 @@ use crate::re_trait::{self, RegularExpression, SubCapturesPosIter};
|
||||
/// The string returned may be safely used as a literal in a regular
|
||||
/// expression.
|
||||
pub fn escape(text: &str) -> String {
|
||||
syntax::escape(text)
|
||||
regex_syntax::escape(text)
|
||||
}
|
||||
|
||||
/// Match represents a single match of a regex in a haystack.
|
||||
@@ -189,7 +188,7 @@ impl Regex {
|
||||
/// Unicode word characters:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = "I categorically deny having triskaidekaphobia.";
|
||||
/// assert!(Regex::new(r"\b\w{13}\b").unwrap().is_match(text));
|
||||
@@ -212,7 +211,7 @@ impl Regex {
|
||||
/// Unicode word characters:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = "I categorically deny having triskaidekaphobia.";
|
||||
/// let mat = Regex::new(r"\b\w{13}\b").unwrap().find(text).unwrap();
|
||||
@@ -234,7 +233,7 @@ impl Regex {
|
||||
/// word characters:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = "Retroactively relinquishing remunerations is reprehensible.";
|
||||
/// for mat in Regex::new(r"\b\w{13}\b").unwrap().find_iter(text) {
|
||||
@@ -262,7 +261,7 @@ impl Regex {
|
||||
/// year separately.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"'([^']+)'\s+\((\d{4})\)").unwrap();
|
||||
/// let text = "Not my favorite movie: 'Citizen Kane' (1941).";
|
||||
@@ -284,7 +283,7 @@ impl Regex {
|
||||
/// We can make this example a bit clearer by using *named* capture groups:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
|
||||
/// .unwrap();
|
||||
@@ -328,7 +327,7 @@ impl Regex {
|
||||
/// some text, where the movie is formatted like "'Title' (xxxx)":
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
|
||||
/// .unwrap();
|
||||
@@ -361,7 +360,7 @@ impl Regex {
|
||||
/// To split a string delimited by arbitrary amounts of spaces or tabs:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"[ \t]+").unwrap();
|
||||
/// let fields: Vec<&str> = re.split("a b \t c\td e").collect();
|
||||
@@ -385,7 +384,7 @@ impl Regex {
|
||||
/// Get the first two words in some text:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"\W+").unwrap();
|
||||
/// let fields: Vec<&str> = re.splitn("Hey! How are you?", 3).collect();
|
||||
@@ -432,7 +431,7 @@ impl Regex {
|
||||
/// In typical usage, this can just be a normal string:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new("[^01]+").unwrap();
|
||||
/// assert_eq!(re.replace("1078910", ""), "1010");
|
||||
@@ -445,7 +444,7 @@ impl Regex {
|
||||
/// capturing group matches easily:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # use regex::Captures; fn main() {
|
||||
/// let re = Regex::new(r"([^,\s]+),\s+(\S+)").unwrap();
|
||||
/// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
|
||||
@@ -461,7 +460,7 @@ impl Regex {
|
||||
/// with named capture groups:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)").unwrap();
|
||||
/// let result = re.replace("Springsteen, Bruce", "$first $last");
|
||||
@@ -478,7 +477,7 @@ impl Regex {
|
||||
/// underscore:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let re = Regex::new(r"(?P<first>\w+)\s+(?P<second>\w+)").unwrap();
|
||||
/// let result = re.replace("deep fried", "${first}_$second");
|
||||
@@ -495,7 +494,7 @@ impl Regex {
|
||||
/// byte string with `NoExpand`:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// use regex::NoExpand;
|
||||
///
|
||||
@@ -605,7 +604,7 @@ impl Regex {
|
||||
/// `a`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate regex; use regex::Regex;
|
||||
/// # use regex::Regex;
|
||||
/// # fn main() {
|
||||
/// let text = "aaaaa";
|
||||
/// let pos = Regex::new(r"a+").unwrap().shortest_match(text);
|
||||
|
||||
Reference in New Issue
Block a user