Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[inline]
- fn is_valid(arg: &String) -> bool {
- static SCREENED_KEYWORDS: [&'static str; 4] = ["back to reddit", "8chan", "bit.ly", "goo.gl"];
- for word in arg.split_ascii_whitespace() {
- for keyword in SCREENED_KEYWORDS.iter() {
- if word.contains(keyword) {
- return false;
- }
- }
- for c in arg.chars() {
- // filter lenny
- // filter barille
- match c {
- '\u{2800}'..='\u{28FF}' | 'ʖ' => {
- return false;
- }
- _ => {}
- }
- }
- }
- true
- }
- fn sanitize(arg: &String) -> Option<String> {
- if is_valid(&arg) {
- return None;
- }
- let mut result = String::with_capacity(arg.len());
- // Trim leading whitespace
- // Trim trailing newlines
- // Trim unicodes (>= U+0370)
- for line in arg.split('\n') {
- for word in line.split_ascii_whitespace() {
- for character in word.chars() {
- match character {
- '\u{0000}' ..= '\u{0370}' => {result.push(character);},
- _ => {}
- }
- }
- }
- }
- return Some(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement