(&self, input: &str, encodings: Option<&[Encoding]>)
| 212 | } |
| 213 | |
| 214 | fn compute_encoding(&self, input: &str, encodings: Option<&[Encoding]>) -> Encoding { |
| 215 | let allow = |e: Encoding| encodings.map_or(true, |opts| opts.contains(&e)); |
| 216 | let statistics = self.compute_statistics(input); |
| 217 | if statistics.can_lower_special_encoded && allow(Encoding::LowerSpecial) { |
| 218 | return Encoding::LowerSpecial; |
| 219 | } |
| 220 | if statistics.can_lower_upper_digit_special_encoded { |
| 221 | if statistics.digit_count != 0 && allow(Encoding::LowerUpperDigitSpecial) { |
| 222 | return Encoding::LowerUpperDigitSpecial; |
| 223 | } |
| 224 | let upper_count: usize = statistics.upper_count; |
| 225 | if upper_count == 1 |
| 226 | && input.chars().next().unwrap().is_uppercase() |
| 227 | && allow(Encoding::FirstToLowerSpecial) |
| 228 | { |
| 229 | return Encoding::FirstToLowerSpecial; |
| 230 | } |
| 231 | if ((input.len() + upper_count) * 5) < (input.len() * 6) |
| 232 | && allow(Encoding::AllToLowerSpecial) |
| 233 | { |
| 234 | return Encoding::AllToLowerSpecial; |
| 235 | } |
| 236 | if allow(Encoding::LowerUpperDigitSpecial) { |
| 237 | return Encoding::LowerUpperDigitSpecial; |
| 238 | } |
| 239 | } |
| 240 | Encoding::Utf8 |
| 241 | } |
| 242 | |
| 243 | fn compute_statistics(&self, chars: &str) -> StringStatistics { |
| 244 | let mut can_lower_upper_digit_special_encoded = true; |
no test coverage detected