| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Text.Unicode |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides static methods that validate UTF-16 strings. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class Utf16 |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Validates that the value is well-formed UTF-16. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="value">The <see cref="ReadOnlySpan{T}"/> containing the UTF-16 input text to validate.</param> |
| | | 15 | | /// <returns><c>true</c> if <paramref name="value"/> is well-formed UTF-16, <c>false</c> otherwise.</returns> |
| | | 16 | | public static bool IsValid(ReadOnlySpan<char> value) => |
| | 0 | 17 | | Utf16Utility.GetIndexOfFirstInvalidUtf16Sequence(value) < 0; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Finds the index of the first invalid UTF-16 subsequence. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="value">The <see cref="ReadOnlySpan{T}"/> containing the UTF-16 input text to examine.</param> |
| | | 23 | | /// <returns>The index of the first invalid UTF-16 subsequence, or <c>-1</c> if the entire input is valid.</retu |
| | | 24 | | public static int IndexOfInvalidSubsequence(ReadOnlySpan<char> value) => |
| | 0 | 25 | | Utf16Utility.GetIndexOfFirstInvalidUtf16Sequence(value); |
| | | 26 | | } |
| | | 27 | | } |
| | | 28 | | |