pub struct State { /* private fields */ }
Expand description
Container for Ruby VM-level Regexp engine state.
Using Regexp
s in Ruby code can set regexp global variables:
$~
is equivalent toRegexp.last_match
.$&
contains the complete matched text.$`
contains string before match.$'
contains string after match.$1
,$2
and so on contain text matching first, second, etc capture group.$+
contains last capture group.
This struct is used by the implementation of Regexp
in Artichoke’s Ruby
Core to track this global state.
Implementations§
Source§impl State
impl State
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Constructs a new, empty Regexp
state.
§Examples
use spinoso_regexp::State;
let state = State::new();
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Reset the state to empty.
§Examples
use spinoso_regexp::State;
let mut state = State::new();
state.clear();
Sourcepub const fn capture_group_globals(&self) -> usize
pub const fn capture_group_globals(&self) -> usize
Retrieve the count of currently active Regexp
capture group globals.
This count is used to track how many $1
, $2
, etc. variables are set
to non-nil values.
§Examples
use spinoso_regexp::State;
let mut state = State::new();
assert_eq!(state.capture_group_globals(), 0);
state.set_capture_group_globals(7);
assert_eq!(state.capture_group_globals(), 7);
Sourcepub fn set_capture_group_globals(&mut self, count: usize)
pub fn set_capture_group_globals(&mut self, count: usize)
Set the count of currently active Regexp
capture group globals.
This count is used to track how many $1
, $2
, etc. variables are set
to non-nil values.
§Examples
use spinoso_regexp::State;
let mut state = State::new();
assert_eq!(state.capture_group_globals(), 0);
state.set_capture_group_globals(7);
assert_eq!(state.capture_group_globals(), 7);
Trait Implementations§
Source§impl Ord for State
impl Ord for State
Source§impl PartialOrd for State
impl PartialOrd for State
impl Eq for State
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnwindSafe for State
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
Mutably borrows from an owned value. Read more