skipper.go (878B)
1 package ini 2 3 // skipper is used to skip certain blocks of an ini file. 4 // Currently skipper is used to skip nested blocks of ini 5 // files. See example below 6 // 7 // [ foo ] 8 // nested = ; this section will be skipped 9 // a=b 10 // c=d 11 // bar=baz ; this will be included 12 type skipper struct { 13 shouldSkip bool 14 TokenSet bool 15 prevTok Token 16 } 17 18 func newSkipper() skipper { 19 return skipper{ 20 prevTok: emptyToken, 21 } 22 } 23 24 func (s *skipper) ShouldSkip(tok Token) bool { 25 // should skip state will be modified only if previous token was new line (NL); 26 // and the current token is not WhiteSpace (WS). 27 if s.shouldSkip && 28 s.prevTok.Type() == TokenNL && 29 tok.Type() != TokenWS { 30 s.Continue() 31 return false 32 } 33 34 s.prevTok = tok 35 return s.shouldSkip 36 } 37 38 func (s *skipper) Skip() { 39 s.shouldSkip = true 40 } 41 42 func (s *skipper) Continue() { 43 s.shouldSkip = false 44 s.prevTok = emptyToken 45 }