github.com/aavshr/aws-sdk-go@v1.41.3/internal/ini/skipper.go (about)

     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  	s.prevTok = tok
    34  	return s.shouldSkip
    35  }
    36  
    37  func (s *skipper) Skip() {
    38  	s.shouldSkip = true
    39  }
    40  
    41  func (s *skipper) Continue() {
    42  	s.shouldSkip = false
    43  	// empty token is assigned as we return to default state, when should skip is false
    44  	s.prevTok = emptyToken
    45  }