(input string, encodings []Encoding)
| 180 | } |
| 181 | |
| 182 | func (e *Encoder) ComputeEncodingWith(input string, encodings []Encoding) Encoding { |
| 183 | encodingFlags := make(map[Encoding]bool) |
| 184 | for _, enc := range encodings { |
| 185 | encodingFlags[enc] = true |
| 186 | } |
| 187 | // Special case for empty string: default to UTF_8 encoding |
| 188 | if len(input) == 0 { |
| 189 | return UTF_8 |
| 190 | } |
| 191 | statistics := e.computeStringStatistics(input) |
| 192 | if statistics.canLowerSpecialEncoded && encodingFlags[LOWER_SPECIAL] { |
| 193 | return LOWER_SPECIAL |
| 194 | } |
| 195 | if statistics.canLowerUpperDigitSpecialEncoded { |
| 196 | // Here, the string contains only letters, numbers, and two special symbols |
| 197 | if statistics.digitCount != 0 && encodingFlags[LOWER_UPPER_DIGIT_SPECIAL] { |
| 198 | return LOWER_UPPER_DIGIT_SPECIAL |
| 199 | } |
| 200 | upperCount := statistics.upperCount |
| 201 | chars := []byte(input) |
| 202 | if upperCount == 1 && chars[0] >= 'A' && chars[0] <= 'Z' && encodingFlags[FIRST_TO_LOWER_SPECIAL] { |
| 203 | return FIRST_TO_LOWER_SPECIAL |
| 204 | } |
| 205 | if (len(chars)+upperCount)*5 < len(chars)*6 && encodingFlags[ALL_TO_LOWER_SPECIAL] { |
| 206 | return ALL_TO_LOWER_SPECIAL |
| 207 | } |
| 208 | if encodingFlags[LOWER_UPPER_DIGIT_SPECIAL] { |
| 209 | return LOWER_UPPER_DIGIT_SPECIAL |
| 210 | } |
| 211 | } |
| 212 | return UTF_8 |
| 213 | } |
| 214 | |
| 215 | func isASCII(input string) bool { |
| 216 | for _, r := range input { |
no test coverage detected