Struct fancy_regex::Expander[][src]

pub struct Expander { /* fields omitted */ }
Expand description

A set of options for expanding a template string using the contents of capture groups.

Implementations

impl Expander[src]

pub fn python() -> Expander[src]

Returns an expander that uses Python-compatible syntax.

Expands all instances of \num or \g<name> in replacement to the corresponding capture group num or name, and writes them to the dst buffer given.

name may be an integer corresponding to the index of the capture group (counted by order of opening parenthesis where \0 is the entire match) or it can be a name (consisting of letters, digits or underscores) corresponding to a named capture group.

num must be an integer corresponding to the index of the capture group.

If num or name isn’t a valid capture group (whether the name doesn’t exist or isn’t a valid index), then it is replaced with the empty string.

The longest possible number is used. e.g., \10 looks up capture group 10 and not capture group 1 followed by a literal 0.

To write a literal \, use \\.

pub fn check(&self, template: &str, regex: &Regex) -> Result<()>[src]

Checks template for errors. The following conditions are checked for:

  • A reference to a numbered group that does not exist in regex
  • A reference to a numbered group (other than 0) when regex contains named groups
  • A reference to a named group that does not occur in regex
  • An opening group name delimiter without a closing delimiter
  • Using an empty string as a group name

pub fn escape<'a>(&self, text: &'a str) -> Cow<'a, str>[src]

Escapes the substitution character in text so it appears literally in the output of expansion.

assert_eq!(
    fancy_regex::Expander::default().escape("Has a literal $ sign."),
    "Has a literal $$ sign.",
);

pub fn expansion(&self, template: &str, captures: &Captures<'_>) -> String[src]

Expands the template string template using the syntax defined by this expander and the values of capture groups from captures.

pub fn append_expansion(
    &self,
    dst: &mut String,
    template: &str,
    captures: &Captures<'_>
)
[src]

Appends the expansion produced by expansion to dst. Potentially more efficient than calling expansion directly and appending to an existing string.

pub fn write_expansion(
    &self,
    dst: impl Write,
    template: &str,
    captures: &Captures<'_>
) -> Result<()>
[src]

Writes the expansion produced by expansion to dst. Potentially more efficient than calling expansion directly and writing the result.

Trait Implementations

impl Debug for Expander[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Default for Expander[src]

fn default() -> Self[src]

Returns the default expander used by Captures::expand.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.