CodepointEnumerator.cs 958 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Avalonia.Utility;
  2. namespace Avalonia.Media.TextFormatting.Unicode
  3. {
  4. public ref struct CodepointEnumerator
  5. {
  6. private ReadOnlySlice<char> _text;
  7. public CodepointEnumerator(ReadOnlySlice<char> text)
  8. {
  9. _text = text;
  10. Current = Codepoint.ReplacementCodepoint;
  11. }
  12. /// <summary>
  13. /// Gets the current <see cref="Codepoint"/>.
  14. /// </summary>
  15. public Codepoint Current { get; private set; }
  16. /// <summary>
  17. /// Moves to the next <see cref="Codepoint"/>.
  18. /// </summary>
  19. /// <returns></returns>
  20. public bool MoveNext()
  21. {
  22. if (_text.IsEmpty)
  23. {
  24. Current = Codepoint.ReplacementCodepoint;
  25. return false;
  26. }
  27. Current = Codepoint.ReadAt(_text, 0, out var count);
  28. _text = _text.Skip(count);
  29. return true;
  30. }
  31. }
  32. }