Some minor documentation touchups for libregex. Fixes #13800.
This commit is contained in:
parent
f5ead0dd66
commit
179fc6dbfd
|
@ -155,15 +155,16 @@
|
||||||
//! # Unicode
|
//! # Unicode
|
||||||
//!
|
//!
|
||||||
//! This implementation executes regular expressions **only** on sequences of
|
//! This implementation executes regular expressions **only** on sequences of
|
||||||
//! UTF8 codepoints while exposing match locations as byte indices.
|
//! Unicode code points while exposing match locations as byte indices into the
|
||||||
|
//! search string.
|
||||||
//!
|
//!
|
||||||
//! Currently, only naive case folding is supported. Namely, when matching
|
//! Currently, only naive case folding is supported. Namely, when matching
|
||||||
//! case insensitively, the characters are first converted to their uppercase
|
//! case insensitively, the characters are first converted to their uppercase
|
||||||
//! forms and then compared.
|
//! forms and then compared.
|
||||||
//!
|
//!
|
||||||
//! Regular expressions themselves are also **only** interpreted as a sequence
|
//! Regular expressions themselves are also **only** interpreted as a sequence
|
||||||
//! of UTF8 codepoints. This means you can embed Unicode characters directly
|
//! of Unicode code points. This means you can use Unicode characters
|
||||||
//! into your expression:
|
//! directly in your expression:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # #![feature(phase)]
|
//! # #![feature(phase)]
|
||||||
|
@ -229,10 +230,10 @@
|
||||||
//! x*? zero or more of x (ungreedy)
|
//! x*? zero or more of x (ungreedy)
|
||||||
//! x+? one or more of x (ungreedy)
|
//! x+? one or more of x (ungreedy)
|
||||||
//! x?? zero or one of x (ungreedy)
|
//! x?? zero or one of x (ungreedy)
|
||||||
//! x{n,m} at least n and at most x (greedy)
|
//! x{n,m} at least n x and at most m x (greedy)
|
||||||
//! x{n,} at least n x (greedy)
|
//! x{n,} at least n x (greedy)
|
||||||
//! x{n} exactly n x
|
//! x{n} exactly n x
|
||||||
//! x{n,m}? at least n and at most x (ungreedy)
|
//! x{n,m}? at least n x and at most m x (ungreedy)
|
||||||
//! x{n,}? at least n x (ungreedy)
|
//! x{n,}? at least n x (ungreedy)
|
||||||
//! x{n}? exactly n x
|
//! x{n}? exactly n x
|
||||||
//! </pre>
|
//! </pre>
|
||||||
|
@ -300,7 +301,7 @@
|
||||||
//! \v vertical tab (\x0B)
|
//! \v vertical tab (\x0B)
|
||||||
//! \123 octal character code (up to three digits)
|
//! \123 octal character code (up to three digits)
|
||||||
//! \x7F hex character code (exactly two digits)
|
//! \x7F hex character code (exactly two digits)
|
||||||
//! \x{10FFFF} any hex character code corresponding to a valid UTF8 codepoint
|
//! \x{10FFFF} any hex character code corresponding to a Unicode code point
|
||||||
//! </pre>
|
//! </pre>
|
||||||
//!
|
//!
|
||||||
//! ## Perl character classes (Unicode friendly)
|
//! ## Perl character classes (Unicode friendly)
|
||||||
|
@ -390,7 +391,7 @@ mod vm;
|
||||||
#[cfg(test, not(windows))]
|
#[cfg(test, not(windows))]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
/// The `program` module exists to support the `regex!` macro. Do not use.
|
/// The `native` module exists to support the `regex!` macro. Do not use.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod native {
|
pub mod native {
|
||||||
// Exporting this stuff is bad form, but it's necessary for two reasons.
|
// Exporting this stuff is bad form, but it's necessary for two reasons.
|
||||||
|
|
|
@ -18,8 +18,10 @@ use parse;
|
||||||
use vm;
|
use vm;
|
||||||
use vm::{CaptureLocs, MatchKind, Exists, Location, Submatches};
|
use vm::{CaptureLocs, MatchKind, Exists, Location, Submatches};
|
||||||
|
|
||||||
/// Escapes all regular expression meta characters in `text` so that it may be
|
/// Escapes all regular expression meta characters in `text`.
|
||||||
/// safely used in a regular expression as a literal string.
|
///
|
||||||
|
/// The string returned may be safely used as a literal in a regular
|
||||||
|
/// expression.
|
||||||
pub fn quote(text: &str) -> String {
|
pub fn quote(text: &str) -> String {
|
||||||
let mut quoted = String::with_capacity(text.len());
|
let mut quoted = String::with_capacity(text.len());
|
||||||
for c in text.chars() {
|
for c in text.chars() {
|
||||||
|
@ -45,9 +47,10 @@ pub fn is_match(regex: &str, text: &str) -> Result<bool, parse::Error> {
|
||||||
Regex::new(regex).map(|r| r.is_match(text))
|
Regex::new(regex).map(|r| r.is_match(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Regex is a compiled regular expression, represented as either a sequence
|
/// A compiled regular expression
|
||||||
/// of bytecode instructions (dynamic) or as a specialized Rust function
|
///
|
||||||
/// (native). It can be used to search, split
|
/// It is represented as either a sequence of bytecode instructions (dynamic)
|
||||||
|
/// or as a specialized Rust function (native). It can be used to search, split
|
||||||
/// or replace text. All searching is done with an implicit `.*?` at the
|
/// or replace text. All searching is done with an implicit `.*?` at the
|
||||||
/// beginning and end of an expression. To force an expression to match the
|
/// beginning and end of an expression. To force an expression to match the
|
||||||
/// whole string (or a prefix or a suffix), you must use an anchor like `^` or
|
/// whole string (or a prefix or a suffix), you must use an anchor like `^` or
|
||||||
|
@ -55,7 +58,7 @@ pub fn is_match(regex: &str, text: &str) -> Result<bool, parse::Error> {
|
||||||
///
|
///
|
||||||
/// While this crate will handle Unicode strings (whether in the regular
|
/// While this crate will handle Unicode strings (whether in the regular
|
||||||
/// expression or in the search text), all positions returned are **byte
|
/// expression or in the search text), all positions returned are **byte
|
||||||
/// indices**. Every byte index is guaranteed to be at a UTF8 codepoint
|
/// indices**. Every byte index is guaranteed to be at a Unicode code point
|
||||||
/// boundary.
|
/// boundary.
|
||||||
///
|
///
|
||||||
/// The lifetimes `'r` and `'t` in this crate correspond to the lifetime of a
|
/// The lifetimes `'r` and `'t` in this crate correspond to the lifetime of a
|
||||||
|
@ -189,7 +192,7 @@ impl Regex {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Find the start and end location of every word with exactly 13
|
/// Find the start and end location of the first word with exactly 13
|
||||||
/// characters:
|
/// characters:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -216,7 +219,7 @@ impl Regex {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Find the start and end location of the first word with exactly 13
|
/// Find the start and end location of every word with exactly 13
|
||||||
/// characters:
|
/// characters:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -577,8 +580,8 @@ impl<'t> Replacer for &'t str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Replacer for |&Captures|: 'a -> String {
|
impl<'t> Replacer for |&Captures|: 't -> String {
|
||||||
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
|
fn reg_replace<'a>(&'a mut self, caps: &Captures) -> MaybeOwned<'a> {
|
||||||
Owned((*self)(caps))
|
Owned((*self)(caps))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -823,8 +826,9 @@ impl<'t> Iterator<Option<(uint, uint)>> for SubCapturesPos<'t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator that yields all non-overlapping capture groups matching a
|
/// An iterator that yields all non-overlapping capture groups matching a
|
||||||
/// particular regular expression. The iterator stops when no more matches can
|
/// particular regular expression.
|
||||||
/// be found.
|
///
|
||||||
|
/// The iterator stops when no more matches can be found.
|
||||||
///
|
///
|
||||||
/// `'r` is the lifetime of the compiled expression and `'t` is the lifetime
|
/// `'r` is the lifetime of the compiled expression and `'t` is the lifetime
|
||||||
/// of the matched string.
|
/// of the matched string.
|
||||||
|
|
Loading…
Reference in New Issue