pub struct Utf8 { /* private fields */ }
Implementations§
Source§impl Utf8
impl Utf8
Sourcepub fn with_literal_derived_encoding(
source: Source,
config: Config,
encoding: Encoding,
) -> Result<Self, Error>
pub fn with_literal_derived_encoding( source: Source, config: Config, encoding: Encoding, ) -> Result<Self, Error>
Construct a Regexp with a UTF-8 regex
backend.
The constructed regexp is Unicode aware. All character classes used in patterns other than POSIX character classes support all of Unicode.
Utf8
regexps require their patterns and haystacks to be valid UTF-8.
§Examples
let pattern = br"[[:alpha:]]\d+ \d+";
let source = Source::with_pattern_and_options(pattern.to_vec(), Options::default());
let config = Config::from(&source);
let regexp = Utf8::with_literal_derived_encoding(source, config, Encoding::None)?;
assert!(regexp.is_match("a123 १०೩೬".as_bytes(), None)?);
§Errors
If the pattern in the given source is not valid UTF-8, an
ArgumentError
is returned. If the given source pattern fails to
parse, either a SyntaxError
or RegexpError
is returned depending
on the source Options
.
Sourcepub fn captures<'a>(
&self,
haystack: &'a [u8],
) -> Result<Option<Captures<'a>>, Error>
pub fn captures<'a>( &self, haystack: &'a [u8], ) -> Result<Option<Captures<'a>>, Error>
§Errors
If the given haystack is not valid UTF-8, an error is returned.
pub fn capture_indices_for_name<'a, 'b>( &'a self, name: &'b [u8], ) -> CaptureIndices<'a, 'b>
Sourcepub fn captures_len(&self) -> usize
pub fn captures_len(&self) -> usize
Returns the number of captures.
Sourcepub fn capture_count_for_haystack(
&self,
haystack: &[u8],
) -> Result<usize, ArgumentError>
pub fn capture_count_for_haystack( &self, haystack: &[u8], ) -> Result<usize, ArgumentError>
The number of captures for a match of haystack
against this regexp.
Captures represents a group of captured strings for a single match.
If there is a match, the returned value is always greater than 0; the 0th capture always corresponds to the entire match.
§Errors
If the given haystack is not valid UTF-8, an error is returned.
Sourcepub fn entire_match<'a>(
&self,
haystack: &'a [u8],
) -> Result<Option<&'a [u8]>, Error>
pub fn entire_match<'a>( &self, haystack: &'a [u8], ) -> Result<Option<&'a [u8]>, Error>
Return the 0th capture group if haystack
is matched by this regexp.
The 0th capture always corresponds to the entire match.
§Errors
If the given haystack is not valid UTF-8, an error is returned.
Sourcepub fn named_captures(&self) -> NamedCaptures ⓘ
pub fn named_captures(&self) -> NamedCaptures ⓘ
Returns a hash representing information about the named captures of this
Regexp
.
A key of the hash is a name of the named captures. A value of the hash is an array which is list of indexes of corresponding named captures.
Sourcepub fn named_captures_for_haystack(
&self,
haystack: &[u8],
) -> Result<Option<NamedCapturesForHaystack>, Error>
pub fn named_captures_for_haystack( &self, haystack: &[u8], ) -> Result<Option<NamedCapturesForHaystack>, Error>
§Errors
If the given haystack is not valid UTF-8, an error is returned.
pub fn names(&self) -> Vec<Vec<u8>>
Sourcepub fn pos(
&self,
haystack: &[u8],
at: usize,
) -> Result<Option<(usize, usize)>, Error>
pub fn pos( &self, haystack: &[u8], at: usize, ) -> Result<Option<(usize, usize)>, Error>
§Errors
If the given haystack is not valid UTF-8, an error is returned.
Sourcepub fn is_match(&self, haystack: &[u8], pos: Option<i64>) -> Result<bool, Error>
pub fn is_match(&self, haystack: &[u8], pos: Option<i64>) -> Result<bool, Error>
Check whether this regexp matches the given haystack starting at an offset.
If the given offset is negative, it counts backward from the end of the haystack.
§Errors
If the given haystack is not valid UTF-8, an error is returned.