github.com/richardwilkes/toolbox@v1.121.0/txt/rune_reader.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  package txt
    11  
    12  import "io"
    13  
    14  // RuneReader implements io.RuneReader
    15  type RuneReader struct {
    16  	Src []rune
    17  	Pos int
    18  }
    19  
    20  // ReadRune returns the next rune and its size in bytes.
    21  func (rr *RuneReader) ReadRune() (r rune, size int, err error) {
    22  	if rr.Pos >= len(rr.Src) {
    23  		return -1, 0, io.EOF
    24  	}
    25  	nextRune := rr.Src[rr.Pos]
    26  	rr.Pos++
    27  	return nextRune, 1, nil
    28  }