コード例 #1
0
 [MethodImpl(MethodImplOptions.NoInlining)] // the caller should be inlined, not this method
 private static UnicodeRange CreateEmptyRange(ref UnicodeRange range)
 {
     // If the range hasn't been created, create it now.
     // It's ok if two threads race and one overwrites the other's 'range' value.
     var newRange = new UnicodeRange(0, 0);
     Volatile.Write(ref range, newRange);
     return newRange;
 }
コード例 #2
0
        public void Ctor_SuccessCase()
        {
            // Act
            var range = new UnicodeRange(0x0100, 128); // Latin Extended-A

            // Assert
            Assert.Equal(0x0100, range.FirstCodePoint);
            Assert.Equal(128, range.RangeSize);
        }
コード例 #3
0
 [MethodImpl(MethodImplOptions.NoInlining)] // the caller should be inlined, not this method
 private static UnicodeRange CreateRange(ref UnicodeRange range, char first, char last)
 {
     // If the range hasn't been created, create it now.
     // It's ok if two threads race and one overwrites the other's 'range' value.
     Debug.Assert(last > first, "Code points were specified out of order.");
     var newRange = UnicodeRange.FromSpan(first, last);
     Volatile.Write(ref range, newRange);
     return newRange;
 }
コード例 #4
0
        public void FromSpan_SuccessCase()
        {
            // Act
            var range = UnicodeRange.FromSpan('\u0180', '\u024F'); // Latin Extended-B

            // Assert
            Assert.Equal(0x0180, range.FirstCodePoint);
            Assert.Equal(208, range.RangeSize);
        }
コード例 #5
0
        public void FromSpan_SuccessCase_All()
        {
            // Act
            var range = UnicodeRange.FromSpan('\u0000', '\uFFFF');

            // Assert
            Assert.Equal(0, range.FirstCodePoint);
            Assert.Equal(0x10000, range.RangeSize);
        }
コード例 #6
0
        public void Ctor_SuccessCase()
        {
            // Act
            var range = new UnicodeRange(0x0100, 128); // Latin Extended-A

            // Assert
            Assert.Equal(0x0100, range.FirstCodePoint);
            Assert.Equal(128, range.RangeSize);
        }
コード例 #7
0
        [MethodImpl(MethodImplOptions.NoInlining)] // the caller should be inlined, not this method
        private static UnicodeRange CreateEmptyRange(ref UnicodeRange range)
        {
            // If the range hasn't been created, create it now.
            // It's ok if two threads race and one overwrites the other's 'range' value.
            var newRange = new UnicodeRange(0, 0);

            Volatile.Write(ref range, newRange);
            return(newRange);
        }
コード例 #8
0
        [MethodImpl(MethodImplOptions.NoInlining)] // the caller should be inlined, not this method
        private static UnicodeRange CreateRange(ref UnicodeRange range, char first, char last)
        {
            // If the range hasn't been created, create it now.
            // It's ok if two threads race and one overwrites the other's 'range' value.
            Debug.Assert(last > first, "Code points were specified out of order.");
            var newRange = UnicodeRange.FromSpan(first, last);

            Volatile.Write(ref range, newRange);
            return(newRange);
        }
コード例 #9
0
        public void Range_None()
        {
            UnicodeRange range = UnicodeRanges.None;

            Assert.NotNull(range);

            // Test 1: the range should be empty
            Assert.Equal(0, range.FirstCodePoint);
            Assert.Equal(0, range.RangeSize);

            // Test 2: calling the property multiple times should cache and return the same range instance
            UnicodeRange range2 = UnicodeRanges.None;

            Assert.Same(range, range2);
        }
コード例 #10
0
        /// <summary>
        /// Disallows all characters specified by <paramref name="range"/> through the filter.
        /// </summary>
        /// <returns>
        /// The 'this' instance.
        /// </returns>
        public CodePointFilter ForbidRange(UnicodeRange range)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            int firstCodePoint = range.FirstCodePoint;
            int rangeSize      = range.RangeSize;

            for (int i = 0; i < rangeSize; i++)
            {
                _allowedCharsBitmap.ForbidCharacter((char)(firstCodePoint + i));
            }
            return(this);
        }
コード例 #11
0
        public void Range_Unicode(char first, char last, string blockName)
        {
            Assert.Equal(0x0, first & 0xF); // first char in any block should be U+nnn0
            Assert.Equal(0xF, last & 0xF);  // last char in any block should be U+nnnF
            Assert.True(first < last);      // code point ranges should be ordered

            var propInfo = typeof(UnicodeRanges).GetProperty(blockName, BindingFlags.Public | BindingFlags.Static);

            Assert.NotNull(propInfo);

            UnicodeRange range = (UnicodeRange)propInfo.GetValue(null);

            Assert.NotNull(range);

            // Test 1: the range should span the range first..last
            Assert.Equal(first, range.FirstCodePoint);
            Assert.Equal(last, range.FirstCodePoint + range.RangeSize - 1);

            // Test 2: calling the property multiple times should cache and return the same range instance
            UnicodeRange range2 = (UnicodeRange)propInfo.GetValue(null);

            Assert.Same(range, range2);
        }
コード例 #12
0
        /// <summary>
        /// Disallows all characters specified by <paramref name="range"/> through the filter.
        /// </summary>
        /// <returns>
        /// The 'this' instance.
        /// </returns>
        public CodePointFilter ForbidRange(UnicodeRange range)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            int firstCodePoint = range.FirstCodePoint;
            int rangeSize = range.RangeSize;
            for (int i = 0; i < rangeSize; i++)
            {
                _allowedCharsBitmap.ForbidCharacter((char)(firstCodePoint + i));
            }
            return this;
        }
コード例 #13
0
        public void FromSpan_FailureCase()
        {
            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => UnicodeRange.FromSpan('\u0020', '\u0010'));

            Assert.Equal("lastChar", ex.ParamName);
        }