github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/unicode/unicode.go (about) 1 // +build js 2 3 package unicode 4 5 func to(_case int, r rune, caseRange []CaseRange) (mappedRune rune, foundMapping bool) { 6 if _case < 0 || MaxCase <= _case { 7 return ReplacementChar, false 8 } 9 lo := 0 10 hi := len(caseRange) 11 for lo < hi { 12 m := lo + (hi-lo)/2 13 cr := &caseRange[m] // performance critical for GopherJS: get address here instead of copying the CaseRange 14 if rune(cr.Lo) <= r && r <= rune(cr.Hi) { 15 delta := rune(cr.Delta[_case]) 16 if delta > MaxRune { 17 return rune(cr.Lo) + ((r-rune(cr.Lo))&^1 | rune(_case&1)), true 18 } 19 return r + delta, true 20 } 21 if r < rune(cr.Lo) { 22 hi = m 23 } else { 24 lo = m + 1 25 } 26 } 27 return r, false 28 }