utf8StrLen returns how many prefix bytes of s are valid UTF-8.
(s string)
| 396 | |
| 397 | // utf8StrLen returns how many prefix bytes of s are valid UTF-8. |
| 398 | func utf8StrLen(s string) int { |
| 399 | for i, r := range s { |
| 400 | for r == utf8.RuneError { |
| 401 | // The RuneError value can be an error |
| 402 | // sentinel value (if it's size 1) or the same |
| 403 | // value encoded properly. Decode it to see if |
| 404 | // it's the 1 byte sentinel value. |
| 405 | _, size := utf8.DecodeRuneInString(s[i:]) |
| 406 | if size == 1 { |
| 407 | return i |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | return len(s) |
| 412 | } |
| 413 | |
| 414 | func (ss *superset) SumPartsSize() (size uint64) { |
| 415 | for _, part := range ss.Parts { |
no outgoing calls