Struct spinoso_regexp::Source[][src]

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

A Source represents the literal contents used to construct a given Regexp.

When Regexps are constructed with a /.../ literal, Regexp#source refers to the literal characters contained within the / delimeters. For example, /\t/.source.bytes has byte sequence [92, 116].

When Regexps are constructed with Regexp::compile, Regexp#source refers to the argument passed to compile. For example, Regexp.compile("\t").source.bytes has byte sequence [9].

Regexp#inspect prints "/#{source}/".

Implementations

Construct a new, empty Source.

Examples

use spinoso_regexp::Source;

const SOURCE: Source = Source::new();
assert!(SOURCE.pattern().is_empty());
assert!(SOURCE.options().as_display_modifier().is_empty());

Construct a new Source with the given pattern and Options.

Examples

use spinoso_regexp::{Options, Source};

let source = Source::with_pattern_and_options(
    b"Artichoke( Ruby)?".to_vec(),
    Options::with_ignore_case(),
);
assert_eq!(source.pattern(), b"Artichoke( Ruby)?");
assert_eq!(source.options().as_display_modifier(), "i");

Whether this source was parsed with ignore case enabled.

Examples

use spinoso_regexp::{Options, Source};

let source = Source::new();
assert!(!source.is_casefold());

let source = Source::with_pattern_and_options(
    b"Artichoke( Ruby)?".to_vec(),
    Options::with_ignore_case(),
);
assert!(source.is_casefold());

Whether the Regexp was parsed as a literal, e.g. '/artichoke/i.

This enables Ruby parsers to inject whether a Regexp is a literal to the core library. Literal Regexps have some special behavior regrding capturing groups and report parse failures differently.

A source’s literal flag can only be set using Options::try_from_int.

Extracts a slice containing the entire pattern.

Examples

use spinoso_regexp::{Options, Source};

let source = Source::with_pattern_and_options(
    b"Artichoke( Ruby)?".to_vec(),
    Options::with_ignore_case(),
);
assert_eq!(source.pattern(), b"Artichoke( Ruby)?");

Return a copy of the underlying Options.

Examples

use spinoso_regexp::{Options, Source};

let source = Source::with_pattern_and_options(
    b"Artichoke( Ruby)?".to_vec(),
    Options::with_ignore_case(),
);
assert_eq!(source.options().as_display_modifier(), "i");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.