// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System; namespace SixLabors.Fonts.Unicode { /// /// An enumerator for retrieving instances from a . /// Methods are pattern-matched by compiler to allow using foreach pattern. /// public ref struct SpanCodePointEnumerator { private ReadOnlySpan source; /// /// Initializes a new instance of the struct. /// /// The buffer to read from. public SpanCodePointEnumerator(ReadOnlySpan source) { this.source = source; this.Current = CodePoint.ReplacementChar; } /// /// Gets the element in the collection at the current position of the enumerator. /// public CodePoint Current { get; private set; } /// /// Returns an enumerator that iterates through the collection. /// /// An enumerator that iterates through the collection. public readonly SpanCodePointEnumerator GetEnumerator() => this; /// /// Advances the enumerator to the next element of the collection. /// /// /// if the enumerator was successfully advanced to the next element; /// if the enumerator has passed the end of the collection. /// public bool MoveNext() { this.Current = CodePoint.DecodeFromUtf16At(this.source, 0, out int consumed); this.source = this.source.Slice(consumed); return consumed > 0; } } }