Struct spinoso_regexp::Source
source · pub struct Source { /* private fields */ }
Expand description
A Source
represents the literal contents used to construct a given
Regexp
.
When Regexp
s are constructed with a /.../
literal, Regexp#source
refers to the literal characters contained within the /
delimiters.
For example, /\t/.source.bytes
has byte sequence [92, 116]
.
When Regexp
s 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§
source§impl Source
impl Source
sourcepub const fn new() -> Self
pub const fn new() -> Self
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());
sourcepub const fn with_pattern_and_options(
pattern: Vec<u8>,
options: Options
) -> Self
pub const fn with_pattern_and_options( pattern: Vec<u8>, options: Options ) -> Self
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");
sourcepub const fn is_casefold(&self) -> bool
pub const fn is_casefold(&self) -> bool
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());
sourcepub const fn is_literal(&self) -> bool
pub const fn is_literal(&self) -> bool
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 regarding capturing groups and report parse failures differently.
A source’s literal flag can only be set using Options::try_from_int
.
Trait Implementations§
source§impl Ord for Source
impl Ord for Source
source§impl PartialEq<Source> for Source
impl PartialEq<Source> for Source
source§impl PartialOrd<Source> for Source
impl PartialOrd<Source> for Source
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more