Files

28 lines
1.2 KiB
C#
Raw Permalink Normal View History

2017-09-07 23:10:17 +02:00
using System.Collections;
using System.Collections.Generic;
namespace System.Unicode
{
2014-12-15 01:57:09 +01:00
/// <summary>Allows enumeration of the code points contained in an encapsulated string.</summary>
/// <remarks>
/// This enumerable will only allow enumeration of valid UTF-16 strings.
/// For incomplete or invalid UTF-16 strings, please use <see cref="PermissiveCodePointEnumerable"/> instead.
/// </remarks>
public struct CodePointEnumerable : IEnumerable<int>
{
2014-12-15 01:57:09 +01:00
/// <summary>Initializes a new instance of the struct <see cref="CodePointEnumerable"/>.</summary>
/// <param name="text">The string whose code points must be enumerated.</param>
2017-09-07 23:10:17 +02:00
public CodePointEnumerable(string text) => Text = text ?? throw new ArgumentNullException(nameof(text));
2014-12-15 01:57:09 +01:00
/// <summary>Gets the text whose code points are being enumerated.</summary>
2017-09-07 23:10:17 +02:00
public string Text { get; }
2014-12-15 01:57:09 +01:00
/// <summary>Gets an enumerator which can be used to enumerate the code points in the text.</summary>
2017-09-07 23:10:17 +02:00
public CodePointEnumerator GetEnumerator() => new CodePointEnumerator(Text);
2017-09-07 23:10:17 +02:00
IEnumerator<int> IEnumerable<int>.GetEnumerator() => GetEnumerator();
2017-09-07 23:10:17 +02:00
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}