Skip to content

Commit

Permalink
LemmyNet#2900 : Added changes to slurs.rs which I forgot to add earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
ContemporaryArtwork committed Jun 17, 2023
1 parent f76b11d commit a13f87d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/utils/src/utils/slurs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ pub(crate) fn slur_check<'a>(
}
}

pub fn build_slur_regex(regex_str: Option<&str>) -> Option<Regex> {
regex_str.map(|slurs| {
RegexBuilder::new(slurs)
.case_insensitive(true)
.build()
.expect("compile regex")
})
fn build_lemmy_regex_compile_error(_e: regex::Error) -> LemmyError {
LemmyError::from_message("slur_regex_failed_to_compile")
}

pub fn build_slur_regex(regex_str: Option<&str>) -> Result<Regex, LemmyError> {
match regex_str {
Some(slurs) => {
let regex_result = RegexBuilder::new(slurs).case_insensitive(true).build();
regex_result.map_err(build_lemmy_regex_compile_error)
}
None => Err(LemmyError::from_message("input_slur_regex_was_not_present")),
}
}

pub fn check_slurs(text: &str, slur_regex: &Option<Regex>) -> Result<(), LemmyError> {
Expand Down

0 comments on commit a13f87d

Please sign in to comment.