[−][src]Function sarcasm_utils::is_sarcasm
pub fn is_sarcasm(input: &str) -> IsSarcasm
Determines if input is SaRcAsM and what the case of the first letter is.
All non-alphanumeric characters will be ignored in the input. As a result, the SaRcAsM pattern only has to hold within groups of alphanumeric characters. This means the starting letter of any "secondary" alphanumeric groups can be any case.
While the encoder is well defined in the capitalization throughout the whole string, the decoder needs to be able to deal with many possible styles of writing SaRcAsM text.
Edge Cases
AbC DeF
andAbC dEf
-> SaRcAsM.Ab-Cd
andAb-cD
-> SaRcAsM.A
-> SaRcAsM.!!
-> Too Short (no alphanumeric characters to judge).A!A
andA!a
-> SaRcAsM.
Arguments
input
- String slice to check for SaRcAsM.
Return
IsSarcasm
dictating if the input text was SaRcAsM.
Examples
ⓘThis code runs with edition 2018
assert_matches!(is_sarcasm("AbC"), IsSarcasm::Yes(StartingCase::Uppercase)); assert_matches!(is_sarcasm("aBc"), IsSarcasm::Yes(StartingCase::Lowercase)); assert_matches!(is_sarcasm("Abc"), IsSarcasm::No); assert_matches!(is_sarcasm("aBC"), IsSarcasm::No); assert_matches!(is_sarcasm(""), IsSarcasm::TooShort); assert_matches!(is_sarcasm("!!"), IsSarcasm::TooShort);