func CharClass(negated bool, table *unicode.RangeTable) Matcher { var t unicode.RangeTable t.R16 = make([]unicode.Range16, len(table.R16)) copy(t.R16, table.R16) t.R32 = make([]unicode.Range32, len(table.R32)) copy(t.R32, table.R32) t.LatinOffset = table.LatinOffset return charClassMatcher{negated, t} }
func OneOf(chars ...rune) Matcher { if len(chars) == 0 { return Fail() } var t unicode.RangeTable sort.Sort(utf8betical(chars)) for _, ch := range chars { if ch >= 0x10000 { t.R32 = append(t.R32, unicode.Range32{Lo: uint32(ch), Hi: uint32(ch), Stride: 1}) } else { t.R16 = append(t.R16, unicode.Range16{Lo: uint16(ch), Hi: uint16(ch), Stride: 1}) if ch < 0x100 { t.LatinOffset += 1 } } } return charClassMatcher{false, t} }
func Range(lo, hi rune) Matcher { if lo > hi { return Fail() } var t unicode.RangeTable if lo >= 0x10000 { t.R32 = append(t.R32, unicode.Range32{Lo: uint32(lo), Hi: uint32(hi), Stride: 1}) } else if hi < 0x10000 { t.R16 = append(t.R16, unicode.Range16{Lo: uint16(lo), Hi: uint16(hi), Stride: 1}) if hi < 0x100 { t.LatinOffset = 1 } } else { t.R16 = append(t.R16, unicode.Range16{Lo: uint16(lo), Hi: 0xffff, Stride: 1}) t.R32 = append(t.R32, unicode.Range32{Lo: 0x10000, Hi: uint32(hi), Stride: 1}) } return charClassMatcher{false, t} }