@@ -45,26 +45,32 @@ func (c *cache) registerConverter(value interface{}, converterFunc Converter) {
4545// var it pathIter
4646// for key, ok := it.start(path); ok; key, ok = it.advance() {}
4747type pathIter struct {
48- rest string
48+ rest string
49+ lastFound bool
4950}
5051
5152// start initializes the iteration, and returns the first key.
5253func (p * pathIter ) start (path string ) (string , bool ) {
53- return p .next (path )
54+ // init the iter for the first call to next, so that the first call will either
55+ // cut on "." and return the "before", or it will return path if it does not contain
56+ // ".".
57+ p .rest = path
58+ p .lastFound = true
59+ return p .next ()
5460}
5561
5662// advance advances the iteration to the next key.
5763func (p * pathIter ) advance () (string , bool ) {
58- return p .next (p . rest )
64+ return p .next ()
5965}
6066
61- // next should only be used by (*pathIter).start and (*pathIter).advance. it will cut path ,
67+ // next should only be used by (*pathIter).start and (*pathIter).advance. it will cut p.rest ,
6268// and return the "before", storing the "after" for the subsequent call.
63- // if path does not contain "." and is non-empty, it will return (path, true), storing "".
64- // if path is empty, it will return ("", false). this means the end of iteration.
65- func ( p * pathIter ) next ( path string ) ( key string , ok bool ) {
66- key , p . rest , _ = strings . Cut ( path , "." )
67- ok = key != ""
69+ func ( p * pathIter ) next () ( key string , ok bool ) {
70+ var found bool
71+ key , p . rest , found = strings . Cut ( p . rest , "." )
72+ ok = found || p . lastFound
73+ p . lastFound = found
6874 return key , ok
6975}
7076
0 commit comments