// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package utf8 implements functions and constants to support text encoded in // UTF-8. It includes functions to translate between runes and UTF-8 byte sequences. // See https://en.wikipedia.org/wiki/UTF-8 package utf8 type RuneIter struct { src []byte pos int32 start int32 r rune size int32 } func Iter(s []byte) RuneIter { return RuneIter{src: s} } func (it *RuneIter) Next() bool { if it.pos >= int32(len(it.src)) { return false } it.start = it.pos r, sz := DecodeRune(it.src[it.pos:]) it.r = r it.size = int32(sz) return true } func (it *RuneIter) Rune() rune { return it.r } func (it *RuneIter) Advance() { it.pos += it.size } func (it *RuneIter) Pos() int32 { return it.start } func (it *RuneIter) Size() int32 { return it.size }