CodepointEnumerator.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Avalonia.Utility;
  4. namespace Avalonia.Media.TextFormatting.Unicode
  5. {
  6. internal ref struct CodepointEnumerator
  7. {
  8. private ReadOnlySlice<char> _text;
  9. public CodepointEnumerator(ReadOnlySlice<char> text)
  10. {
  11. _text = text;
  12. Current = Codepoint.ReplacementCodepoint;
  13. }
  14. /// <summary>
  15. /// Gets the current <see cref="Codepoint"/>.
  16. /// </summary>
  17. public Codepoint Current { get; private set; }
  18. /// <summary>
  19. /// Moves to the next <see cref="Codepoint"/>.
  20. /// </summary>
  21. /// <returns></returns>
  22. public bool MoveNext()
  23. {
  24. if (_text.IsEmpty)
  25. {
  26. Current = Codepoint.ReplacementCodepoint;
  27. return false;
  28. }
  29. Current = Codepoint.ReadAt(_text, 0, out var count);
  30. _text = _text.Skip(count);
  31. return true;
  32. }
  33. }
  34. }