#[repr(transparent)]pub struct Region { /* private fields */ }
Expand description
Represents a set of capture groups found in a search or match.
Implementations§
source§impl Region
impl Region
sourcepub fn with_capacity(capacity: usize) -> Region
pub fn with_capacity(capacity: usize) -> Region
Create a new region with a given capacity. This function allocates
a new region object as in Region::new
and resizes it to
contain at least capacity
regions.
Arguments
capacity
- the number of captures this region should be capable of storing without allocation.
sourcepub unsafe fn clone_from_raw(ptr: *mut OnigRegion) -> Self
pub unsafe fn clone_from_raw(ptr: *mut OnigRegion) -> Self
Clone From Raw
Construct a new region based on an existing raw
*onig_sys::OnigRegion
pointer by copying.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
This can be used to clear out a region so it can be used
again. See onig_sys::onig_region_clear
sourcepub fn reserve(&mut self, new_capacity: usize)
pub fn reserve(&mut self, new_capacity: usize)
Updates the region to contain new_capacity
slots. See
onig_sys::onig_region_resize
for mor
information.
Arguments
new_capacity
- The new number of groups in the region.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the size of the region.
Returns the number of registers in the region.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the region is empty.
Returns true if there are no registers in the region.
sourcepub fn pos(&self, pos: usize) -> Option<(usize, usize)>
pub fn pos(&self, pos: usize) -> Option<(usize, usize)>
Returns the start and end positions of the Nth capture group.
Returns None
if pos
is not a valid capture group or if the
capture group did not match anything. The positions returned
are always byte indices with respect to the original string
matched.
sourcepub fn tree(&self) -> Option<&CaptureTreeNode>
pub fn tree(&self) -> Option<&CaptureTreeNode>
Get Capture Tree
Returns the capture tree for this region, if there is one.
sourcepub fn tree_traverse<F>(&self, callback: F) -> i32where
F: Fn(u32, (usize, usize), u32) -> bool,
pub fn tree_traverse<F>(&self, callback: F) -> i32where F: Fn(u32, (usize, usize), u32) -> bool,
Walk the Tree of Captures
The given callback is invoked for each node in the capture tree. Each node is passed to the callback before any children.
sourcepub fn tree_traverse_at<F>(&self, at: TraverseCallbackAt, callback: F) -> i32where
F: Fn(u32, (usize, usize), u32) -> bool,
pub fn tree_traverse_at<F>(&self, at: TraverseCallbackAt, callback: F) -> i32where F: Fn(u32, (usize, usize), u32) -> bool,
Walk the Tree of Captures in a Given Order
The given callback is invoked for each node in the capture tree. The order in which the callback is invoked can be chosen.