singleRuneCountMismatch reports whether s and c agree on every rune class except one, where the disagreeing rune appears at least twice on one side.
(s, c string)
| 1387 | // class except one, where the disagreeing rune appears at least twice |
| 1388 | // on one side. |
| 1389 | func singleRuneCountMismatch(s, c string) (r rune, sCount, cCount int, ok bool) { |
| 1390 | if s == "" || c == "" { |
| 1391 | return 0, 0, 0, false |
| 1392 | } |
| 1393 | sFreq := runeFrequency(s) |
| 1394 | cFreq := runeFrequency(c) |
| 1395 | var ( |
| 1396 | diffRune rune |
| 1397 | diffCount int |
| 1398 | sc int |
| 1399 | cc int |
| 1400 | ) |
| 1401 | for rr, scv := range sFreq { |
| 1402 | ccv := cFreq[rr] |
| 1403 | if scv != ccv { |
| 1404 | diffCount++ |
| 1405 | diffRune = rr |
| 1406 | sc = scv |
| 1407 | cc = ccv |
| 1408 | } |
| 1409 | } |
| 1410 | for rr, ccv := range cFreq { |
| 1411 | if _, present := sFreq[rr]; present { |
| 1412 | continue |
| 1413 | } |
| 1414 | diffCount++ |
| 1415 | diffRune = rr |
| 1416 | sc = 0 |
| 1417 | cc = ccv |
| 1418 | } |
| 1419 | if diffCount != 1 { |
| 1420 | return 0, 0, 0, false |
| 1421 | } |
| 1422 | if sc < 2 && cc < 2 { |
| 1423 | return 0, 0, 0, false |
| 1424 | } |
| 1425 | return diffRune, sc, cc, true |
| 1426 | } |
| 1427 | |
| 1428 | // runeFrequency returns the count of each rune in s. |
| 1429 | func runeFrequency(s string) map[rune]int { |
no test coverage detected