Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
navneetankur committed Oct 4, 2024
1 parent 2f9da67 commit 0f2e93e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
34 changes: 28 additions & 6 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,12 @@ impl Regex {
/// assert_eq!(&output, b"Hi john, wait you are not mike.");
/// # Ok(()) }; example().unwrap()
/// ```
pub fn substitute(&self, subject: &[u8], replacement: &[u8], output: &mut Vec<u8>) -> Result<usize, Error>{
pub fn substitute(
&self,
subject: &[u8],
replacement: &[u8],
output: &mut Vec<u8>,
) -> Result<usize, Error> {
self.code.substitute(subject, replacement, output, 0)
}
/// Replaces all the matches in `subject` with the `replacement`,
Expand All @@ -622,10 +627,19 @@ impl Regex {
/// assert_eq!(&output, b"Hi john, wait you are not john.");
/// # Ok(()) }; example().unwrap()
/// ```
pub fn substitute_all(&self, subject: &[u8], replacement: &[u8], output: &mut Vec<u8>) -> Result<usize, Error>{
self.code.substitute(subject, replacement, output, pcre2_sys::PCRE2_SUBSTITUTE_GLOBAL)
pub fn substitute_all(
&self,
subject: &[u8],
replacement: &[u8],
output: &mut Vec<u8>,
) -> Result<usize, Error> {
self.code.substitute(
subject,
replacement,
output,
pcre2_sys::PCRE2_SUBSTITUTE_GLOBAL,
)
}

}

/// Advanced or "lower level" search methods.
Expand Down Expand Up @@ -1425,7 +1439,11 @@ mod tests {
.unwrap();
let mut output = Vec::new();
re.substitute(hay.as_bytes(), b"42", &mut output).unwrap();
assert_eq!(&output, "012345678942abcdefghijklmnopqrst😀👍🏼🎉auvwxyzABCKLMNOPQRSTUVWXYZ".as_bytes());
assert_eq!(
&output,
"012345678942abcdefghijklmnopqrst😀👍🏼🎉auvwxyzABCKLMNOPQRSTUVWXYZ"
.as_bytes()
);
}
#[test]
fn test_substitute_all() {
Expand All @@ -1444,6 +1462,10 @@ mod tests {
.unwrap();
let mut output = Vec::new();
re.substitute_all(hay.as_bytes(), b"42", &mut output).unwrap();
assert_eq!(&output, "012345678942abcdefghijklmnopqrst42auvwxyzABCKLMNOPQRSTUVWXYZ".as_bytes());
assert_eq!(
&output,
"012345678942abcdefghijklmnopqrst42auvwxyzABCKLMNOPQRSTUVWXYZ"
.as_bytes()
);
}
}
8 changes: 7 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ impl Code {

/// Substitute the replacement pattern in subject and put the output in
/// output vec. Output vec is will be cleared before use.
pub(crate) fn substitute(&self, subject: &[u8], replacement: &[u8], output: &mut Vec<u8>, options: u32) -> Result<usize, Error>{
pub(crate) fn substitute(
&self,
subject: &[u8],
replacement: &[u8],
output: &mut Vec<u8>,
options: u32,
) -> Result<usize, Error> {
output.clear();
let mut output_length = output.capacity();
let mut rc = unsafe {
Expand Down

0 comments on commit 0f2e93e

Please sign in to comment.