MCPcopy Create free account
hub / github.com/dlclark/regexp2 / newStringByteMapper

Function newStringByteMapper

regexp.go:390–410  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

388}
389
390func newStringByteMapper(s string) *stringByteMapper {
391 var mapper *stringByteMapper
392 runeIndex := 0
393 delta := 0
394 for strIdx, ch := range s {
395 runeLen := utf8.RuneLen(ch)
396 if ch == utf8.RuneError {
397 _, runeLen = utf8.DecodeRuneInString(s[strIdx:])
398 }
399 if runeLen != 1 {
400 if mapper == nil {
401 mapper = &stringByteMapper{}
402 }
403 delta += runeLen - 1
404 mapper.runeIndexes = append(mapper.runeIndexes, runeIndex+1)
405 mapper.deltas = append(mapper.deltas, delta)
406 }
407 runeIndex++
408 }
409 return mapper
410}
411
412func (m *stringByteMapper) byteIndex(runeIndex int) int {
413 i := sort.Search(len(m.runeIndexes), func(i int) bool {

Callers 1

FindAllStringIndexMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected