コード例 #1
0
        /// <summary>
        /// Removes from the bitmap's allow list all code points which aren't mapped to defined characters
        /// or which are otherwise always disallowed.
        /// </summary>
        /// <remarks>
        /// Always-disallowed categories include Cc, Cs, Co, Cn, Zs [except U+0020 SPACE], Zl, and Zp.
        /// </remarks>
        public void ForbidUndefinedCharacters()
        {
            fixed(uint *pBitmap = Bitmap)
            {
                ReadOnlySpan <byte> definedCharsBitmapAsLittleEndian = UnicodeHelpers.GetDefinedBmpCodePointsBitmapLittleEndian();
                Span <uint>         thisAllowedCharactersBitmap      = new Span <uint>(pBitmap, BitmapLengthInDWords);

                Debug.Assert(definedCharsBitmapAsLittleEndian.Length == thisAllowedCharactersBitmap.Length * sizeof(uint));

#if NETCOREAPP
                if (Vector.IsHardwareAccelerated && BitConverter.IsLittleEndian)
                {
                    while (!definedCharsBitmapAsLittleEndian.IsEmpty)
                    {
                        (new Vector <uint>(definedCharsBitmapAsLittleEndian) & new Vector <uint>(thisAllowedCharactersBitmap)).CopyTo(thisAllowedCharactersBitmap);
                        definedCharsBitmapAsLittleEndian = definedCharsBitmapAsLittleEndian.Slice(Vector <byte> .Count);
                        thisAllowedCharactersBitmap      = thisAllowedCharactersBitmap.Slice(Vector <uint> .Count);
                    }
                    Debug.Assert(thisAllowedCharactersBitmap.IsEmpty, "Both vectors should've been fully consumed.");
                    return;
                }
#endif

                // Not Core, or not little-endian, or not SIMD-optimized.
                for (int i = 0; i < thisAllowedCharactersBitmap.Length; i++)
                {
                    thisAllowedCharactersBitmap[i] &= BinaryPrimitives.ReadUInt32LittleEndian(definedCharsBitmapAsLittleEndian.Slice(i * sizeof(uint)));
                }
            }
        }