github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/parse/read/range.go (about) 1 package read 2 3 import ( 4 "unicode" 5 "github.com/v2pro/plz/parse" 6 ) 7 8 func UnicodeRange(src *parse.Source, space []rune, table *unicode.RangeTable) []rune { 9 for { 10 r, n := src.PeekRune() 11 if unicode.Is(table, r) { 12 src.ConsumeN(n) 13 space = append(space, r) 14 continue 15 } 16 return space 17 } 18 } 19 20 func UnicodeRanges(src *parse.Source, space []rune, includes []*unicode.RangeTable, excludes []*unicode.RangeTable) []rune { 21 for { 22 r, n := src.PeekRune() 23 for _, exclude := range excludes { 24 if unicode.Is(exclude, r) { 25 return space 26 } 27 } 28 if len(includes) == 0 { 29 src.ConsumeN(n) 30 space = append(space, r) 31 continue 32 } 33 for _, include := range includes { 34 if unicode.Is(include, r) { 35 src.ConsumeN(n) 36 space = append(space, r) 37 continue 38 } 39 } 40 return space 41 } 42 }