Esempio n. 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;
 }
        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);
        }
Esempio n. 3
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.Length);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void FromSpan_SuccessCase()
        {
            // Act
            var range = UnicodeRange.Create('\u0180', '\u024F'); // Latin Extended-B

            // Assert
            Assert.Equal(0x0180, range.FirstCodePoint);
            Assert.Equal(208, range.Length);
        }
Esempio n. 6
0
        public void FromSpan_SuccessCase_All()
        {
            // Act
            var range = UnicodeRange.Create('\u0000', '\uFFFF');

            // Assert
            Assert.Equal(0, range.FirstCodePoint);
            Assert.Equal(0x10000, range.Length);
        }
Esempio n. 7
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;
 }
Esempio n. 8
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.Length);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        /// <summary>
        /// Disallows all characters specified by <paramref name="range"/> through the filter.
        /// </summary>
        /// <returns>
        /// The 'this' instance.
        /// </returns>
        public CodePointFilter ForbidRange([NotNull] UnicodeRange range)
        {
            int firstCodePoint = range.FirstCodePoint;
            int rangeSize      = range.RangeSize;

            for (int i = 0; i < rangeSize; i++)
            {
                _allowedCharsBitmap.ForbidCharacter((char)(firstCodePoint + i));
            }
            return(this);
        }
Esempio n. 11
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.Length);

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

            Assert.Same(range, range2);
        }
Esempio n. 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);
        }
Esempio n. 13
0
        public void Range_Unicode(ushort first, ushort 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).GetRuntimeProperty(blockName);

            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.Length - 1);
        }
        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);
        }
Esempio n. 15
0
 public HtmlEncoder(UnicodeRange allowedRange) : this(new TextEncoderSettings(allowedRange))
 {
 }
Esempio n. 16
0
 public JavaScriptStringEncoder(UnicodeRange allowedRange) : this(new TextEncoderSettings(allowedRange))
 {
 }
Esempio n. 17
0
 public HtmlEncoder(UnicodeRange allowedRange) : this(new CodePointFilter(allowedRange))
 {
 }
Esempio n. 18
0
 public JavaScriptStringEncoder(UnicodeRange allowedRange) : this(new CodePointFilter(allowedRange))
 {
 }
Esempio n. 19
0
        public void FromSpan_FailureCase()
        {
            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => UnicodeRange.Create('\u0020', '\u0010'));

            Assert.Equal("lastCharacter", ex.ParamName);
        }
Esempio n. 20
0
 public void FromSpan_FailureCase()
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("lastCharacter", () => UnicodeRange.Create('\u0020', '\u0010'));
 }
        /// <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;
        }