// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.Framework.WebEncoders { /// /// Represents a contiguous range of Unicode code points. /// /// /// Currently only the Basic Multilingual Plane is supported. /// public sealed class UnicodeRange { /// /// Creates a new . /// /// The first code point in the range. /// The number of code points in the range. public UnicodeRange(int firstCodePoint, int rangeSize) { // Parameter checking: the first code point and last code point must // lie within the BMP. See http://unicode.org/faq/blocks_ranges.html for more info. if (firstCodePoint < 0 || firstCodePoint > 0xFFFF) { throw new ArgumentOutOfRangeException(nameof(firstCodePoint)); } if (rangeSize < 0 || ((long)firstCodePoint + (long)rangeSize > 0x10000)) { throw new ArgumentOutOfRangeException(nameof(rangeSize)); } FirstCodePoint = firstCodePoint; RangeSize = rangeSize; } /// /// The first code point in this range. /// public int FirstCodePoint { get; } /// /// The number of code points in this range. /// public int RangeSize { get; } /// /// Creates a new from a span of characters. /// /// The first character in the range. /// The last character in the range. /// The representing this span. public static UnicodeRange FromSpan(char firstChar, char lastChar) { if (lastChar < firstChar) { throw new ArgumentOutOfRangeException(nameof(lastChar)); } return new UnicodeRange(firstChar, 1 + (int)(lastChar - firstChar)); } } }