Advertisement
Guest User

Untitled

a guest
Aug 27th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.22 KB | None | 0 0
  1. #[inline]
  2. fn is_valid(arg: &String) -> bool {
  3.     static SCREENED_KEYWORDS: [&'static str; 4] = ["back to reddit", "8chan", "bit.ly", "goo.gl"];
  4.    for word in arg.split_ascii_whitespace() {
  5.        for keyword in SCREENED_KEYWORDS.iter() {
  6.            if word.contains(keyword) {
  7.                return false;
  8.            }
  9.        }
  10.        for c in arg.chars() {
  11.            // filter lenny
  12.            // filter barille
  13.            match c {
  14.                '\u{2800}'..='\u{28FF}' | 'ʖ' => {
  15.                    return false;
  16.                }
  17.                _ => {}
  18.            }
  19.        }
  20.    }
  21.    true
  22. }
  23.  
  24. fn sanitize(arg: &String) -> Option<String> {
  25.    if is_valid(&arg) {
  26.        return None;
  27.    }
  28.    let mut result = String::with_capacity(arg.len());
  29.  
  30.    // Trim leading whitespace
  31.    // Trim trailing newlines
  32.    // Trim unicodes (>= U+0370)
  33.    for line in arg.split('\n') {
  34.        for word in line.split_ascii_whitespace() {
  35.            for character in word.chars() {
  36.                match character {
  37.                    '\u{0000}' ..= '\u{0370}' => {result.push(character);},
  38.                    _ => {}
  39.                }
  40.            }
  41.        }
  42.    }
  43.  
  44.    return Some(result);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement