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
.
sourcepub fn pattern(&self) -> &[u8] ⓘ
pub fn pattern(&self) -> &[u8] ⓘ
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)?");
Trait Implementations§
source§impl Ord for Source
impl Ord for Source
source§impl PartialOrd for Source
impl PartialOrd for Source
impl Eq for Source
impl StructuralPartialEq for Source
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnwindSafe for Source
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)