github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/parse/skip/space.go (about) 1 package skip 2 3 import ( 4 "unicode" 5 "github.com/v2pro/plz/parse" 6 ) 7 8 func Space(src *parse.Source) int { 9 count := 0 10 for src.Error() == nil { 11 buf := src.Peek() 12 for i := 0; i < len(buf); i++ { 13 b := buf[i] 14 switch b { 15 case '\t', '\n', '\v', '\f', '\r', ' ': 16 count++ 17 continue 18 default: 19 src.ConsumeN(i) 20 return count 21 } 22 } 23 src.Consume() 24 } 25 return count 26 } 27 28 func UnicodeSpace(src *parse.Source) int { 29 count := 0 30 for src.Error() == nil { 31 r, n := src.PeekRune() 32 if unicode.IsSpace(r) { 33 src.ConsumeN(n) 34 count += n 35 continue 36 } 37 return count 38 } 39 return count 40 }