cleverbotfreeapi 0.1.2

Interact with a washed down version of the Cleverbot API for free
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};

macro_rules! remove_many {
    ($set:expr, [$($char:literal),*]) => {
      ($set$(.remove($char))*)  
    };
}

/// pythonic safe chars: `!#$%&'()*+,/:;=?@[]~`
const PYTHONIC_NON_ALPHANUMERIC: &AsciiSet = &remove_many!(
    NON_ALPHANUMERIC, 
    [b'!', b'#', b'$', b'%', b'&', b'\'', b'(', b')', b'*', b'+', b',', b'/', b':', b';', b'=', b'?', b'@', b'[', b']', b'~']
);

/// TIL that python's requests' `requests.utils.requote_uri(s)` uses "!#$%&'()*+,/:;=?@[]~" as safe chars, ok i guess
pub fn pythonic_encode(input: &str) -> String {
    utf8_percent_encode(input, PYTHONIC_NON_ALPHANUMERIC).to_string()
}