Anti Inject XSS JavaScript/HTML/LDAP/XML/CSS Encode Inject


namespace ConsoleApplication
{
    using System;
    using Microsoft.Security.Application;
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public class Class1
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        //[STAThread]
        static void Main(string[] args)
        {
            //
            // TODO: 在此处添加代码以启动应用程序
            //
            string s = "alert('asdasdsa')";
            string ss = Encoder.JavaScriptEncode(s, false);
            Console.WriteLine(ss);
            Console.WriteLine(Environment.Version.ToString());
        }
    }
}
//Microsoft Web Protection Library
//http://wpl.codeplex.com/
namespace Microsoft.Security.Application.CodeCharts
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Lower.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides safe character positions for the lower section of the UTF code tables.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    /// <summary>
    /// Provides safe character positions for the lower section of the UTF code tables.
    /// </summary>
    internal static class Lower
    {
        /// <summary>
        /// Determines if the specified flag is set.
        /// </summary>
        /// <param name="flags">The value to check.</param>
        /// <param name="flagToCheck">The flag to check for.</param>
        /// <returns>true if the flag is set, otherwise false.</returns>
        public static bool IsFlagSet(LowerCodeCharts flags, LowerCodeCharts flagToCheck)
        {
            return (flags & flagToCheck) != 0;
        }
        /// <summary>
        /// Provides the safe characters for the Basic Latin code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable BasicLatin()
        {
            for (int i = 0x0020; i <= 0x007E; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Latin 1 Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Latin1Supplement()
        {
            for (int i = 0x00A1; i <= 0x00FF; i++)
            {
                if (i == 0x00AD)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Latin Extended A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable LatinExtendedA()
        {
            for (int i = 0x0100; i <= 0x17F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Latin Extended B code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable LatinExtendedB()
        {
            for (int i = 0x0180; i <= 0x024F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the IPA Extensions code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable IpaExtensions()
        {
            for (int i = 0x0250; i <= 0x2AF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Spacing Modifiers code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SpacingModifierLetters()
        {
            for (int i = 0x02B0; i <= 0x2FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Combining Diacritical Marks code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CombiningDiacriticalMarks()
        {
            for (int i = 0x0300; i <= 0x36F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Greek and Coptic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable GreekAndCoptic()
        {
            for (int i = 0x0370; i <= 0x03FF; i++)
            {
                if (i == 0x378 ||
                    i == 0x379 ||
                    (i >= 0x37F && i <= 0x383) ||
                    i == 0x38B ||
                    i == 0x38D ||
                    i == 0x3A2)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Cyrillic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Cyrillic()
        {
            for (int i = 0x0400; i <= 0x04FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Cyrillic Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CyrillicSupplement()
        {
            for (int i = 0x0500; i <= 0x0525; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Armenian code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>        
        public static IEnumerable Armenian()
        {
            for (int i = 0x0531; i <= 0x058A; i++)
            {
                if (i == 0x0557 ||
                    i == 0x0558 ||
                    i == 0x0560 ||
                    i == 0x0588)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hebrew code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Hebrew()
        {
            for (int i = 0x0591; i <= 0x05F4; i++)
            {
                if ((i >= 0x05C8 && i <= 0x05CF) ||
                    (i >= 0x05EB && i <= 0x05EF))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Arabic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Arabic()
        {
            for (int i = 0x0600; i <= 0x06FF; i++)
            {
                if (i == 0x0604 ||
                    i == 0x0605 ||
                    i == 0x061C ||
                    i == 0x061d ||
                    i == 0x0620 ||
                    i == 0x065F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Syriac code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Syriac()
        {
            for (int i = 0x0700; i <= 0x074F; i++)
            {
                if (i == 0x070E ||
                    i == 0x074B ||
                    i == 0x074C)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Arabic Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable ArabicSupplement()
        {
            for (int i = 0x0750; i <= 0x077F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Thaana code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Thaana()
        {
            for (int i = 0x0780; i <= 0x07B1; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Nko code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Nko()
        {
            for (int i = 0x07C0; i <= 0x07FA; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Samaritan code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Samaritan()
        {
            for (int i = 0x0800; i <= 0x083E; i++)
            {
                if (i == 0x082E ||
                    i == 0x082F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Devenagari code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Devanagari()
        {
            for (int i = 0x0900; i <= 0x097F; i++)
            {
                if (i == 0x093A ||
                    i == 0x093B ||
                    i == 0x094F ||
                    i == 0x0956 ||
                    i == 0x0957 ||
                    (i >= 0x0973 && i <= 0x0978))
                {
                    continue;
                }
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Bengali code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Bengali()
        {
            for (int i = 0x0981; i <= 0x09FB; i++)
            {
                if (i == 0x0984 ||
                    i == 0x098D || 
                    i == 0x098E ||
                    i == 0x0991 ||
                    i == 0x0992 ||
                    i == 0x09A9 || 
                    i == 0x09B1 ||
                    i == 0x09B3 ||
                    i == 0x09B4 ||
                    i == 0x09B5 ||
                    i == 0x09BA ||
                    i == 0x09BB ||
                    i == 0x09C5 ||
                    i == 0x09C6 ||
                    i == 0x09C9 ||
                    i == 0x09CA ||
                    (i >= 0x09CF && i <= 0x09D6) ||
                    (i >= 0x09D8 && i <= 0x09DB) ||
                    i == 0x09DE ||
                    i == 0x09E4 ||
                    i == 0x09E5)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Gurmukhi code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Gurmukhi()
        {
            for (int i = 0x0A01; i <= 0x0A75; i++)
            {
                if (i == 0x0A04 ||
                    (i >= 0x0A0B && i <= 0x0A0E) ||
                    i == 0x0A11 ||
                    i == 0x0A12 ||
                    i == 0x0A29 ||
                    i == 0x0A31 ||
                    i == 0x0A34 ||
                    i == 0x0A37 ||
                    i == 0x0A3A ||
                    i == 0x0A3B ||
                    i == 0x0A3D ||
                    (i >= 0x0A43 && i <= 0x0A46) ||
                    i == 0x0A49 ||
                    i == 0x0A4A ||
                    (i >= 0x0A4E && i <= 0x0A50) ||
                    (i >= 0x0A52 && i <= 0x0A58) ||
                    i == 0x0A5D ||
                    (i >= 0x0A5F && i <= 0x0A65))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Gujarati code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Gujarati()
        {
            for (int i = 0x0A81; i <= 0x0AF1; i++)
            {
                if (i == 0x0A84 ||
                    i == 0x0A8E ||
                    i == 0x0A92 ||
                    i == 0x0AA9 ||
                    i == 0x0AB1 ||
                    i == 0x0AB4 ||
                    i == 0x0ABA ||
                    i == 0x0ABB ||
                    i == 0x0AC6 ||
                    i == 0x0ACA ||
                    i == 0x0ACE ||
                    i == 0x0ACF ||
                    (i >= 0xAD1 && i <= 0x0ADF) ||
                    i == 0x0AE4 ||
                    i == 0x0AE5 ||
                    i == 0x0AF0)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Oriya code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Oriya()
        {
            for (int i = 0x0B01; i <= 0x0B71; i++)
            {
                if (i == 0x0B04 ||
                    i == 0x0B0D ||
                    i == 0x0B0E ||
                    i == 0x0B11 ||
                    i == 0x0B12 ||
                    i == 0x0B29 ||
                    i == 0x0B31 ||
                    i == 0x0B34 ||
                    i == 0x0B3A ||
                    i == 0x0B3B ||
                    i == 0x0B45 ||
                    i == 0x0B46 ||
                    i == 0x0B49 ||
                    i == 0x0B4A ||
                    (i >= 0x0B4E && i <= 0x0B55) ||
                    (i >= 0x0B58 && i <= 0x0B5B) ||
                    i == 0x0B5E ||
                    i == 0x0B64 ||
                    i == 0x0B65)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Tamil code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Tamil()
        {
            for (int i = 0x0B82; i <= 0x0BFA; i++)
            {
                if (i == 0x0B84 ||
                    i == 0x0B8B ||
                    i == 0x0B8C ||
                    i == 0x0B8D ||
                    i == 0x0B91 ||
                    i == 0x0B96 ||
                    i == 0x0B97 ||
                    i == 0x0B98 ||
                    i == 0x0B9B ||
                    i == 0x0B9D ||
                    i == 0x0BA0 ||
                    i == 0x0BA1 ||
                    i == 0x0BA2 ||
                    i == 0x0BA5 ||
                    i == 0x0BA6 ||
                    i == 0x0BA7 ||
                    i == 0x0BAB ||
                    i == 0x0BAC ||
                    i == 0x0BAD ||
                    (i >= 0x0BBA && i <= 0x0BBD) ||
                    i == 0x0BC3 ||
                    i == 0x0BC4 ||
                    i == 0x0BC5 ||
                    i == 0x0BC9 ||
                    i == 0x0BCE ||
                    i == 0x0BCF ||
                    (i >= 0x0BD1 && i <= 0x0BD6) ||                    
                    (i >= 0x0BD8 && i <= 0x0BE5))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Telugu code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Telugu()
        {
            for (int i = 0x0C01; i <= 0x0C7F; i++)
            {
                if (i == 0x0C04 ||
                    i == 0x0C0D ||
                    i == 0x0C11 ||
                    i == 0x0C29 ||
                    i == 0x0C34 ||
                    i == 0x0C3A ||
                    i == 0x0C3B ||
                    i == 0x0C3C ||
                    i == 0x0C45 ||
                    i == 0x0C49 ||
                    (i >= 0x0C4E && i <= 0x0C54) ||
                    i == 0x0C57 ||
                    (i >= 0x0C5A && i <= 0x0C5F) ||
                    i == 0x0C64 ||
                    i == 0x0C65 ||
                    (i >= 0x0C70 && i <= 0x0C77))
                {
                    continue;
                }
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Kannada code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>        
        public static IEnumerable Kannada()
        {
            for (int i = 0x0C82; i <= 0x0CF2; i++)
            {
                if (i == 0x0C84 ||
                    i == 0x0C8D || 
                    i == 0x0C91 ||
                    i == 0x0CA9 ||
                    i == 0x0CB4 ||
                    i == 0x0CBA ||
                    i == 0x0CBB ||
                    i == 0x0CC5 ||
                    i == 0x0CC9 || 
                    (i >= 0x0CCE && i <= 0x0CD4) ||
                    (i >= 0x0CD7 && i <= 0x0CDD) ||
                    i == 0x0CDF ||
                    i == 0x0CE4 ||
                    i == 0x0CE5 ||
                    i == 0x0CF0)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Malayalam code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Malayalam()
        {
            for (int i = 0x0D02; i <= 0x0D7F; i++)
            {
                if (i == 0x0D04 ||
                    i == 0x0D0D ||
                    i == 0x0D11 ||
                    i == 0x0D29 ||
                    i == 0x0D3A ||
                    i == 0x0D3B ||
                    i == 0x0D3C ||
                    i == 0x0D45 ||
                    i == 0x0D49 ||
                    (i >= 0x0D4E && i <= 0x0D56) ||
                    (i >= 0x0D58 && i <= 0x0D5F) ||
                    i == 0x0D64 ||
                    i == 0x0D65 ||
                    i == 0x0D76 ||
                    i == 0x0D77 ||
                    i == 0x0D78)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Sinhala code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Sinhala()
        {
            for (int i = 0x0D82; i <= 0x0DF4; i++)
            {
                if (i == 0x0D84 ||
                    i == 0x0D97 ||
                    i == 0X0D98 ||
                    i == 0x0D99 ||
                    i == 0x0DB2 ||
                    i == 0x0DBC ||
                    i == 0x0DBE ||
                    i == 0x0DBF ||
                    i == 0x0DC7 ||
                    i == 0x0DC8 ||
                    i == 0x0DC9 ||
                    (i >= 0x0DCB && i <= 0x0DCE) ||
                    i == 0x0DD5 ||
                    i == 0x0DD7 ||
                    (i >= 0x0DE0 && i <= 0x0DF1))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Thai code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Thai()
        {
            for (int i = 0x0E01; i <= 0x0E5B; i++)
            {
                if (i >= 0x0E3B && i <= 0x0E3E)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Lao code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Lao()
        {
            for (int i = 0x0E81; i <= 0x0EDD; i++)
            {
                if (i == 0x0E83 ||
                    i == 0x0E85 ||
                    i == 0x0E86 ||
                    i == 0x0E89 ||
                    i == 0x0E8B ||
                    i == 0x0E8C ||
                    (i >= 0x0E8E && i <= 0x0E93) ||
                    i == 0x0E98 ||
                    i == 0x0EA0 ||
                    i == 0x0EA4 ||
                    i == 0x0EA6 ||
                    i == 0x0EA8 ||
                    i == 0x0EA9 ||
                    i == 0x0EAC ||
                    i == 0x0EBA ||
                    i == 0x0EBE ||
                    i == 0x0EBF ||
                    i == 0x0EC5 ||
                    i == 0x0EC7 ||
                    i == 0x0ECE ||
                    i == 0x0ECF ||
                    i == 0x0EDA ||
                    i == 0x0EDB)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Tibetan code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Tibetan()
        {
            for (int i = 0x0F00; i <= 0x0FD8; i++)
            {
                if (i == 0x0F48 ||
                    (i >= 0x0F6D && i <= 0x0F70) ||
                    (i >= 0x0F8C && i <= 0x0F8F) ||
                    i == 0x0F98 ||
                    i == 0x0FBD ||
                    i == 0x0FCD)
                {
                    continue;
                }
                yield return i;
            }
        }
    }
}
namespace Microsoft.Security.Application.CodeCharts
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LowerMiddle.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides safe character positions for the lower middle section of the UTF code tables.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    /// <summary>
    /// Provides safe character positions for the lower middle section of the UTF code tables.
    /// </summary>
    internal static class LowerMiddle
    {
        /// <summary>
        /// Determines if the specified flag is set.
        /// </summary>
        /// <param name="flags">The value to check.</param>
        /// <param name="flagToCheck">The flag to check for.</param>
        /// <returns>true if the flag is set, otherwise false.</returns>
        public static bool IsFlagSet(LowerMidCodeCharts flags, LowerMidCodeCharts flagToCheck)
        {
            return (flags & flagToCheck) != 0;
        }
        /// <summary>
        /// Provides the safe characters for the Myanmar code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Myanmar()
        {
            for (int i = 0x1000; i <= 0x109F; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Georgian code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>        
        public static IEnumerable Georgian()
        {
            for (int i = 0x10A0; i <= 0x10FC; i++)
            {
                if (i >= 0x10C6 && i <= 0x10CF)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hangul Jamo code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable HangulJamo()
        {
            for (int i = 0x1100; i <= 0x11FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Ethiopic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable Ethiopic()
        {
            for (int i = 0x1200; i <= 0x137C; i++)
            {
                if (i == 0x1249 ||
                    i == 0x124E ||
                    i == 0x124F ||
                    i == 0x1257 ||
                    i == 0x1259 ||
                    i == 0x125E ||
                    i == 0x125F ||
                    i == 0x1289 ||
                    i == 0x128E ||
                    i == 0x128F ||
                    i == 0x12B1 ||
                    i == 0x12B6 ||
                    i == 0x12B7 ||
                    i == 0x12BF ||
                    i == 0x12C1 ||
                    i == 0x12C6 ||
                    i == 0x12C7 ||
                    i == 0x12D7 ||
                    i == 0x1311 ||
                    i == 0x1316 ||
                    i == 0x1317 ||
                    (i >= 0x135B && i <= 0x135E))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Ethiopic Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable EthiopicSupplement()
        {
            for (int i = 0x1380; i <= 0x1399; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Cherokee code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable Cherokee()
        {
            for (int i = 0x13A0; i <= 0x13F4; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Unified Canadian Aboriginal Syllabic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable UnifiedCanadianAboriginalSyllabics()
        {
            for (int i = 0x1400; i <= 0x167F; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Ogham code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Ogham()
        {
            for (int i = 0x1680; i <= 0x169C; i++)
            {
                yield return i;
            }              
        }
        /// <summary>
        /// Provides the safe characters for the Runic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Runic()
        {
            for (int i = 0x16A0; i <= 0x16F0; i++)
            {
                yield return i;
            }              
        }
        /// <summary>
        /// Provides the safe characters for the Tagalog code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Tagalog()
        {
            for (int i = 0x1700; i <= 0x1714; i++)
            {
                if (i == 0x170D)
                {
                    continue;
                }
                yield return i;
            }               
        }
        /// <summary>
        /// Provides the safe characters for the Hanunoo code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Hanunoo()
        {
            for (int i = 0x1720; i <= 0x1736; i++)
            {
                yield return i;
            }             
        }
        /// <summary>
        /// Provides the safe characters for the Buhid code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Buhid()
        {
            for (int i = 0x1740; i <= 0x1753; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Tagbanwa code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Tagbanwa()
        {
            for (int i = 0x1760; i <= 0x1773; i++)
            {
                if (i == 0x176D ||
                    i == 0x1771)
                {
                    continue;
                }
                yield return i;
            }                         
        }
        /// <summary>
        /// Provides the safe characters for the Khmer code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Khmer()
        {
            for (int i = 0x1780; i <= 0x17F9; i++)
            {
                if (i == 0x17DE ||
                    i == 0x17DF ||
                    (i >= 0x17EA && i <= 0x17EF))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Mongolian code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns> 
        public static IEnumerable Mongolian()
        {
            for (int i = 0x1800; i <= 0x18AA; i++)
            {
                if (i == 0x180F ||
                    (i >= 0x181A && i <= 0x181F) ||
                    (i >= 0x1878 && i <= 0x187F))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Unified Canadian Aboriginal Syllabic Extended code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable UnifiedCanadianAboriginalSyllabicsExtended()
        {
            for (int i = 0x18B0; i <= 0x18F5; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Limbu code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable Limbu()
        {
            for (int i = 0x1900; i <= 0x194F; i++)
            {
                if (i == 0x191D ||
                    i == 0x191E ||
                    i == 0x191F ||
                    (i >= 0x192C && i <= 0x192F) ||
                    (i >= 0x193C && i <= 0x193F) ||
                    i == 0x1941 ||
                    i == 0x1942 ||
                    i == 0x1943)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Tai Le code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable TaiLe()
        {
            for (int i = 0x1950; i <= 0x1974; i++)
            {
                if (i == 0x196E ||
                    i == 0x196F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the New Tai Lue code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>          
        public static IEnumerable NewTaiLue()
        {
            for (int i = 0x1980; i <= 0x19DF; i++)
            {
                if ((i >= 0x19AC && i <= 0x19AF) ||
                    (i >= 0x19CA && i <= 0x19CF) ||
                    (i >= 0x19DB && i <= 0x19DD))
                {
                    continue;
                }
                yield return i;            
            }
        }
        /// <summary>
        /// Provides the safe characters for the Khmer Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable KhmerSymbols()
        {
            for (int i = 0x19E0; i <= 0x19FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Khmer Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable Buginese()
        {
            for (int i = 0x1A00; i <= 0x1A1F; i++)
            {
                if (i == 0x1A1C ||
                    i == 0x1A1D)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Tai Tham code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable TaiTham()
        {
            for (int i = 0x1A20; i <= 0x1AAD; i++)
            {
                if (i == 0x1A5F ||
                    i == 0x1A7D ||
                    i == 0x1A7E ||
                    (i >= 0x1A8A && i <= 0x1A8F) ||
                    (i >= 0x1A9A && i <= 0x1A9F))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Balinese code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable Balinese()
        {
            for (int i = 0x1B00; i <= 0x1B7C; i++)
            {
                if (i >= 0x1B4C && i <= 0x1B4F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Sudanese code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable Sudanese()
        {
            for (int i = 0x1B80; i <= 0x1BB9; i++)
            {
                if (i >= 0x1BAB && i <= 0x1BAD)
                {
                    continue;
                }
                yield return i;                
            }
        }
        /// <summary>
        /// Provides the safe characters for the Lepcha code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>   
        public static IEnumerable Lepcha()
        {
            for (int i = 0x1C00; i <= 0x1C4F; i++)
            {
                if ((i >= 0x1C38 && i <= 0x1C3A) ||
                    (i >= 0x1C4A && i <= 0x1C4C))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Ol Chiki code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable OlChiki()
        {
            for (int i = 0x1C50; i <= 0x1C7F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Vedic Extensions code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable VedicExtensions()
        {
            for (int i = 0x1CD0; i <= 0x1CF2; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Phonetic Extensions code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable PhoneticExtensions()
        {
            for (int i = 0x1D00; i <= 0x1D7F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Phonetic Extensions Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable PhoneticExtensionsSupplement()
        {
            for (int i = 0x1D80; i <= 0x1DBF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Combining Diacritical Marks Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable CombiningDiacriticalMarksSupplement()
        {
            for (int i = 0x1DC0; i <= 0x1DFF; i++)
            {
                if (i >= 0x1DE7 && i <= 0x1DFC)
                {
                    continue;
                }
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Latin Extended Addition code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>  
        public static IEnumerable LatinExtendedAdditional()
        {
            for (int i = 0x1E00; i <= 0x1EFF; i++)
            {
                yield return i;
            }
        }
    }
}
namespace Microsoft.Security.Application.CodeCharts
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Middle.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides safe character positions for the lower middle section of the UTF code tables.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    /// <summary>
    /// Provides safe character positions for the middle section of the UTF code tables.
    /// </summary>
    internal static class Middle
    {
        /// <summary>
        /// Determines if the specified flag is set.
        /// </summary>
        /// <param name="flags">The value to check.</param>
        /// <param name="flagToCheck">The flag to check for.</param>
        /// <returns>true if the flag is set, otherwise false.</returns>
        public static bool IsFlagSet(MidCodeCharts flags, MidCodeCharts flagToCheck)
        {
            return (flags & flagToCheck) != 0;
        }
        /// <summary>
        /// Provides the safe characters for the Greek Extended code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable GreekExtended()
        {
            for (int i = 0x1F00; i <= 0x1FFE; i++)
            {
                if (i == 0x1F16 ||
                    i == 0x1F17 ||
                    i == 0x1F1E ||
                    i == 0x1F1F ||
                    i == 0x1F46 ||
                    i == 0x1F47 ||
                    i == 0x1F4E ||
                    i == 0x1F4F ||
                    i == 0x1F58 ||
                    i == 0x1F5A ||
                    i == 0x1F5C ||
                    i == 0x1F5E ||
                    i == 0x1F7E ||
                    i == 0x1F7F ||
                    i == 0x1FB5 ||
                    i == 0x1FC5 ||
                    i == 0x1FD4 ||
                    i == 0x1FD5 ||
                    i == 0x1FDC ||
                    i == 0x1FF0 ||
                    i == 0x1FF1 ||
                    i == 0x1FF5)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the General Punctuation code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable GeneralPunctuation()
        {
            for (int i = 0x2000; i <= 0x206F; i++)
            {
                if (i >= 0x2065 && i <= 0x2069)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Superscripts and subscripts code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SuperscriptsAndSubscripts()
        {
            for (int i = 0x2070; i <= 0x2094; i++)
            {
                if (i == 0x2072 ||
                    i == 0x2073 ||
                    i == 0x208F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Currency Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CurrencySymbols()
        {
            for (int i = 0x20A0; i <= 0x20B8; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Combining Diacritrical Marks for Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CombiningDiacriticalMarksForSymbols()
        {
            for (int i = 0x20D0; i <= 0x20F0; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Letterlike Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable LetterlikeSymbols()
        {
            for (int i = 0x2100; i <= 0x214F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Number Forms code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable NumberForms()
        {
            for (int i = 0x2150; i <= 0x2189; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Arrows code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Arrows()
        {
            for (int i = 0x2190; i <= 0x21FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Mathematical Operators code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MathematicalOperators()
        {
            for (int i = 0x2200; i <= 0x22FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Miscellaneous Technical code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MiscellaneousTechnical()
        {
            for (int i = 0x2300; i <= 0x23E8; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Control Pictures code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable ControlPictures()
        {
            for (int i = 0x2400; i <= 0x2426; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the OCR code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable OpticalCharacterRecognition()
        {
            for (int i = 0x2440; i <= 0x244A; i++)
            {
                yield return i;
            }        
        }
        /// <summary>
        /// Provides the safe characters for the Enclosed Alphanumerics code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable EnclosedAlphanumerics()
        {
            for (int i = 0x2460; i <= 0x24FF; i++)
            {
                yield return i;
            }                
        }
        /// <summary>
        /// Provides the safe characters for the Box Drawing code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable BoxDrawing()
        {
            for (int i = 0x2500; i <= 0x257F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Block Elements code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable BlockElements()
        {
            for (int i = 0x2580; i <= 0x259F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Geometric Shapes code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable GeometricShapes()
        {
            for (int i = 0x25A0; i <= 0x25FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Miscellaneous Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MiscellaneousSymbols()
        {
            for (int i = 0x2600; i <= 0x26FF; i++)
            {
                if (i == 0x26CE || 
                    i == 0x26E2 ||
                    (i >= 0x26E4 && i <= 0x26E7))
                {
                    continue;
                }
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Dingbats code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Dingbats()
        {
            for (int i = 0x2701; i <= 0x27BE; i++)
            {
                if (i == 0x2705 ||
                    i == 0x270A ||
                    i == 0x270B ||
                    i == 0x2728 ||
                    i == 0x274C ||
                    i == 0x274E ||
                    i == 0x2753 ||
                    i == 0x2754 ||
                    i == 0x2755 ||
                    i == 0x275F ||
                    i == 0x2760 ||
                    i == 0x2795 ||
                    i == 0x2796 ||
                    i == 0x2797 ||
                    i == 0x27B0)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Miscellaneous Mathematical Symbols A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MiscellaneousMathematicalSymbolsA()
        {
            for (int i = 0x27C0; i <= 0x27EF; i++)
            {
                if (i == 0x27CB ||
                    i == 0x27CD ||
                    i == 0x27CE ||
                    i == 0x27CF)
                {
                    continue;
                }
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Supplemental Arrows A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SupplementalArrowsA()
        {
            for (int i = 0x27F0; i <= 0x27FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Braille Patterns code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable BraillePatterns()
        {
            for (int i = 0x2800; i <= 0x28FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Supplemental Arrows B code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SupplementalArrowsB()
        {
            for (int i = 0x2900; i <= 0x297F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Miscellaneous Mathematical Symbols B code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MiscellaneousMathematicalSymbolsB()
        {
            for (int i = 0x2980; i <= 0x29FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Supplemental Mathematical Operators code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SupplementalMathematicalOperators()
        {
            for (int i = 0x2A00; i <= 0x2AFF; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Miscellaneous Symbols and Arrows code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MiscellaneousSymbolsAndArrows()
        {
            for (int i = 0x2B00; i <= 0x2B59; i++)
            {
                if (i == 0x2B4D || 
                    i == 0x2B4E ||
                    i == 0x2B4F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Glagolitic code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Glagolitic()
        {
            for (int i = 0x2C00; i <= 0x2C5E; i++)
            {
                if (i == 0x2C2F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Latin Extended C code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable LatinExtendedC()
        {
            for (int i = 0x2C60; i <= 0x2C7F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Coptic table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Coptic()
        {
            for (int i = 0x2C80; i <= 0x2CFF; i++)
            {
                if (i >= 0x2CF2 && i <= 0x2CF8)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Georgian Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable GeorgianSupplement()
        {
            for (int i = 0x2D00; i <= 0x2D25; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Tifinagh code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Tifinagh()
        {
            for (int i = 0x2D30; i <= 0x2D6F; i++)
            {
                if (i >= 0x2D66 && i <= 0x2D6E)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Ethiopic Extended code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable EthiopicExtended()
        {
            for (int i = 0x2D80; i <= 0x2DDE; i++)
            {
                if ((i >= 0x2D97 && i <= 0x2D9F) ||
                    i == 0x2DA7 ||
                    i == 0x2DAF ||
                    i == 0x2DB7 ||
                    i == 0x2DBF ||
                    i == 0x2DC7 ||
                    i == 0x2DCF ||
                    i == 0x2DD7 ||
                    i == 0x2DDF)
                {
                    continue;
                }
                yield return i;
            }
        }
    }
}
namespace Microsoft.Security.Application.CodeCharts
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Upper.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides safe character positions for the upper section of the UTF code tables.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    /// <summary>
    /// Provides safe character positions for the upper section of the UTF code tables.
    /// </summary>
    internal static class Upper
    {
        /// <summary>
        /// Determines if the specified flag is set.
        /// </summary>
        /// <param name="flags">The value to check.</param>
        /// <param name="flagToCheck">The flag to check for.</param>
        /// <returns>true if the flag is set, otherwise false.</returns>
        public static bool IsFlagSet(UpperCodeCharts flags, UpperCodeCharts flagToCheck)
        {
            return (flags & flagToCheck) != 0;
        }
        /// <summary>
        /// Provides the safe characters for the Devanagari Extended code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable DevanagariExtended()
        {
            for (int i = 0xA8E0; i <= 0xA8FB; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Kayah Li code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable KayahLi()
        {
            for (int i = 0xA900; i <= 0xA92F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Rejang code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Rejang()
        {
            for (int i = 0xA930; i <= 0xA953; i++)
            {
                yield return i;
            }
            yield return 0xA95F;
        }
        /// <summary>
        /// Provides the safe characters for the Hangul Jamo Extended A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable HangulJamoExtendedA()
        {
            for (int i = 0xA960; i <= 0xA97C; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Javanese code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Javanese()
        {
            for (int i = 0xA980; i <= 0xA9DF; i++)
            {
                if (i == 0xA9CE ||
                    (i >= 0xA9DA && i <= 0xA9DD))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Cham code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Cham()
        {
            for (int i = 0xAA00; i <= 0xAA5F; i++)
            {
                if ((i >= 0xAA37 && i <= 0xAA3F) ||
                    i == 0xAA4E ||
                    i == 0xAA4F ||
                    i == 0xAA5A ||
                    i == 0xAA5B)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Myanmar Extended A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MyanmarExtendedA()
        {
            for (int i = 0xAA60; i <= 0xAA7B; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Myanmar Extended A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable TaiViet()
        {
            for (int i = 0xAA80; i <= 0xAAC2; i++)
            {
                yield return i;
            }
            for (int i = 0xAADB; i <= 0xAADF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Meetei Mayek code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable MeeteiMayek()
        {
            for (int i = 0xABC0; i <= 0xABF9; i++)
            {
                if (i == 0xABEE ||
                    i == 0xABEF)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hangul Syllables code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable HangulSyllables()
        {
            for (int i = 0xAC00; i <= 0xD7A3; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hangul Jamo Extended B code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable HangulJamoExtendedB()
        {
            for (int i = 0xD7B0; i <= 0xD7FB; i++)
            {
                if (i == 0xD7C7 ||
                    i == 0xD7C8 ||
                    i == 0xD7C9 ||
                    i == 0xD7CA)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Compatibility Ideographs code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkCompatibilityIdeographs()
        {
            for (int i = 0xF900; i <= 0xFAD9; i++)
            {
                if (i == 0xFA2E ||
                    i == 0xFA2F ||
                    i == 0xFA6E ||
                    i == 0xFA6F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Alphabetic Presentation Forms code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable AlphabeticPresentationForms()
        {
            for (int i = 0xFB00; i <= 0xFB4F; i++)
            {
                if ((i >= 0xFB07 && i <= 0xFB12) ||
                    (i >= 0xFB18 && i <= 0xFB1C) ||
                    i == 0xFB37 ||
                    i == 0xFB3D ||
                    i == 0xFB3F ||
                    i == 0xFB42 ||
                    i == 0xFB45)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Arabic Presentation Forms A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable ArabicPresentationFormsA()
        {
            for (int i = 0xFB50; i <= 0xFDFD; i++)
            {
                if ((i >= 0xFBB2 && i <= 0xFBD2) || 
                    (i >= 0xFD40 && i <= 0xFD4F) ||
                    i == 0xFD90 ||
                    i == 0xFD91 ||
                    (i >= 0xFDC8 && i <= 0xFDEF))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Variation Selectors code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable VariationSelectors()
        {
            for (int i = 0xFE00; i <= 0xFE0F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Vertical Forms code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable VerticalForms()
        {
            for (int i = 0xFE10; i <= 0xFE19; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Combining Half Marks code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CombiningHalfMarks()
        {
            for (int i = 0xFE20; i <= 0xFE26; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Compatibility Forms code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkCompatibilityForms()
        {
            for (int i = 0xFE30; i <= 0xFE4F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Small Form Variants code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SmallFormVariants()
        {
            for (int i = 0xFE50; i <= 0xFE6B; i++)
            {
                if (i == 0xFE53 || i == 0xFE67)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Arabic Presentation Forms B code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable ArabicPresentationFormsB()
        {
            for (int i = 0xFE70; i <= 0xFEFC; i++)
            {
                if (i == 0xFE75)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Half Width and Full Width Forms code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable HalfWidthAndFullWidthForms()
        {
            for (int i = 0xFF01; i <= 0xFFEE; i++)
            {
                if (i == 0xFFBF ||
                    i == 0xFFC0 ||
                    i == 0xFFC1 ||
                    i == 0xFFC8 ||
                    i == 0xFFC9 ||
                    i == 0xFFD0 ||
                    i == 0xFFD1 ||
                    i == 0xFFD8 ||
                    i == 0xFFD9 ||
                    i == 0xFFDD ||
                    i == 0xFFDE ||
                    i == 0xFFDF ||
                    i == 0xFFE7)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Specials code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Specials()
        {
            for (int i = 0xFFF9; i <= 0xFFFD; i++)
            {
                yield return i;
            }
        }
    }
}
namespace Microsoft.Security.Application.CodeCharts
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UpperMiddle.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides safe character positions for the upper middle section of the UTF code tables.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    /// <summary>
    /// Provides safe character positions for the upper middle section of the UTF code tables.
    /// </summary>
    internal static class UpperMiddle
    {
        /// <summary>
        /// Determines if the specified flag is set.
        /// </summary>
        /// <param name="flags">The value to check.</param>
        /// <param name="flagToCheck">The flag to check for.</param>
        /// <returns>true if the flag is set, otherwise false.</returns>
        public static bool IsFlagSet(UpperMidCodeCharts flags, UpperMidCodeCharts flagToCheck)
        {
            return (flags & flagToCheck) != 0;
        }
        /// <summary>
        /// Provides the safe characters for the Cyrillic Extended A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CyrillicExtendedA()
        {
            for (int i = 0x2DE0; i <= 0x2DFF; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Cyrillic Extended A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SupplementalPunctuation()
        {
            for (int i = 0x2E00; i <= 0x2E31; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Radicals Supplement code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkRadicalsSupplement()
        {
            for (int i = 0x2E80; i <= 0x2EF3; i++)
            {
                if (i == 0x2E9A)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Kangxi Radicals code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable KangxiRadicals()
        {
            for (int i = 0x2F00; i <= 0x2FD5; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Ideographic Description Characters code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable IdeographicDescriptionCharacters()
        {
            for (int i = 0x2FF0; i <= 0x2FFB; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the CJK Symbols and Punctuation code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkSymbolsAndPunctuation()
        {
            for (int i = 0x3000; i <= 0x303F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hiragana code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Hiragana()
        {
            for (int i = 0x3041; i <= 0x309F; i++)
            {
                if (i == 0x3097 ||
                    i == 0x3098)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hiragana code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Katakana()
        {
            for (int i = 0x30A0; i <= 0x30FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Bopomofo code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Bopomofo()
        {
            for (int i = 0x3105; i <= 0x312D; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Hangul Compatibility Jamo code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable HangulCompatibilityJamo()
        {
            for (int i = 0x3131; i <= 0x318E; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Kanbun code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Kanbun()
        {
            for (int i = 0x3190; i <= 0x319F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Bopomofo Extended code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable BopomofoExtended()
        {
            for (int i = 0x31A0; i <= 0x31B7; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Strokes code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkStrokes()
        {
            for (int i = 0x31C0; i <= 0x31E3; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Katakana Phonetic Extensions code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable KatakanaPhoneticExtensions()
        {
            for (int i = 0x31F0; i <= 0x31FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Enclosed CJK Letters and Months code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable EnclosedCjkLettersAndMonths()
        {
            for (int i = 0x3200; i <= 0x32FE; i++)
            {
                if (i == 0x321F)
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Compatibility code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkCompatibility()
        {
            for (int i = 0x3300; i <= 0x33FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Unified Ideographs Extension A code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkUnifiedIdeographsExtensionA()
        {
            for (int i = 0x3400; i <= 0x4DB5; i++)
            {
                yield return i;
            }            
        }
        /// <summary>
        /// Provides the safe characters for the Yijing Hexagram Symbols code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable YijingHexagramSymbols()
        {
            for (int i = 0x4DC0; i <= 0x4DFF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the CJK Unified Ideographs code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CjkUnifiedIdeographs()
        {
            for (int i = 0x4E00; i <= 0x9FCB; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Yi Syllables code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable YiSyllables()
        {
            for (int i = 0xA000; i <= 0xA48C; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Yi Radicals code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable YiRadicals()
        {
            for (int i = 0xA490; i <= 0xA4C6; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Lisu code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Lisu()
        {
            for (int i = 0xA4D0; i <= 0xA4FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Vai code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Vai()
        {
            for (int i = 0xA500; i <= 0xA62B; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Cyrillic Extended B code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CyrillicExtendedB()
        {
            for (int i = 0xA640; i <= 0xA697; i++)
            {
                if (i == 0xA660 ||
                    i == 0xA661 ||
                    (i >= 0xA674 && i <= 0xA67b))
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Bamum code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Bamum()
        {
            for (int i = 0xA6A0; i <= 0xA6F7; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Modifier Tone Letters code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable ModifierToneLetters()
        {
            for (int i = 0xA700; i <= 0xA71F; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Latin Extended D code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable LatinExtendedD()
        {
            for (int i = 0xA720; i <= 0xA78C; i++)
            {
                yield return i;
            }
            for (int i = 0xA7FB; i <= 0xA7FF; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Syloti Nagri code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable SylotiNagri()
        {
            for (int i = 0xA800; i <= 0xA82B; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Common Indic Number Forms code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable CommonIndicNumberForms()
        {
            for (int i = 0xA830; i <= 0xA839; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Phags-pa code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Phagspa()
        {
            for (int i = 0xA840; i <= 0xA877; i++)
            {
                yield return i;
            }
        }
        /// <summary>
        /// Provides the safe characters for the Saurashtra code table.
        /// </summary>
        /// <returns>The safe characters for the code table.</returns>
        public static IEnumerable Saurashtra()
        {
            for (int i = 0xA880; i <= 0xA8D9; i++)
            {
                if (i >= 0xA8C5 && i <= 0xA8CD)
                {
                    continue;
                }
                yield return i;
            }
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CodeCharts.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Enumerations for the various printable code tables within the Unicode UTF space.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System;
    /// <summary>
    /// Values for the lowest section of the UTF8 Unicode code tables, from U0000 to U0FFF.
    /// </summary>
    [Flags]
    public enum LowerCodeCharts : long
    {
        /// <summary>
        /// No code charts from the lower region of the Unicode tables are safe-listed.
        /// </summary>
        None                                        = 0,
        /// <summary>
        /// The Basic Latin code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0000.pdf</remarks>
        BasicLatin                                  = 1 << 0x00,
        /// <summary>
        /// The C1 Controls and Latin-1 Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0080.pdf</remarks>
        C1ControlsAndLatin1Supplement               = 1 << 0x01,
        /// <summary>
        /// The Latin Extended-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0100.pdf</remarks>
        LatinExtendedA                              = 1 << 0x02,
        /// <summary>
        /// The Latin Extended-B code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0180.pdf</remarks>
        LatinExtendedB                              = 1 << 0x03,
        /// <summary>
        /// The IPA Extensions code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0250.pdf</remarks>
        IpaExtensions                               = 1 << 0x04,
        /// <summary>
        /// The Spacing Modifier Letters code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U02B0.pdf</remarks>
        SpacingModifierLetters                      = 1 << 0x05,
        /// <summary>
        /// The Combining Diacritical Marks code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0300.pdf</remarks>
        CombiningDiacriticalMarks                   = 1 << 0x06,        
        /// <summary>
        /// The Greek and Coptic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0370.pdf</remarks>
        GreekAndCoptic                              = 1 << 0x07,
        /// <summary>
        /// The Cyrillic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0400.pdf</remarks>
        Cyrillic                                    = 1 << 0x08,
        /// <summary>
        /// The Cyrillic Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0500.pdf</remarks>
        CyrillicSupplement                          = 1 << 0x09,
        /// <summary>
        /// The Armenian code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0530.pdf</remarks>
        Armenian                                    = 1 << 0x0A,
        /// <summary>
        /// The Hebrew code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0590.pdf</remarks>
        Hebrew                                      = 1 << 0x0B,
        /// <summary>
        /// The Arabic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0600.pdf</remarks>
        Arabic                                      = 1 << 0x0C,
        /// <summary>
        /// The Syriac code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0700.pdf</remarks>
        Syriac                                      = 1 << 0x0D,
        /// <summary>
        /// The Arabic Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0750.pdf</remarks>
        ArabicSupplement                            = 1 << 0x0E,
        /// <summary>
        /// The Thaana code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0780.pdf</remarks>
        Thaana                                      = 1 << 0x0F,
        /// <summary>
        /// The Nko code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U07C0.pdf</remarks>
        Nko                                         = 1 << 0x10,
        /// <summary>
        /// The Samaritan code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0800.pdf</remarks>
        Samaritan                                   = 1 << 0x11,
        /// <summary>
        /// The Devanagari code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0900.pdf</remarks>
        Devanagari                                  = 1 << 0x12,
        /// <summary>
        /// The Bengali code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0980.pdf</remarks>
        Bengali                                     = 1 << 0x13,
        /// <summary>
        /// The Gurmukhi code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0A00.pdf</remarks>
        Gurmukhi                                    = 1 << 0x14,
        /// <summary>
        /// The Gujarati code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0A80.pdf</remarks>
        Gujarati                                    = 1 << 0x15,
        /// <summary>
        /// The Oriya code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0B00.pdf</remarks>
        Oriya                                       = 1 << 0x16,
        /// <summary>
        /// The Tamil code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0B80.pdf</remarks>
        Tamil                                       = 1 << 0x17,
        /// <summary>
        /// The Telugu code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0C00.pdf</remarks>
        Telugu                                      = 1 << 0x18,
        /// <summary>
        /// The Kannada code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0C80.pdf</remarks>
        Kannada                                     = 1 << 0x19,
        /// <summary>
        /// The Malayalam code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0D00.pdf</remarks>
        Malayalam                                   = 1 << 0x1A,
        /// <summary>
        /// The Sinhala code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0D80.pdf</remarks>
        Sinhala                                     = 1 << 0x1B,
        /// <summary>
        /// The Thai code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0E00.pdf</remarks>
        Thai                                        = 1 << 0x1C,
        /// <summary>
        /// The Lao code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0E80.pdf</remarks>
        Lao                                         = 1 << 0x1D,
        /// <summary>
        /// The Tibetan code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U0F00.pdf</remarks>
        Tibetan                                     = 1 << 0x1E,
        /// <summary>
        /// The default code tables marked as safe on initialisation.
        /// </summary>
        Default = BasicLatin | C1ControlsAndLatin1Supplement | LatinExtendedA | LatinExtendedB | SpacingModifierLetters | IpaExtensions | CombiningDiacriticalMarks
    }
    /// <summary>
    /// Values for the lower-mid section of the UTF8 Unicode code tables, from U1000 to U1EFF.
    /// </summary>
    [Flags]
    public enum LowerMidCodeCharts : long
    {
        /// <summary>
        /// No code charts from the lower-mid region of the Unicode tables are safe-listed.
        /// </summary>
        None                                        = 0,
        /// <summary>
        /// The Myanmar code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1000.pdf</remarks>
        Myanmar                                      = 1 << 0x00,
        /// <summary>
        /// The Georgian code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U10A0.pdf</remarks>
        Georgian                                    = 1 << 0x01,
        /// <summary>
        /// The Hangul Jamo code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1100.pdf</remarks>
        HangulJamo                                  = 1 << 0x02,
        /// <summary>
        /// The Ethiopic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1200.pdf</remarks>
        Ethiopic                                    = 1 << 0x03,
        /// <summary>
        /// The Ethiopic supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1380.pdf</remarks>
        EthiopicSupplement                          = 1 << 0x04,
        /// <summary>
        /// The Cherokee code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U13A0.pdf</remarks>
        Cherokee                                    = 1 << 0x05,
        /// <summary>
        /// The Unified Canadian Aboriginal Syllabics code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1400.pdf</remarks>
        UnifiedCanadianAboriginalSyllabics          = 1 << 0x06,
        /// <summary>
        /// The Ogham code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1680.pdf</remarks>
        Ogham                                       = 1 << 0x07,
        /// <summary>
        /// The Runic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U16A0.pdf</remarks>
        Runic                                       = 1 << 0x08,
        /// <summary>
        /// The Tagalog code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1700.pdf</remarks>
        Tagalog                                     = 1 << 0x09,
        /// <summary>
        /// The Hanunoo code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1720.pdf</remarks>
        Hanunoo                                     = 1 << 0x0A,
        /// <summary>
        /// The Buhid code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1740.pdf</remarks>
        Buhid                                       = 1 << 0x0B,
        /// <summary>
        /// The Tagbanwa code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1760.pdf</remarks>
        Tagbanwa                                    = 1 << 0x0C,
        /// <summary>
        /// The Khmer code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1780.pdf</remarks>
        Khmer                                       = 1 << 0x0D,
        /// <summary>
        /// The Mongolian code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1800.pdf</remarks>
        Mongolian                                   = 1 << 0x0E,
        /// <summary>
        /// The Unified Canadian Aboriginal Syllabics Extended code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U18B0.pdf</remarks>
        UnifiedCanadianAboriginalSyllabicsExtended  = 1 << 0x0F,
        /// <summary>
        /// The Limbu code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1900.pdf</remarks>
        Limbu                                       = 1 << 0x10,
        /// <summary>
        /// The Tai Le code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1950.pdf</remarks>
        TaiLe                                       = 1 << 0x11,
        /// <summary>
        /// The New Tai Lue code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1980.pdf</remarks>
        NewTaiLue                                   = 1 << 0x12,
        /// <summary>
        /// The Khmer Symbols code table
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U19E0.pdf</remarks>
        KhmerSymbols                                = 1 << 0x13,
        /// <summary>
        /// The Buginese code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1A00.pdf</remarks>
        Buginese                                    = 1 << 0x14,
        /// <summary>
        /// The Tai Tham code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1A20.pdf</remarks>
        TaiTham                                     = 1 << 0x15,
        /// <summary>
        /// The Balinese code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1B00.pdf</remarks>
        Balinese                                    = 1 << 0x16,
        /// <summary>
        /// The Sudanese code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1B80.pdf</remarks>
        Sudanese                                    = 1 << 0x17,
        /// <summary>
        /// The Lepcha code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1C00.pdf</remarks>
        Lepcha                                      = 1 << 0x18,
        /// <summary>
        /// The Ol Chiki code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1C50.pdf</remarks>
        OlChiki                                     = 1 << 0x19,
        /// <summary>
        /// The Vedic Extensions code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1CD0.pdf</remarks>
        VedicExtensions                             = 1 << 0x1A,
        /// <summary>
        /// The Phonetic Extensions code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1D00.pdf</remarks>
        PhoneticExtensions                          = 1 << 0x1B,
        /// <summary>
        /// The Phonetic Extensions Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1D80.pdf</remarks>
        PhoneticExtensionsSupplement                = 1 << 0x1C,        
        /// <summary>
        /// The Combining Diacritical Marks Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1DC0.pdf</remarks>        
        CombiningDiacriticalMarksSupplement         = 1 << 0x1D,
        /// <summary>
        /// The Latin Extended Additional code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1E00.pdf</remarks>
        LatinExtendedAdditional                     = 1 << 0x0E
    }
    /// <summary>
    /// Values for the middle section of the UTF8 Unicode code tables, from U1F00 to U2DDF
    /// </summary>
    [Flags]
    public enum MidCodeCharts : long
    {
        /// <summary>
        /// No code charts from the lower region of the Unicode tables are safe-listed.
        /// </summary>
        None                                        = 0,
        /// <summary>
        /// The Greek Extended code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U1F00.pdf</remarks>
        GreekExtended                               = 1 << 0x00,
        /// <summary>
        /// The General Punctuation code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2000.pdf</remarks>
        GeneralPunctuation                          = 1 << 0x01,
        /// <summary>
        /// The Superscripts and Subscripts code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2070.pdf</remarks>
        SuperscriptsAndSubscripts                   = 1 << 0x02,
        /// <summary>
        /// The Currency Symbols code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U20A0.pdf</remarks>
        CurrencySymbols                             = 1 << 0x03,
        /// <summary>
        /// The Combining Diacritical Marks for Symbols code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U20D0.pdf</remarks>
        CombiningDiacriticalMarksForSymbols         = 1 << 0x04,
        /// <summary>
        /// The Letterlike Symbols code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2100.pdf</remarks>
        LetterlikeSymbols                           = 1 << 0x05,
        /// <summary>
        /// The Number Forms code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2150.pdf</remarks>
        NumberForms                                 = 1 << 0x06,
        /// <summary>
        /// The Arrows code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2190.pdf</remarks>
        Arrows                                      = 1 << 0x07,
        /// <summary>
        /// The Mathematical Operators code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2200.pdf</remarks>
        MathematicalOperators                       = 1 << 0x08,
        /// <summary>
        /// The Miscellaneous Technical code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2300.pdf</remarks>
        MiscellaneousTechnical                      = 1 << 0x09,
        /// <summary>
        /// The Control Pictures code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2400.pdf</remarks>
        ControlPictures                             = 1 << 0x0A,
        /// <summary>
        /// The Optical Character Recognition table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2440.pdf</remarks>
        OpticalCharacterRecognition                 = 1 << 0x0B,
        /// <summary>
        /// The Enclosed Alphanumeric code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2460.pdf</remarks>
        EnclosedAlphanumerics                       = 1 << 0x0C,
        /// <summary>
        /// The Box Drawing code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2500.pdf</remarks>
        BoxDrawing                                  = 1 << 0x0D,
        /// <summary>
        /// The Block Elements code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2580.pdf</remarks>
        BlockElements                               = 1 << 0x0E,
        /// <summary>
        /// The Geometric Shapes code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U25A0.pdf</remarks>
        GeometricShapes                             = 1 << 0x0F,
        /// <summary>
        /// The Miscellaneous Symbols code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2600.pdf</remarks>
        MiscellaneousSymbols                        = 1 << 0x10,
        /// <summary>
        /// The Dingbats code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2700.pdf</remarks>
        Dingbats                                    = 1 << 0x11,
        /// <summary>
        /// The Miscellaneous Mathematical Symbols-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U27C0.pdf</remarks>
        MiscellaneousMathematicalSymbolsA           = 1 << 0x12,
        /// <summary>
        /// The Supplemental Arrows-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U27F0.pdf</remarks>
        SupplementalArrowsA                         = 1 << 0x13,
        /// <summary>
        /// The Braille Patterns code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2800.pdf</remarks>
        BraillePatterns                             = 1 << 0x14,
        /// <summary>
        /// The Supplemental Arrows-B code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2900.pdf</remarks>
        SupplementalArrowsB                         = 1 << 0x15,
        /// <summary>
        /// The Miscellaneous Mathematical Symbols-B code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2980.pdf</remarks>                
        MiscellaneousMathematicalSymbolsB           = 1 << 0x16,
        /// <summary>
        /// The Supplemental Mathematical Operators code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2A00.pdf</remarks>
        SupplementalMathematicalOperators           = 1 << 0x17,
        /// <summary>
        /// The Miscellaneous Symbols and Arrows code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2B00.pdf</remarks>        
        MiscellaneousSymbolsAndArrows               = 1 << 0x18,
        /// <summary>
        /// The Glagolitic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2C00.pdf</remarks>
        Glagolitic                                  = 1 << 0x19,
        /// <summary>
        /// The Latin Extended-C code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2C60.pdf</remarks>        
        LatinExtendedC                              = 1 << 0x1A,
        /// <summary>
        /// The Coptic code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2C80.pdf</remarks>
        Coptic                                      = 1 << 0x1B,
        /// <summary>
        /// The Georgian Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2D00.pdf</remarks>
        GeorgianSupplement                          = 1 << 0x1C,
        /// <summary>
        /// The Tifinagh code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2D30.pdf</remarks>
        Tifinagh                                    = 1 << 0x1D,
        /// <summary>
        /// The Ethiopic Extended code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2D80.pdf</remarks>
        EthiopicExtended                            = 1 << 0x0E,    
    }
    /// <summary>
    /// Values for the upper middle section of the UTF8 Unicode code tables, from U2DE0 to UA8DF
    /// </summary>
    [Flags]
    public enum UpperMidCodeCharts : long
    {
        /// <summary>
        /// No code charts from the lower region of the Unicode tables are safe-listed.
        /// </summary>
        None                                        = 0,                  
        /// <summary>
        /// The Cyrillic Extended-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2DE0.pdf</remarks>
        CyrillicExtendedA                           = 1 << 0x00,
        /// <summary>
        /// The Supplemental Punctuation code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2E00.pdf</remarks>
        SupplementalPunctuation                     = 1 << 0x01,
        /// <summary>
        /// The CJK Radicials Supplement code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2E80.pdf</remarks>
        CjkRadicalsSupplement                       = 1 << 0x02,
        /// <summary>
        /// The Kangxi Radicials code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2F00.pdf</remarks>
        KangxiRadicals                              = 1 << 0x03,
        /// <summary>
        /// The Ideographic Description Characters code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U2FF0.pdf</remarks>
        IdeographicDescriptionCharacters            = 1 << 0x04,
        /// <summary>
        /// The CJK Symbols and Punctuation code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3000.pdf</remarks>
        CjkSymbolsAndPunctuation                    = 1 << 0x05,
        /// <summary>
        /// The Hiragana code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3040.pdf</remarks>
        Hiragana                                    = 1 << 0x06,
        /// <summary>
        /// The Katakana code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U30A0.pdf</remarks>
        Katakana                                    = 1 << 0x07,
        /// <summary>
        /// The Bopomofo code table.
        /// <seealso cref="BopomofoExtended"/>
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3100.pdf</remarks>
        Bopomofo                                    = 1 << 0x08,
        /// <summary>
        /// The Hangul Compatbility Jamo code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3130.pdf</remarks>
        HangulCompatibilityJamo                     = 1 << 0x09,
        /// <summary>
        /// The Kanbun code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3190.pdf</remarks>
        Kanbun                                      = 1 << 0x0A,
        /// <summary>
        /// The Bopomofu Extended code table.
        /// <seealso cref="Bopomofo"/>
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U31A0.pdf</remarks>
        BopomofoExtended                            = 1 << 0x0B,
        /// <summary>
        /// The CJK Strokes code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U31C0.pdf</remarks>
        CjkStrokes                                  = 1 << 0x0C,
        /// <summary>
        /// The Katakana Phonetic Extensoins code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U31F0.pdf</remarks>
        KatakanaPhoneticExtensions                  = 1 << 0x0D,
        /// <summary>
        /// The Enclosed CJK Letters and Months code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3200.pdf</remarks>
        EnclosedCjkLettersAndMonths                 = 1 << 0x0E,
        /// <summary>
        /// The CJK Compatibility code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3300.pdf</remarks>
        CjkCompatibility                            = 1 << 0x0F,
        /// <summary>
        /// The CJK Unified Ideographs Extension A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U3400.pdf</remarks>
        CjkUnifiedIdeographsExtensionA              = 1 << 0x10,
        /// <summary>
        /// The Yijing Hexagram Symbols code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U4DC0.pdf</remarks>
        YijingHexagramSymbols                       = 1 << 0x11,
        /// <summary>
        /// The CJK Unified Ideographs code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/U4E00.pdf</remarks>
        CjkUnifiedIdeographs                        = 1 << 0x12,
        /// <summary>
        /// The Yi Syllables code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA000.pdf</remarks>
        YiSyllables                                 = 1 << 0x13,
        /// <summary>
        /// The Yi Radicals code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA490.pdf</remarks>
        YiRadicals                                  = 1 << 0x14,
        /// <summary>
        /// The Lisu code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA4D0.pdf</remarks>        
        Lisu                                        = 1 << 0x15,
        /// <summary>
        /// The Vai code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA500.pdf</remarks>
        Vai                                         = 1 << 0x16,
        /// <summary>
        /// The Cyrillic Extended-B code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA640.pdf</remarks>
        CyrillicExtendedB                           = 1 << 0x17,
        /// <summary>
        /// The Bamum code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA6A0.pdf</remarks>
        Bamum                                       = 1 << 0x18,
        /// <summary>
        /// The Modifier Tone Letters code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA700.pdf</remarks>
        ModifierToneLetters                         = 1 << 0x19,
        /// <summary>
        /// The Latin Extended-D code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA720.pdf</remarks>
        LatinExtendedD                              = 1 << 0x1A,
        /// <summary>
        /// The Syloti Nagri code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA800.pdf</remarks>
        SylotiNagri                                 = 1 << 0x1B,
        /// <summary>
        /// The Common Indic Number Forms code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA830.pdf</remarks>
        CommonIndicNumberForms                      = 1 << 0x1C,
        /// <summary>
        /// The Phags-pa code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA840.pdf</remarks>
        Phagspa                                     = 1 << 0x1D,
        /// <summary>
        /// The Saurashtra code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA880.pdf</remarks>
        Saurashtra                                  = 1 << 0x1E,
    }
    /// <summary>
    /// Values for the upper section of the UTF8 Unicode code tables, from UA8E0 to UFFFD
    /// </summary>
    [Flags]
    public enum UpperCodeCharts
    {
        /// <summary>
        /// No code charts from the upper region of the Unicode tables are safe-listed.
        /// </summary>
        None                                        = 0,
        /// <summary>
        /// The Devanagari Extended code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA8E0.pdf</remarks>
        DevanagariExtended                          = 1 << 0x00,
        /// <summary>
        /// The Kayah Li code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA900.pdf</remarks>
        KayahLi                                     = 1 << 0x01,
        /// <summary>
        /// The Rejang code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA930.pdf</remarks>
        Rejang                                      = 1 << 0x02,
        /// <summary>
        /// The Hangul Jamo Extended-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA960.pdf</remarks>
        HangulJamoExtendedA                         = 1 << 0x03,
        /// <summary>
        /// The Javanese code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UA980.pdf</remarks>
        Javanese                                    = 1 << 0x04,
        /// <summary>
        /// The Cham code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UAA00.pdf</remarks>
        Cham                                        = 1 << 0x05,
        /// <summary>
        /// The Myanmar Extended-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UAA60.pdf</remarks>
        MyanmarExtendedA                            = 1 << 0x06,
        /// <summary>
        /// The Tai Viet code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UAA80.pdf</remarks>
        TaiViet                                     = 1 << 0x07,
        /// <summary>
        /// The Meetei Mayek code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UABC0.pdf</remarks>
        MeeteiMayek                                 = 1 << 0x08,
        /// <summary>
        /// The Hangul Syllables code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UAC00.pdf</remarks>
        HangulSyllables                             = 1 << 0x09,
        /// <summary>
        /// The Hangul Jamo Extended-B code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UD7B0.pdf</remarks>
        HangulJamoExtendedB                         = 1 << 0x0A,
        /// <summary>
        /// The CJK Compatibility Ideographs code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UF900.pdf</remarks>
        CjkCompatibilityIdeographs                  = 1 << 0x0B,
        /// <summary>
        /// The Alphabetic Presentation Forms code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFB00.pdf</remarks>
        AlphabeticPresentationForms                 = 1 << 0x0C,
        /// <summary>
        /// The Arabic Presentation Forms-A code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFB50.pdf</remarks>
        ArabicPresentationFormsA                    = 1 << 0x0D,
        /// <summary>
        /// The Variation Selectors code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFE00.pdf</remarks>
        VariationSelectors                          = 1 << 0x0E,
        /// <summary>
        /// The Vertical Forms code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFE10.pdf</remarks>
        VerticalForms                               = 1 << 0x0F,
        /// <summary>
        /// The Combining Half Marks code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFE20.pdf</remarks>
        CombiningHalfMarks                          = 1 << 0x10,
        /// <summary>
        /// The CJK Compatibility Forms code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFE30.pdf</remarks>
        CjkCompatibilityForms                       = 1 << 0x11,
        /// <summary>
        /// The Small Form Variants code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFE50.pdf</remarks>
        SmallFormVariants                           = 1 << 0x12,
        /// <summary>
        /// The Arabic Presentation Forms-B code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFE70.pdf</remarks>
        ArabicPresentationFormsB                    = 1 << 0x13,
        /// <summary>
        /// The half width and full width Forms code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFF00.pdf</remarks>
        HalfWidthAndFullWidthForms                  = 1 << 0x14,
        /// <summary>
        /// The Specials code table.
        /// </summary>
        /// <remarks>http://www.unicode.org/charts/PDF/UFFF0.pdf</remarks>
        Specials                                    = 1 << 0x15,
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CssEncoder.cs" company="Microsoft Corporation">
//   Copyright (c) 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides CSS Encoding methods.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    using System.Threading;
    /// <summary>
    /// Provides CSS Encoding methods.
    /// </summary>
    internal static class CssEncoder
    {
        /// <summary>
        /// A lock object to use when performing safe listing.
        /// </summary>
        private static readonly ReaderWriterLockSlim SyncLock = new ReaderWriterLockSlim();
        /// <summary>
        /// The values to output for each character.
        /// </summary>
        private static char[][] characterValues;
        /// <summary>
        /// Encodes according to the CSS encoding rules.
        /// </summary>
        /// <param name="input">The string to encode.</param>
        /// <returns>The encoded string.</returns>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        internal static string Encode(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }
            if (characterValues == null)
            {
                InitialiseSafeList();
            }
            // Setup a new character array for output.
            char[] inputAsArray = input.ToCharArray();
            int outputLength = 0;
            int inputLength = inputAsArray.Length;
            char[] encodedInput = new char[inputLength * 7]; // Worse case scenario - CSS encoding wants \XXXXXX for encoded characters.
            SyncLock.EnterReadLock();
            try
            {
                for (int i = 0; i < inputLength; i++)
                {
                    char currentCharacter = inputAsArray[i];
                    int currentCodePoint = inputAsArray[i];
                    // Check for invalid values
                    if (currentCodePoint == 0xFFFE ||
                        currentCodePoint == 0xFFFF)
                    {
                        throw new InvalidUnicodeValueException(currentCodePoint);
                    }
                    else if (char.IsHighSurrogate(currentCharacter))
                    {
                        if (i + 1 == inputLength)
                        {
                            throw new InvalidSurrogatePairException(currentCharacter, '\0');
                        }
                        // Now peak ahead and check if the following character is a low surrogate.
                        char nextCharacter = inputAsArray[i + 1];
                        char nextCodePoint = inputAsArray[i + 1];
                        if (!char.IsLowSurrogate(nextCharacter))
                        {
                            throw new InvalidSurrogatePairException(currentCharacter, nextCharacter);
                        }
                        // Look-ahead was good, so skip.
                        i++;
                        // Calculate the combined code point
                        long combinedCodePoint =
                            0x10000 + ((currentCodePoint - 0xD800) * 0x400) + (nextCodePoint - 0xDC00);
                        char[] encodedCharacter = SafeList.SlashThenSixDigitHexValueGenerator(combinedCodePoint);
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                    }
                    else if (char.IsLowSurrogate(currentCharacter))
                    {
                        throw new InvalidSurrogatePairException('\0', currentCharacter);
                    }
                    else if (currentCodePoint > characterValues.Length - 1)
                    {
                        char[] encodedCharacter = SafeList.SlashThenSixDigitHexValueGenerator(currentCodePoint);
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }                        
                    }
                    else if (characterValues[currentCodePoint] != null)
                    {
                        // character needs to be encoded
                        char[] encodedCharacter = characterValues[currentCodePoint];
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                    }
                    else
                    {
                        // character does not need encoding
                        encodedInput[outputLength++] = currentCharacter;
                    }
                }
            }
            finally
            {
                SyncLock.ExitReadLock();
            }
            return new string(encodedInput, 0, outputLength);
        }
        /// <summary>
        /// Initializes the HTML safe list.
        /// </summary>
        private static void InitialiseSafeList()
        {
            SyncLock.EnterWriteLock();
            try
            {
                if (characterValues == null)
                {
                    characterValues = SafeList.Generate(0xFF, SafeList.SlashThenSixDigitHexValueGenerator);
                    SafeList.PunchSafeList(ref characterValues, CssSafeList());
                }
            }
            finally
            {
                SyncLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// Provides the safe characters for CS encoding.
        /// </summary>
        /// <returns>The safe characters for CSS encoding.</returns>
        /// <remarks>See http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet </remarks>
        private static IEnumerable CssSafeList()
        {
            for (int i = '0'; i <= '9'; i++)
            {
                yield return i;
            }
            for (int i = 'A'; i <= 'Z'; i++)
            {
                yield return i;
            }
            for (int i = 'a'; i <= 'z'; i++)
            {
                yield return i;
            }
            // Extended higher ASCII, Ç to É
            for (int i = 0x80; i <= 0x90; i++)
            {
                yield return i;
            }
            // Extended higher ASCII, ô to Ü
            for (int i = 0x93; i <= 0x9A; i++)
            {
                yield return i;
            }
            // Extended higher ASCII, á to Ñ
            for (int i = 0xA0; i <= 0xA5; i++)
            {
                yield return i;
            }
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Encoder.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Performs encoding of input strings to provide protection against
//   Cross-Site Scripting (XSS) attacks and LDAP injection attacks in
//   various contexts.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System;
    using System.Globalization;
    using System.Text;
    /// <summary>
    /// Performs encoding of input strings to provide protection against
    /// Cross-Site Scripting (XSS) attacks and LDAP injection attacks in 
    /// various contexts.
    /// </summary>
    /// <remarks>
    /// This encoding library uses the Principle of Inclusions, 
    /// sometimes referred to as "safe-listing" to provide protection 
    /// against injection attacks.  With safe-listing protection, 
    /// algorithms look for valid inputs and automatically treat 
    /// everything outside that set as a potential attack.  This library 
    /// can be used as a defense in depth approach with other mitigation 
    /// techniques. It is suitable for applications with high security 
    /// requirements.
    /// </remarks>
    public static class Encoder
    {
        /// <summary>
        /// Empty string for Visual Basic Script context
        /// </summary>
        private const string VbScriptEmptyString = "\"\"";
        /// <summary>
        /// Empty string for Java Script context
        /// </summary>
        private const string JavaScriptEmptyString = "''";
        /// <summary>
        /// Initializes character Html encoding array
        /// </summary>
        private static readonly char[][] SafeListCodes = InitializeSafeList();
        /// <summary>
        /// Encodes input strings for use as a value  in Lightweight Directory Access Protocol (LDAP) filter queries.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>Encoded string for use as a value in LDAP filter queries.</returns>
        /// <remarks>This method encodes all but known safe characters defined in the safe list.
        /// <newpara/>
        /// RFC 4515 defines the format in which special characters need to be 
        /// escaped to be used inside a search filter. Special characters need to be 
        /// encoded in \XX format where XX is the hex representation of the character.
        /// <newpara/>
        /// The following examples illustrate the use of the escaping mechanism.
        /// <list type="table">
        /// <item><term>Parens R Us (for all your parenthetical needs)</term><description>Parens R Us \28for all your parenthetical needs\29</description></item>
        /// <item><term>*</term><description>\2A</description></item>
        /// <item><term>C:\MyFile</term><description>C:\5CMyFile</description></item>
        /// <item><term>NULLNULLNULLEOT (binary)</term><description>\00\00\00\04</description></item>
        /// <item><term>Lučić</term><description>Lu\C4\8Di\C4\87</description></item>
        /// </list>
        /// </remarks>
        public static string LdapFilterEncode(string input)
        {
            return LdapEncoder.FilterEncode(input);
        }
        /// <summary>
        /// Encodes input strings for use as a value in Lightweight Directory Access Protocol (LDAP) DNs.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>Encoded string for use as a value in LDAP DNs.</returns>
        /// <remarks>This method encodes all but known safe characters defined in the safe list.
        /// <newpara/>
        /// RFC 2253 defines the format in which special characters need to be 
        /// escaped to be used inside a search filter. Special characters need to be 
        /// encoded in #XX format where XX is the hex representation of the character or a 
        /// specific \ escape format.
        /// <newpara/>
        /// The following examples illustrate the use of the escaping mechanism.
        /// <list type="table">
        /// <item><term>, + \ " \ &lt; &gt;</term><description>\, \+ \" \\ \&lt; \&gt;</description></item>
        /// <item><term> hello</term><description>\ hello</description></item>
        /// <item><term>hello </term><description>hello \ </description></item>
        /// <item><term>#hello</term><description>\#hello</description></item>
        /// <item><term>Lučić</term><description>Lu#C4#8Di#C4#87</description></item>
        /// </list>
        /// </remarks>
        public static string LdapDistinguishedNameEncode(string input)
        {
            return LdapDistinguishedNameEncode(input, true, true);
        }
        /// <summary>
        /// Encodes input strings for use as a value in Lightweight Directory Access Protocol (LDAP) DNs.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="useInitialCharacterRules">Value indicating whether the special case rules for encoding of spaces and octothorpes at the start of a string are used.</param>
        /// <param name="useFinalCharacterRule">Value indicating whether the special case for encoding of final character spaces is used.</param>
        /// <returns>Encoded string for use as a value in LDAP DNs.</returns>\
        /// <remarks>This method encodes all but known safe characters defined in the safe list.
        /// <newpara/>
        /// RFC 2253 defines the format in which special characters need to be 
        /// escaped to be used inside a search filter. Special characters need to be 
        /// encoded in #XX format where XX is the hex representation of the character or a 
        /// specific \ escape format.
        /// <newpara/>
        /// The following examples illustrate the use of the escaping mechanism.
        /// <list type="table">
        /// <item><term>, + \ " \ &lt; &gt;</term><description>\, \+ \" \\ \&lt; \&gt;</description></item>
        /// <item><term> hello</term><description>\ hello</description></item>
        /// <item><term>hello </term><description>hello\ </description></item>
        /// <item><term>#hello</term><description>\#hello</description></item>
        /// <item><term>Lučić</term><description>Lu#C4#8Di#C4#87</description></item>
        /// </list>
        /// If useInitialCharacterRules is set to false then escaping of the initial space or octothorpe characters is not performed;
        /// <list type="table">
        /// <item><term>, + \ " \ &lt; &gt;</term><description>\, \+ \" \\ \&lt; \&gt;</description></item>
        /// <item><term> hello</term><description> hello</description></item>
        /// <item><term>hello </term><description>hello\ </description></item>
        /// <item><term>#hello</term><description>#hello</description></item>
        /// <item><term>Lučić</term><description>Lu#C4#8Di#C4#87</description></item>
        /// </list>
        /// If useFinalCharacterRule is set to false then escaping of a space at the end of a string is not performed;
        /// <list type="table">
        /// <item><term>, + \ " \ &lt; &gt;</term><description>\, \+ \" \\ \&lt; \&gt;</description></item>
        /// <item><term> hello</term><description> hello</description></item>
        /// <item><term>hello </term><description>hello </description></item>
        /// <item><term>#hello</term><description>#hello</description></item>
        /// <item><term>Lučić</term><description>Lu#C4#8Di#C4#87</description></item>
        /// </list>
        /// </remarks>
        public static string LdapDistinguishedNameEncode(string input, bool useInitialCharacterRules, bool useFinalCharacterRule)
        {
            return LdapEncoder.DistinguishedNameEncode(input, useInitialCharacterRules, useFinalCharacterRule);
        }
        /// <summary>
        /// Encodes input strings to be used as a value in Lightweight Directory Access Protocol (LDAP) search queries.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>Encoded string for use in LDAP search queries.</returns>
        /// <remarks>This method encodes all but known safe characters defined in the safe list.
        /// <newpara/>
        /// RFC 4515 defines the format in which special characters need to be 
        /// escaped to be used inside a search filter. Special characters need to be 
        /// encoded in \XX format where XX is the hex representation of the character.
        /// <newpara/>
        /// The following examples illustrate the use of the escaping mechanism.
        /// <list type="table">
        /// <item><term>Parens R Us (for all your parenthetical needs)</term><description>Parens R Us \28for all your parenthetical needs\29</description></item>
        /// <item><term>*</term><description>\2A</description></item>
        /// <item><term>C:\MyFile</term><description>C:\5CMyFile</description></item>
        /// <item><term>NULLNULLNULLEOT (binary)</term><description>\00\00\00\04</description></item>
        /// <item><term>Lučić</term><description>Lu\C4\8Di\C4\87</description></item>
        /// </list>
        /// </remarks>
        [Obsolete("This method has been deprecated. Please use Encoder.LdapFilterEncode() instead.")]
        public static string LdapEncode(string input)
        {
            return LdapFilterEncode(input);
        }
        /// <summary>
        /// Encodes input strings used in Cascading Style Sheet (CSS) elements values.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>Encoded string for use in CSS element values.</returns>
        /// <remarks>This method encodes all but known safe characters defined in the safe list.
        /// <newpara/>
        /// The CSS character escape sequence consists of a backslash character (\) followed by 
        /// between one and six hexadecimal digits that represent a character code from the 
        /// ISO 10646 standard (which is equivalent to Unicode, for all intents and purposes). Any 
        /// character other than a hexadecimal digit will terminate the escape sequence. If a 
        /// character following the escape sequence is also a valid hexadecimal digit then it must 
        /// either include six digits in the escape, or use a whitespace character to terminate the 
        /// escape. This encoder enforces the six digit rule.
        /// For example \000020 denotes a space.
        /// </remarks>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        public static string CssEncode(string input)
        {
            return CssEncoder.Encode(input);
        }
        /// <summary>
        /// Encodes input strings for use in HTML.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in HTML.
        /// </returns>
        /// <remarks>
        /// All characters not safe listed are encoded to their Unicode decimal value, using &amp;#DECIMAL; notation.
        /// The default safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>'</term><description>Apostrophe</description></item>
        /// <item><term> </term><description>Space</description></item>
        /// </list>
        /// The safe list may be adjusted using <see cref="UnicodeCharacterEncoder.MarkAsSafe"/>.
        /// <newpara/>
        /// Example inputs and their related encoded outputs:
        /// <list type="table">
        /// <item><term>&lt;script&gt;alert('XSS Attack!');&lt;/script&gt;</term><description>&amp;lt;script&amp;gt;alert('XSS Attack!');&amp;lt;/script&amp;gt;</description></item>
        /// <item><term>user@contoso.com</term><description>user@contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross Site Scripting Library</description></item>
        /// <item><term>"Anti-Cross Site Scripting Library"</term><description>&amp;quote;Anti-Cross Site Scripting Library&amp;quote;</description></item>
        /// </list>
        /// </remarks>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        public static string HtmlEncode(string input)
        {
            return HtmlEncode(input, false);
        }
        /// <summary>
        /// Encodes input strings for use in HTML.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="useNamedEntities">Value indicating if the HTML 4.0 named entities should be used.</param>
        /// <returns>
        /// Encoded string for use in HTML.
        /// </returns>
        /// <remarks>
        /// All characters not safe listed are encoded to their Unicode decimal value, using &amp;#DECIMAL; notation.
        /// If you choose to use named entities then if a character is an HTML4.0 named entity the named entity will be used.
        /// The default safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>'</term><description>Apostrophe</description></item>
        /// <item><term> </term><description>Space</description></item>
        /// </list>
        /// The safe list may be adjusted using <see cref="UnicodeCharacterEncoder.MarkAsSafe"/>.
        /// <newpara/>
        /// Example inputs and their related encoded outputs:
        /// <list type="table">
        /// <item><term>&lt;script&gt;alert('XSS Attack!');&lt;/script&gt;</term><description>&amp;lt;script&amp;gt;alert('XSS Attack!');&amp;lt;/script&amp;gt;</description></item>
        /// <item><term>user@contoso.com</term><description>user@contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross Site Scripting Library</description></item>
        /// <item><term>"Anti-Cross Site Scripting Library"</term><description>&amp;quote;Anti-Cross Site Scripting Library&amp;quote;</description></item>
        /// </list>
        /// </remarks>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        public static string HtmlEncode(string input, bool useNamedEntities)
        {
            return UnicodeCharacterEncoder.HtmlEncode(input, useNamedEntities);
        }
        /// <summary>
        /// Encodes an input string for use in an HTML attribute.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>The input string encoded for use in an HTML attribute.</returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are encoded using  &amp;#DECIMAL; notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// </list>
        /// The safe list may be adjusted using <see cref="UnicodeCharacterEncoder.MarkAsSafe"/>.
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>alert(&amp;#39;XSS&amp;#32;Attack!&amp;#39;);</description></item>
        /// <item><term>user@contoso.com</term><description>user@contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross&amp;#32;Site&amp;#32;Scripting&amp;#32;Library</description></item>
        /// </list>
        /// </remarks>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        public static string HtmlAttributeEncode(string input)
        {
            return UnicodeCharacterEncoder.HtmlAttributeEncode(input);
        }
        /// <summary>
        /// Encodes input strings for use in universal resource locators (URLs).
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in URLs.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are encoded using %SINGLE_BYTE_HEX 
        /// and %DOUBLE_BYTE_HEX notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>~</term><description>Tilde</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>alert%28%27XSS%20Attack%21%27%29%3b</description></item>
        /// <item><term>user@contoso.com</term><description>user%40contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross%20Site%20Scripting%20Library</description></item>
        /// </list>
        /// </remarks>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1055:UriReturnValuesShouldNotBeStrings",
            Justification = "As this is meant as a replacement for HttpUility.Encode we must keep the same return type.")]
        public static string UrlEncode(string input)
        {
            return UrlEncode(input, Encoding.UTF8);
        }
        /// <summary>
        /// Encodes input strings for use in application/x-www-form-urlencoded form submissions.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in URLs.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are encoded using %SINGLE_BYTE_HEX 
        /// and %DOUBLE_BYTE_HEX notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>~</term><description>Tilde</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>alert%28%27XSS+Attack%21%27%29%3b</description></item>
        /// <item><term>user@contoso.com</term><description>user%40contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross+Site+Scripting+Library</description></item>
        /// </list>
        /// </remarks>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1055:UriReturnValuesShouldNotBeStrings",
            Justification = "This does not return a URL so the return type can be a string.")]
        public static string HtmlFormUrlEncode(string input)
        {
            return HtmlFormUrlEncode(input, Encoding.UTF8);
        }
        /// <summary>
        /// Encodes input strings for use in universal resource locators (URLs).
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="codePage">Codepage number of the input.</param>
        /// <returns>
        /// Encoded string for use in URLs.
        /// </returns>
        /// <remarks>
        /// This function encodes the output as per the encoding parameter (codepage) passed to it. It encodes 
        /// all but known safe characters.  Characters are encoded using %SINGLE_BYTE_HEX and %DOUBLE_BYTE_HEX notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>~</term><description>Tilde</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSSあAttack!');</term><description>alert%28%27XSS%82%a0Attack%21%27%29%3b</description></item>
        /// <item><term>user@contoso.com</term><description>user%40contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross%20Site%20Scripting%20Library</description></item>
        /// </list>
        /// </remarks>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1055:UriReturnValuesShouldNotBeStrings",
            Justification = "This does not return a URL so the return type can be a string.")]
        public static string UrlEncode(string input, int codePage)
        {
            return UrlEncode(input, Encoding.GetEncoding(codePage));
        }
        /// <summary>
        /// Encodes input strings for use in application/x-www-form-urlencoded form submissions.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="codePage">Codepage number of the input.</param>
        /// <returns>
        /// Encoded string for use in URLs.
        /// </returns>
        /// <remarks>
        /// This function encodes the output as per the encoding parameter (codepage) passed to it. It encodes 
        /// all but known safe characters.  Characters are encoded using %SINGLE_BYTE_HEX and %DOUBLE_BYTE_HEX notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>~</term><description>Tilde</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSSあAttack!');</term><description>alert%28%27XSS%82%a0Attack%21%27%29%3b</description></item>
        /// <item><term>user@contoso.com</term><description>user%40contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross+Site+Scripting+Library</description></item>
        /// </list>
        /// </remarks>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1055:UriReturnValuesShouldNotBeStrings",
            Justification = "This not not return a URL, so the return type can be a string.")]
        public static string HtmlFormUrlEncode(string input, int codePage)
        {
            return HtmlFormUrlEncode(input, Encoding.GetEncoding(codePage));
        }
        /// <summary>
        /// Encodes input strings for use in universal resource locators (URLs).
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="inputEncoding">Input encoding type.</param>
        /// <returns>
        /// Encoded string for use in URLs.
        /// </returns>
        /// <remarks>
        /// This function encodes the output as per the encoding parameter (codepage) passed to it. It encodes 
        /// all but known safe characters.  Characters are encoded using %SINGLE_BYTE_HEX and %DOUBLE_BYTE_HEX notation.
        /// If the inputEncoding is null then UTF-8 is assumed by default.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>~</term><description>Tilde</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSSあAttack!');</term><description>alert%28%27XSS%82%a0Attack%21%27%29%3b</description></item>
        /// <item><term>user@contoso.com</term><description>user%40contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross%20Site%20Scripting%20Library</description></item>
        /// </list>
        /// </remarks>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1055:UriReturnValuesShouldNotBeStrings",
            Justification = "This does not return a URL so the return type can be a string.")]
        public static string UrlEncode(string input, Encoding inputEncoding)
        {
            // Assuming the default to be UTF-8
            if (inputEncoding == null)
            {
                inputEncoding = Encoding.UTF8;
            }
            return HtmlParameterEncoder.QueryStringParameterEncode(input, inputEncoding);
        }
        /// <summary>
        /// Encodes input strings for use in application/x-www-form-urlencoded form submissions.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="inputEncoding">Input encoding type.</param>
        /// <returns>
        /// Encoded string for use in URLs.
        /// </returns>
        /// <remarks>
        /// This function encodes the output as per the encoding parameter (codepage) passed to it. It encodes 
        /// all but known safe characters.  Characters are encoded using %SINGLE_BYTE_HEX and %DOUBLE_BYTE_HEX notation.
        /// If the inputEncoding is null then UTF-8 is assumed by default.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term>~</term><description>Tilde</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSSあAttack!');</term><description>alert%28%27XSS%82%a0Attack%21%27%29%3b</description></item>
        /// <item><term>user@contoso.com</term><description>user%40contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross+Site+Scripting+Library</description></item>
        /// </list>
        /// </remarks>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1055:UriReturnValuesShouldNotBeStrings",
            Justification = "This does not return a URL so the return type can be a string.")]
        public static string HtmlFormUrlEncode(string input, Encoding inputEncoding)
        {
            // Assuming the default to be UTF-8
            if (inputEncoding == null)
            {
                inputEncoding = Encoding.UTF8;
            }
            return HtmlParameterEncoder.FormStringParameterEncode(input, inputEncoding);
        }
        /// <summary>
        /// Encodes input strings for use in XML.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in XML.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters. Characters are encoded using &amp;#DECIMAL; notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term> </term><description>Space</description></item>
        /// </list>
        /// The safe list may be adjusted using <see cref="UnicodeCharacterEncoder.MarkAsSafe"/>.
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>alert(&amp;apos;XSS Attack!&amp;apos;);</description></item>
        /// <item><term>user@contoso.com</term><description>user@contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross Site Scripting Library</description></item>
        /// </list>
        /// </remarks>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        public static string XmlEncode(string input)
        {
            return UnicodeCharacterEncoder.XmlEncode(input);
        }
        /// <summary>
        /// Encodes input strings for use in XML attributes.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in XML attributes.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are encoded using &amp;#DECIMAL; notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// </list>
        /// The safe list may be adjusted using <see cref="UnicodeCharacterEncoder.MarkAsSafe"/>.
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>alert(&amp;apos;XSS Attack!&amp;apos);</description></item>
        /// <item><term>user@contoso.com</term><description>user@contoso.com</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>Anti-Cross&amp;#32;Site&amp;#32;Scripting&amp;#32;Library</description></item>
        /// </list>
        /// </remarks>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        public static string XmlAttributeEncode(string input)
        {
            // HtmlEncodeAttribute will handle input
            return UnicodeCharacterEncoder.XmlAttributeEncode(input);
        }
        /// <summary>
        /// Encodes input strings for use in JavaScript.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in JavaScript.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are encoded using \xSINGLE_BYTE_HEX and \uDOUBLE_BYTE_HEX notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term> </term><description>Space</description></item>
        /// <item><term> </term><description>Other International character ranges</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>'alert\x28\x27XSS Attack\x21\x27\x29\x3b'</description></item>
        /// <item><term>user@contoso.com</term><description>'user\x40contoso.com'</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>'Anti-Cross Site Scripting Library'</description></item>
        /// </list>
        /// </remarks>
        public static string JavaScriptEncode(string input)
        {
            return JavaScriptEncode(input, true);
        }
        /// <summary>
        /// Encodes input strings for use in JavaScript.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <param name="emitQuotes">value indicating whether or not to emit quotes. true = emit quote. false = no quote.</param>
        /// <returns>
        /// Encoded string for use in JavaScript and does not return the output with en quotes.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are encoded using \xSINGLE_BYTE_HEX and \uDOUBLE_BYTE_HEX notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term> </term><description>Space</description></item>
        /// <item><term> </term><description>Other International character ranges</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>'alert\x28\x27XSS Attack\x21\x27\x29\x3b'</description></item>
        /// <item><term>user@contoso.com</term><description>'user\x40contoso.com'</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>'Anti-Cross Site Scripting Library'</description></item>
        /// </list>
        /// </remarks>
        public static string JavaScriptEncode(string input, bool emitQuotes)
        {
            // Input validation: empty or null string condition
            if (string.IsNullOrEmpty(input))
            {
                return emitQuotes ? JavaScriptEmptyString : string.Empty;
            }
            // Use a new char array.
            int outputLength = 0;
            int inputLength = input.Length;
            char[] returnMe = new char[inputLength * 8]; // worst case length scenario
            // First step is to start the encoding with an apostrophe if flag is true.
            if (emitQuotes)
            {
                returnMe[outputLength++] = '\'';
            }
            for (int i = 0; i < inputLength; i++)
            {
                int currentCharacterAsInteger = input[i];
                char currentCharacter = input[i];
                if (SafeListCodes[currentCharacterAsInteger] != null || currentCharacterAsInteger == 92 || (currentCharacterAsInteger >= 123 && currentCharacterAsInteger <= 127))
                {
                    // character needs to be encoded
                    if (currentCharacterAsInteger >= 127)
                    {
                        returnMe[outputLength++] = '\\';
                        returnMe[outputLength++] = 'u';
                        string hex = ((int)currentCharacter).ToString("x", CultureInfo.InvariantCulture).PadLeft(4, '0');
                        returnMe[outputLength++] = hex[0];
                        returnMe[outputLength++] = hex[1];
                        returnMe[outputLength++] = hex[2];
                        returnMe[outputLength++] = hex[3];
                    }
                    else
                    {
                        returnMe[outputLength++] = '\\';
                        returnMe[outputLength++] = 'x';
                        string hex = ((int)currentCharacter).ToString("x", CultureInfo.InvariantCulture).PadLeft(2, '0');
                        returnMe[outputLength++] = hex[0];
                        returnMe[outputLength++] = hex[1];
                    }
                }
                else
                {
                    // character does not need encoding
                    returnMe[outputLength++] = input[i];
                }
            }
            // Last step is to end the encoding with an apostrophe if flag is true.
            if (emitQuotes)
            {
                returnMe[outputLength++] = '\'';
            }
            return new string(returnMe, 0, outputLength);
        }
        /// <summary>
        /// Encodes input strings for use in Visual Basic Script.
        /// </summary>
        /// <param name="input">String to be encoded.</param>
        /// <returns>
        /// Encoded string for use in Visual Basic Script.
        /// </returns>
        /// <remarks>
        /// This function encodes all but known safe characters.  Characters are 
        /// encoded using &chrw(DECIMAL) notation.
        /// <newpara/>
        /// Safe characters include:
        /// <list type="table">
        /// <item><term>a-z</term><description>Lower case alphabet</description></item>
        /// <item><term>A-Z</term><description>Upper case alphabet</description></item>
        /// <item><term>0-9</term><description>Numbers</description></item>
        /// <item><term>,</term><description>Comma</description></item>
        /// <item><term>.</term><description>Period</description></item>
        /// <item><term>-</term><description>Dash</description></item>
        /// <item><term>_</term><description>Underscore</description></item>
        /// <item><term> </term><description>Space</description></item>
        /// </list>
        /// <newpara/>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>alert('XSS Attack!');</term><description>"alert"&chrw(40)&chrw(39)&"XSS Attack"&chrw(33)&chrw(39)&chrw(41)&chrw(59)</description></item>
        /// <item><term>user@contoso.com</term><description>"user"&chrw(64)&"contoso.com"</description></item>
        /// <item><term>Anti-Cross Site Scripting Library</term><description>"Anti-Cross Site Scripting Library"</description></item>
        /// </list></remarks>
        public static string VisualBasicScriptEncode(string input)
        {
            // Input validation: empty or null string condition
            if (string.IsNullOrEmpty(input))
            {
                return VbScriptEmptyString;
            }
            // Use a new char array.
            int outputLength = 0;
            int inputLength = input.Length;
            char[] encodedInput = new char[inputLength * 12]; // worst case length scenario
            // flag to surround double quotes around safe characters
            bool isInQuotes = false;
            for (int i = 0; i < inputLength; i++)
            {
                int currentCharacterAsInteger = input[i];
                char currentCharacter = input[i];
                if (SafeListCodes[currentCharacterAsInteger] != null)
                {
                    // character needs to be encoded
                    // surround in quotes
                    if (isInQuotes)
                    {
                        // get out of quotes
                        encodedInput[outputLength++] = '"';
                        isInQuotes = false;
                    }
                    // adding "encoded" characters
                    string temp = "&chrw(" + ((uint)currentCharacter) + ")";
                    foreach (char ch in temp)
                    {
                        encodedInput[outputLength++] = ch;
                    }
                }
                else
                {
                    // character does not need encoding
                    // surround in quotes
                    if (!isInQuotes)
                    {
                        // add quotes to start
                        encodedInput[outputLength++] = '&';
                        encodedInput[outputLength++] = '"';
                        isInQuotes = true;
                    }
                    encodedInput[outputLength++] = input[i];
                }
            }
            // if we're inside of quotes, close them
            if (isInQuotes)
            {
                encodedInput[outputLength++] = '"';
            }
            // finally strip extraneous "&" from beginning of the string, if necessary and RETURN
            if (encodedInput.Length > 0 && encodedInput[0] == '&')
            {
                return new string(encodedInput, 1, outputLength - 1);
            }
            return new string(encodedInput, 0, outputLength);
        }
        /// <summary>
        /// Initializes the safe list.
        /// </summary>
        /// <returns>A two dimensional character array containing characters and their encoded values.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "This is necessary complexity.")]
        private static char[][] InitializeSafeList()
        {
            char[][] allCharacters = new char[65536][];
            for (int i = 0; i < allCharacters.Length; i++)
            {
                if (
                    (i >= 97 && i <= 122) ||        // a-z
                    (i >= 65 && i <= 90) ||         // A-Z
                    (i >= 48 && i <= 57) ||         // 0-9
                    i == 32 ||                      // space
                    i == 46 ||                      // .
                    i == 44 ||                      // ,
                    i == 45 ||                      // -
                    i == 95 ||                      // _
                    (i >= 256 && i <= 591) ||       // Latin,Extended-A,Latin Extended-B        
                    (i >= 880 && i <= 2047) ||      // Greek and Coptic,Cyrillic,Cyrillic Supplement,Armenian,Hebrew,Arabic,Syriac,Arabic,Supplement,Thaana,NKo
                    (i >= 2304 && i <= 6319) ||     // Devanagari,Bengali,Gurmukhi,Gujarati,Oriya,Tamil,Telugu,Kannada,Malayalam,Sinhala,Thai,Lao,Tibetan,Myanmar,eorgian,Hangul Jamo,Ethiopic,Ethiopic Supplement,Cherokee,Unified Canadian Aboriginal Syllabics,Ogham,Runic,Tagalog,Hanunoo,Buhid,Tagbanwa,Khmer,Mongolian   
                    (i >= 6400 && i <= 6687) ||     // Limbu, Tai Le, New Tai Lue, Khmer, Symbols, Buginese
                    (i >= 6912 && i <= 7039) ||     // Balinese         
                    (i >= 7680 && i <= 8191) ||     // Latin Extended Additional, Greek Extended        
                    (i >= 11264 && i <= 11743) ||   // Glagolitic, Latin Extended-C, Coptic, Georgian Supplement, Tifinagh, Ethiopic Extended    
                    (i >= 12352 && i <= 12591) ||   // Hiragana, Katakana, Bopomofo       
                    (i >= 12688 && i <= 12735) ||   // Kanbun, Bopomofo Extended        
                    (i >= 12784 && i <= 12799) ||   // Katakana, Phonetic Extensions         
                    (i >= 19968 && i <= 40899) ||   // Mixed japanese/chinese/korean
                    (i >= 40960 && i <= 42191) ||   // Yi Syllables, Yi Radicals        
                    (i >= 42784 && i <= 43055) ||   // Latin Extended-D, Syloti, Nagri        
                    (i >= 43072 && i <= 43135) ||   // Phags-pa         
                    (i >= 44032 && i <= 55215) /* Hangul Syllables */)
                {
                    allCharacters[i] = null;
                }
                else
                {
                    string integerStringValue = i.ToString(CultureInfo.InvariantCulture);
                    int integerStringLength = integerStringValue.Length;
                    char[] thisChar = new char[integerStringLength];
                    for (int j = 0; j < integerStringLength; j++)
                    {
                        thisChar[j] = integerStringValue[j];
                    }
                    allCharacters[i] = thisChar;
                }
            }
            return allCharacters;
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HtmlParameterEncoder.cs" company="Microsoft Corporation">
//   Copyright (c) 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides HTML Parameter Encoding methods.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System;
    using System.Collections;
    using System.Text;
    using System.Threading;
    /// <summary>
    /// The type of space encoding to use.
    /// </summary>
    internal enum EncodingType
    {
        /// <summary>
        /// Encode spaces for use in query strings
        /// </summary>
        QueryString = 1,
        /// <summary>
        /// Encode spaces for use in form data
        /// </summary>
        HtmlForm = 2
    }
    /// <summary>
    /// Provides Html Parameter Encoding methods.
    /// </summary>
    internal static class HtmlParameterEncoder
    {
        /// <summary>
        /// A lock object to use when performing safe listing.
        /// </summary>
        private static readonly ReaderWriterLockSlim SyncLock = new ReaderWriterLockSlim();
        /// <summary>
        /// The value to use when encoding a space for query strings.
        /// </summary>
        private static readonly char[] QueryStringSpace = "%20".ToCharArray();
        /// <summary>
        /// The value to use when encoding a space for form data.
        /// </summary>
        private static readonly char[] FormStringSpace = "+".ToCharArray();
        /// <summary>
        /// The values to output for each character.
        /// </summary>
        private static char[][] characterValues;
        /// <summary>
        /// Encodes a string for query string encoding and returns the encoded string.
        /// </summary>
        /// <param name="s">The text to URL-encode.</param>
        /// <param name="encoding">The encoding for the text parameter.</param>
        /// <returns>The URL-encoded text.</returns>
        /// <remarks>URL encoding ensures that all browsers will correctly transmit text in URL strings. 
        /// Characters such as a question mark (?), ampersand (&amp;), slash mark (/), and spaces might be truncated or corrupted by some browsers. 
        /// As a result, these characters must be encoded in &lt;a&gt; tags or in query strings where the strings can be re-sent by a browser 
        /// in a request string.</remarks>
        /// <exception cref="ArgumentNullException">Thrown if the encoding is null.</exception>
        internal static string QueryStringParameterEncode(string s, Encoding encoding)
        {
            return FormQueryEncode(s, encoding, EncodingType.QueryString);
        }
        /// <summary>
        /// Encodes a string for form URL encoding and returns the encoded string.
        /// </summary>
        /// <param name="s">The text to URL-encode.</param>
        /// <param name="encoding">The encoding for the text parameter.</param>
        /// <returns>The URL-encoded text.</returns>
        /// <remarks>URL encoding ensures that all browsers will correctly transmit text in URL strings. 
        /// Characters such as a question mark (?), ampersand (&amp;), slash mark (/), and spaces might be truncated or corrupted by some browsers. 
        /// As a result, these characters must be encoded in &lt;a&gt; tags or in query strings where the strings can be re-sent by a browser 
        /// in a request string.</remarks>
        /// <exception cref="ArgumentNullException">Thrown if the encoding is null.</exception>
        internal static string FormStringParameterEncode(string s, Encoding encoding)
        {
            return FormQueryEncode(s, encoding, EncodingType.HtmlForm);
        }
        /// <summary>
        /// Encodes a string for Query String or Form Data encoding.
        /// </summary>
        /// <param name="s">The text to URL-encode.</param>
        /// <param name="encoding">The encoding for the text parameter.</param>
        /// <param name="encodingType">The encoding type to use.</param>
        /// <returns>The encoded text.</returns>
        private static string FormQueryEncode(string s, Encoding encoding, EncodingType encodingType)
        {
            if (string.IsNullOrEmpty(s))
            {
                return s;
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }
            if (characterValues == null)
            {
                InitialiseSafeList();
            }
            // RFC 3986 states strings must be converted to their UTF8 value before URL encoding.
            // See http://tools.ietf.org/html/rfc3986
            // Conversion to char[] keeps null characters inline.
            byte[] utf8Bytes = encoding.GetBytes(s.ToCharArray());
            char[] encodedInput = new char[utf8Bytes.Length * 3]; // Each byte can potentially be encoded as %xx
            int outputLength = 0;
            for (int characterPosition = 0; characterPosition < utf8Bytes.Length; characterPosition++)
            {
                byte currentCharacter = utf8Bytes[characterPosition];
                if (currentCharacter == 0x00 || currentCharacter == 0x20 || currentCharacter > characterValues.Length || characterValues[currentCharacter] != null)
                {                
                    // character needs to be encoded
                    char[] encodedCharacter;
                    if (currentCharacter == 0x20)
                    {
                        switch (encodingType)
                        {
                            case EncodingType.QueryString:
                                encodedCharacter = QueryStringSpace;
                                break;
                            // Special case for Html Form data, from http://www.w3.org/TR/html401/appendix/notes.html#non-ascii-chars
                            case EncodingType.HtmlForm:
                                encodedCharacter = FormStringSpace;
                                break;
                            default:
                                throw new ArgumentOutOfRangeException("encodingType");
                        }
                    }
                    else
                    {
                        encodedCharacter = characterValues[currentCharacter];
                    }
                    for (int j = 0; j < encodedCharacter.Length; j++)
                    {
                        encodedInput[outputLength++] = encodedCharacter[j];
                    }
                }
                else
                {
                    // character does not need encoding
                    encodedInput[outputLength++] = (char)currentCharacter;
                }
            }
            return new string(encodedInput, 0, outputLength);
        }
        /// <summary>
        /// Initializes the HTML safe list.
        /// </summary>
        private static void InitialiseSafeList()
        {
            SyncLock.EnterWriteLock();
            try
            {
                characterValues = SafeList.Generate(255, SafeList.PercentThenHexValueGenerator);
                SafeList.PunchSafeList(ref characterValues, UrlParameterSafeList());
            }
            finally
            {
                SyncLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// Provides the safe characters for URL parameter encoding.
        /// </summary>
        /// <returns>The safe characters for URL parameter encoding.</returns>
        private static IEnumerable UrlParameterSafeList()
        {
            // Hyphen
            yield return 0x2D;
            // Full stop/period
            yield return 0x2E;
            // Digits
            for (int i = 0x30; i <= 0x39; i++)
            {
                yield return i;
            }  
            // Upper case alphabet
            for (int i = 0x41; i <= 0x5A; i++)
            {
                yield return i;
            }
            // Underscore
            yield return 0x5F;
            // Lower case alphabet
            for (int i = 0x61; i <= 0x7A; i++)
            {
                yield return i;
            }
            // Tilde
            yield return 0x7E;
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InvalidSurrogatePairException.cs" company="Microsoft Corporation">
//   Copyright (c) 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Thrown when a bad surrogate pair is encountered.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System;
    using System.Globalization;
    /// <summary>
    /// Thrown when a bad surrogate pair is encountered.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage(
        "Microsoft.Usage",
        "CA2237:MarkISerializableTypesWithSerializable",
        Justification = "The exception does not leave the application domain and serialization breaks medium trust.")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage(
        "Microsoft.Design",
        "CA1032:ImplementStandardExceptionConstructors",
        Justification = "The exception does not leave the application domain and serialization breaks medium trust.")]
    public class InvalidSurrogatePairException : Exception
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidSurrogatePairException"/> class.
        /// </summary>
        public InvalidSurrogatePairException()
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidSurrogatePairException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        public InvalidSurrogatePairException(string message)
            : base(message)
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidSurrogatePairException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="inner">The inner exception.</param>
        public InvalidSurrogatePairException(string message, Exception inner)
            : base(message, inner)
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidSurrogatePairException"/> class.
        /// </summary>
        /// <param name="highSurrogate">The high surrogate value which caused the error.</param>
        /// <param name="lowSurrogate">The low surrogate value which caused the error.</param>
        public InvalidSurrogatePairException(char highSurrogate, char lowSurrogate)
        {
            this.HighSurrogate = highSurrogate;
            this.LowSurrogate = lowSurrogate;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidSurrogatePairException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="highSurrogate">The high surrogate value which caused the error.</param>
        /// <param name="lowSurrogate">The low surrogate value which caused the error.</param>
        public InvalidSurrogatePairException(string message, char highSurrogate, char lowSurrogate)
            : base(message)
        {
            this.HighSurrogate = highSurrogate;
            this.LowSurrogate = lowSurrogate;
        }
        /// <summary>
        /// Gets or sets the high surrogate value.
        /// </summary>
        /// <value>The high surrogate.</value>
        public char HighSurrogate
        {
            get;
            protected set;
        }
        /// <summary>
        /// Gets or sets the low surrogate value.
        /// </summary>
        /// <value>The low surrogate.</value>
        public char LowSurrogate
        {
            get;
            protected set;
        }
        /// <summary>
        /// Gets a message that describes the current exception.
        /// </summary>
        /// <returns>The error message that explains the reason for the exception, or an empty string("").</returns>
        public override string Message
        {
            get
            {
                if (this.HighSurrogate == 0 && this.LowSurrogate == 0)
                {
                    return base.Message;
                }
                string surrogatePair = string.Format(
                    CultureInfo.CurrentUICulture,
                    "Surrogate Pair =     {0:x4}:{1:x4}", 
                    Convert.ToInt32(this.HighSurrogate), 
                    Convert.ToInt32(this.LowSurrogate));
                return surrogatePair + Environment.NewLine + "Message: " + base.Message;
            }
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InvalidUnicodeValueException.cs" company="Microsoft Corporation">
//   Copyright (c) 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Thrown when a invalid Unicode valid is encountered.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System;
    using System.Globalization;
    /// <summary>
    /// Thrown when a invalid Unicode valid is encountered.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage(
        "Microsoft.Usage",
        "CA2237:MarkISerializableTypesWithSerializable",
        Justification = "The exception does not leave the application domain and serialization breaks medium trust.")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage(
        "Microsoft.Design",
        "CA1032:ImplementStandardExceptionConstructors",
        Justification = "The exception does not leave the application domain and serialization breaks medium trust.")]
    public class InvalidUnicodeValueException : Exception
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidUnicodeValueException"/> class.
        /// </summary>
        public InvalidUnicodeValueException()
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidUnicodeValueException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        public InvalidUnicodeValueException(string message)
            : base(message)
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidUnicodeValueException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="inner">The inner exception.</param>
        public InvalidUnicodeValueException(string message, Exception inner)
            : base(message, inner)
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidUnicodeValueException"/> class.
        /// </summary>
        /// <param name="value">The invalid value.</param>
        public InvalidUnicodeValueException(int value)
        {
            this.Value = value;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidUnicodeValueException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="value">The invalid value.</param>
        public InvalidUnicodeValueException(string message, int value)
            : base(message)
        {
            this.Value = value;
        }
        /// <summary>
        /// Gets or sets the the invalid value.
        /// </summary>
        /// <value>The invalid value.</value>
        public int Value
        {
            get;
            protected set;
        }
        /// <summary>
        /// Gets a message that describes the current exception.
        /// </summary>
        /// <returns>The error message that explains the reason for the exception, or an empty string("").</returns>
        public override string Message
        {
            get
            {
                if (this.Value == 0)
                {
                    return base.Message;
                }
                return string.Format(CultureInfo.CurrentUICulture, "Value : {0:x4}", this.Value) + Environment.NewLine + "Message: " + base.Message;
            }
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LdapEncoder.cs" company="Microsoft Corporation">
//   Copyright (c) 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides LDAP Encoding methods.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    using System.Text;
    using System.Threading;
    /// <summary>
    /// Provides LDAP Encoding methods.
    /// </summary>
    internal static class LdapEncoder
    {
        /// <summary>
        /// A lock object to use when performing filter safe listing initialization.
        /// </summary>
        private static readonly ReaderWriterLockSlim FilterSafeListSyncLock = new ReaderWriterLockSlim();
        /// <summary>
        /// A lock object to use when performing DN safe listing initialization.
        /// </summary>
        private static readonly ReaderWriterLockSlim DistinguishedNameSafeListSyncLock = new ReaderWriterLockSlim();
        /// <summary>
        /// The values to output for each character when filter encoding.
        /// </summary>
        private static char[][] filterCharacterValues;
        /// <summary>
        /// The values to output for each character when DN encoding.
        /// </summary>
        private static char[][] distinguishedNameCharacterValues;
        /// <summary>
        /// Encodes the input string for use in LDAP filters.
        /// </summary>
        /// <param name="input">The string to encode.</param>
        /// <returns>An encoded version of the input string suitable for use in LDAP filters.</returns>
        internal static string FilterEncode(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }
            if (filterCharacterValues == null)
            {
                InitialiseFilterSafeList();
            }
            // RFC 4515 states strings must be converted to their UTF8 value before search filter encoding.
            // See http://tools.ietf.org/html/rfc4515
            // Conversion to char[] keeps null characters inline.
            byte[] utf8Bytes = Encoding.UTF8.GetBytes(input.ToCharArray());
            char[] encodedInput = new char[utf8Bytes.Length * 3]; // Each byte can potentially be encoded as %xx
            int outputLength = 0;
            FilterSafeListSyncLock.EnterReadLock();
            try
            {
                for (int characterPosition = 0; characterPosition < utf8Bytes.Length; characterPosition++)
                {
                    byte currentCharacter = utf8Bytes[characterPosition];
                    if (filterCharacterValues[currentCharacter] != null)
                    {
                        // Character needs encoding.
                        char[] encodedCharacter = filterCharacterValues[currentCharacter];
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                    }
                    else
                    {
                        // Character does not need encoding.
                        encodedInput[outputLength++] = (char)currentCharacter;
                    }
                }
            }
            finally
            {
                FilterSafeListSyncLock.ExitReadLock();
            }
            return new string(encodedInput, 0, outputLength);
        }
        /// <summary>
        /// Encodes the input string for use in LDAP DNs.
        /// </summary>
        /// <param name="input">The string to encode.</param>
        /// <param name="useInitialCharacterRules">Value indicating whether the special case rules for encoding of spaces and octothorpes at the start of a string are used.</param>
        /// <param name="useFinalCharacterRule">Value indicating whether the special case for encoding of final character spaces is used.</param>
        /// <returns>An encoded version of the input string suitable for use in LDAP DNs.</returns>
        internal static string DistinguishedNameEncode(string input, bool useInitialCharacterRules, bool useFinalCharacterRule)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }
            if (distinguishedNameCharacterValues == null)
            {
                InitialiseDistinguishedNameSafeList();
            }
            byte[] utf8Bytes = Encoding.UTF8.GetBytes(input.ToCharArray());
            char[] encodedInput = new char[utf8Bytes.Length * 3]; // Each byte can potentially be encoded as #xx
            int outputLength = 0;
            DistinguishedNameSafeListSyncLock.EnterReadLock();
            try
            {
                for (int characterPosition = 0; characterPosition < utf8Bytes.Length; characterPosition++)
                {
                    byte currentCharacter = utf8Bytes[characterPosition];
                    if (characterPosition == 0 && currentCharacter == ' ' && useInitialCharacterRules)
                    {
                        // rfc2253 states spaces at the start of a string must be escaped
                        encodedInput[outputLength++] = '\\';
                        encodedInput[outputLength++] = ' ';
                    }
                    else if (characterPosition == 0 && currentCharacter == '#' && useInitialCharacterRules)
                    {
                        // rfc2253 states hashes at the start of a string must be escaped
                        encodedInput[outputLength++] = '\\';
                        encodedInput[outputLength++] = '#';
                    }
                    else if (characterPosition == (utf8Bytes.Length - 1) && currentCharacter == ' ' &&
                             useFinalCharacterRule)
                    {
                        // rfc2253 states spaces at the end of a string must be escaped
                        encodedInput[outputLength++] = '\\';
                        encodedInput[outputLength++] = ' ';
                    }
                    else if (distinguishedNameCharacterValues[currentCharacter] != null)
                    {
                        // Character needs encoding.
                        char[] encodedCharacter = distinguishedNameCharacterValues[currentCharacter];
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                    }
                    else
                    {
                        // Character does not need encoding.
                        encodedInput[outputLength++] = (char)currentCharacter;
                    }
                }
            }
            finally
            {
                DistinguishedNameSafeListSyncLock.ExitReadLock();
            }
            return new string(encodedInput, 0, outputLength);
        }
        /// <summary>
        /// Initializes the LDAP filter safe lists.
        /// </summary>
        private static void InitialiseFilterSafeList()
        {
            FilterSafeListSyncLock.EnterWriteLock();
            try
            {
                if (filterCharacterValues == null)
                {
                    filterCharacterValues = SafeList.Generate(255, SafeList.SlashThenHexValueGenerator);
                    SafeList.PunchSafeList(ref filterCharacterValues, FilterEncodingSafeList());
                }
            }
            finally
            {
                FilterSafeListSyncLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// Provides the safe characters for LDAP filter encoding.
        /// </summary>
        /// <returns>The safe characters for LDAP filter encoding.</returns>
        /// <remarks>See http://tools.ietf.org/html/rfc4515/</remarks>
        private static IEnumerable FilterEncodingSafeList()
        {
            for (int i = 0x20; i <= 0x7E; i++)
            {
                // Escape dangerous filter characters
                // See http://projects.webappsec.org/LDAP-Injection
                if (i == '(' ||
                    i == ')' ||
                    i == '*' ||
                    i == '/' ||
                    i == '\\')
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Initializes the LDAP DN safe lists.
        /// </summary>
        private static void InitialiseDistinguishedNameSafeList()
        {
            DistinguishedNameSafeListSyncLock.EnterWriteLock();
            try
            {
                if (distinguishedNameCharacterValues == null)
                {
                    distinguishedNameCharacterValues = SafeList.Generate(255, SafeList.HashThenHexValueGenerator);
                    SafeList.PunchSafeList(ref distinguishedNameCharacterValues, DistinguishedNameSafeList());
                    // Now mark up the specially listed characters from http://www.ietf.org/rfc/rfc2253.txt
                    EscapeDistinguisedNameCharacter(',');
                    EscapeDistinguisedNameCharacter('+');
                    EscapeDistinguisedNameCharacter('"');
                    EscapeDistinguisedNameCharacter('\\');
                    EscapeDistinguisedNameCharacter('<');
                    EscapeDistinguisedNameCharacter('>');
                    EscapeDistinguisedNameCharacter(';');
                }
            }
            finally
            {
                DistinguishedNameSafeListSyncLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// Provides the safe characters for LDAP filter encoding.
        /// </summary>
        /// <returns>The safe characters for LDAP filter encoding.</returns>
        /// <remarks>See http://www.ietf.org/rfc/rfc2253.txt </remarks>
        private static IEnumerable DistinguishedNameSafeList()
        {
            for (int i = 0x20; i <= 0x7E; i++)
            {
                // RFC mandated escapes.
                if (i == ',' ||
                    i == '+' ||
                    i == '"' ||
                    i == '\\' ||
                    i == '<' ||
                    i == '>')
                {
                    continue;
                }
                // Safety escapes
                // See http://projects.webappsec.org/LDAP-Injection
                if (i == '&' ||
                    i == '!' ||
                    i == '|' ||
                    i == '=' ||
                    i == '-' ||
                    i == '\'' ||
                    i == ';')
                {
                    continue;
                }
                yield return i;
            }
        }
        /// <summary>
        /// Escapes a special DN character.
        /// </summary>
        /// <param name="c">The character to escape.</param>
        private static void EscapeDistinguisedNameCharacter(char c)
        {
            distinguishedNameCharacterValues[c] = new[] { '\\', c };
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SafeList.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides safe list utility functions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    using System.Globalization;
    /// <summary>
    /// Provides safe list utility functions.
    /// </summary>
    internal static class SafeList
    {
        /// <summary>
        /// Generates a safe character array representing the specified value.
        /// </summary>
        /// <returns>A safe character array representing the specified value.</returns>
        /// <param name="value">The value to generate a safe representation for.</param>
        internal delegate char[] GenerateSafeValue(int value);
        /// <summary>
        /// Generates a new safe list of the specified size, using the specified function to produce safe values.
        /// </summary>
        /// <param name="length">The length of the safe list to generate.</param>
        /// <param name="generateSafeValue">The <see cref="GenerateSafeValue"/> function to use.</param>
        /// <returns>A new safe list.</returns>
        internal static char[][] Generate(int length, GenerateSafeValue generateSafeValue)
        {
            char[][] allCharacters = new char[length + 1][];
            for (int i = 0; i <= length; i++)
            {
                allCharacters[i] = generateSafeValue(i);
            }
            return allCharacters;
        }
        /// <summary>
        /// Marks characters from the specified languages as safe.
        /// </summary>
        /// <param name="safeList">The safe list to punch holes in.</param>
        /// <param name="lowerCodeCharts">The combination of lower code charts to use.</param>
        /// <param name="lowerMidCodeCharts">The combination of lower mid code charts to use.</param>
        /// <param name="midCodeCharts">The combination of mid code charts to use.</param>
        /// <param name="upperMidCodeCharts">The combination of upper mid code charts to use.</param>
        /// <param name="upperCodeCharts">The combination of upper code charts to use.</param>
        internal static void PunchUnicodeThrough(
            ref char[][] safeList,
            LowerCodeCharts lowerCodeCharts, 
            LowerMidCodeCharts lowerMidCodeCharts, 
            MidCodeCharts midCodeCharts, 
            UpperMidCodeCharts upperMidCodeCharts, 
            UpperCodeCharts upperCodeCharts)
        {
            if (lowerCodeCharts != LowerCodeCharts.None)
            {
                PunchCodeCharts(ref safeList, lowerCodeCharts);
            }
            if (lowerMidCodeCharts != LowerMidCodeCharts.None)
            {
                PunchCodeCharts(ref safeList, lowerMidCodeCharts);
            }
            if (midCodeCharts != MidCodeCharts.None)
            {
                PunchCodeCharts(ref safeList, midCodeCharts);
            }
            if (upperMidCodeCharts != UpperMidCodeCharts.None)
            {
                PunchCodeCharts(ref safeList, upperMidCodeCharts);
            }
            if (upperCodeCharts != UpperCodeCharts.None)
            {
                PunchCodeCharts(ref safeList, upperCodeCharts);
            }
        }
        /// <summary>
        /// Punches holes as necessary.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="whiteListedCharacters">The list of character positions to punch.</param>
        internal static void PunchSafeList(ref char[][] safeList, IEnumerable whiteListedCharacters)
        {
            PunchHolesIfNeeded(ref safeList, true, whiteListedCharacters);
        }
        /// <summary>
        /// Generates a hash prefixed character array representing the specified value.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>#1</description></item>
        /// <item><term>10</term><description>#10</description></item>
        /// <item><term>100</term><description>#100</description></item>
        /// </list>
        /// </remarks>
        internal static char[] HashThenValueGenerator(int value)
        {
            return StringToCharArrayWithHashPrefix(value.ToString(CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a hash prefixed character array representing the specified value in hexadecimal.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>#1</description></item>
        /// <item><term>10</term><description>#0a</description></item>
        /// <item><term>100</term><description>#64</description></item>
        /// </list>
        /// </remarks>
        internal static char[] HashThenHexValueGenerator(int value)
        {
            return StringToCharArrayWithHashPrefix(value.ToString("x2", CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a percent prefixed character array representing the specified value in hexadecimal.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>%01</description></item>
        /// <item><term>10</term><description>%0a</description></item>
        /// <item><term>100</term><description>%64</description></item>
        /// </list>
        /// </remarks>
        internal static char[] PercentThenHexValueGenerator(int value)
        {
            return StringToCharArrayWithPercentPrefix(value.ToString("x2", CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a slash prefixed character array representing the specified value in hexadecimal.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>\01</description></item>
        /// <item><term>10</term><description>\0a</description></item>
        /// <item><term>100</term><description>\64</description></item>
        /// </list>
        /// </remarks>
        internal static char[] SlashThenHexValueGenerator(int value)
        {
            return StringToCharArrayWithSlashPrefix(value.ToString("x2", CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a slash prefixed character array representing the specified value in hexadecimal.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>\000001</description></item>
        /// <item><term>10</term><description>\000000A</description></item>
        /// <item><term>100</term><description>\000064</description></item>
        /// </list>
        /// </remarks>
        internal static char[] SlashThenSixDigitHexValueGenerator(long value)
        {
            return StringToCharArrayWithSlashPrefix(value.ToString("X6", CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a slash prefixed character array representing the specified value in hexadecimal.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>\000001</description></item>
        /// <item><term>10</term><description>\000000A</description></item>
        /// <item><term>100</term><description>\000064</description></item>
        /// </list>
        /// </remarks>
        internal static char[] SlashThenSixDigitHexValueGenerator(int value)
        {
            return StringToCharArrayWithSlashPrefix(value.ToString("X6", CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a hash prefixed character array representing the specified value.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>#1</description></item>
        /// <item><term>10</term><description>#10</description></item>
        /// <item><term>100</term><description>#100</description></item>
        /// </list>
        /// </remarks>
        internal static char[] HashThenValueGenerator(long value)
        {
            return StringToCharArrayWithHashPrefix(value.ToString(CultureInfo.InvariantCulture));
        }
        /// <summary>
        /// Generates a hash prefixed character array from the specified string.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>#1</description></item>
        /// <item><term>10</term><description>#10</description></item>
        /// <item><term>100</term><description>#100</description></item>
        /// </list>
        /// </remarks>
        private static char[] StringToCharArrayWithHashPrefix(string value)
        {
            return StringToCharArrayWithPrefix(value, '#');            
        }
        /// <summary>
        /// Generates a percent prefixed character array from the specified string.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>%1</description></item>
        /// <item><term>10</term><description>%10</description></item>
        /// <item><term>100</term><description>%100</description></item>
        /// </list>
        /// </remarks>
        private static char[] StringToCharArrayWithPercentPrefix(string value)
        {
            return StringToCharArrayWithPrefix(value, '%');            
        }
        /// <summary>
        /// Generates a slash prefixed character array from the specified string.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <returns>A character array representing the specified value.</returns>
        /// <remarks>
        /// Example inputs and encoded outputs:
        /// <list type="table">
        /// <item><term>1</term><description>\1</description></item>
        /// <item><term>10</term><description>\10</description></item>
        /// <item><term>100</term><description>\100</description></item>
        /// </list>
        /// </remarks>
        private static char[] StringToCharArrayWithSlashPrefix(string value)
        {
            return StringToCharArrayWithPrefix(value, '\\');
        }
        /// <summary>
        /// Generates a prefixed character array from the specified string and prefix.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <param name="prefix">The prefix to use.</param>
        /// <returns>A prefixed character array representing the specified value.</returns>
        private static char[] StringToCharArrayWithPrefix(string value, char prefix)
        {
            int valueAsStringLength = value.Length;
            char[] valueAsCharArray = new char[valueAsStringLength + 1];
            valueAsCharArray[0] = prefix;
            for (int j = 0; j < valueAsStringLength; j++)
            {
                valueAsCharArray[j + 1] = value[j];
            }
            return valueAsCharArray;
        }
        /// <summary>
        /// Punch appropriate holes for the selected code charts.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="codeCharts">The code charts to punch.</param>
        private static void PunchCodeCharts(ref char[][] safeList, LowerCodeCharts codeCharts)
        {
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.BasicLatin), CodeCharts.Lower.BasicLatin());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.C1ControlsAndLatin1Supplement), CodeCharts.Lower.Latin1Supplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.LatinExtendedA), CodeCharts.Lower.LatinExtendedA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.LatinExtendedB), CodeCharts.Lower.LatinExtendedB());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.IpaExtensions), CodeCharts.Lower.IpaExtensions());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.SpacingModifierLetters), CodeCharts.Lower.SpacingModifierLetters());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.CombiningDiacriticalMarks), CodeCharts.Lower.CombiningDiacriticalMarks());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.GreekAndCoptic), CodeCharts.Lower.GreekAndCoptic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Cyrillic), CodeCharts.Lower.Cyrillic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.CyrillicSupplement), CodeCharts.Lower.CyrillicSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Armenian), CodeCharts.Lower.Armenian());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Hebrew), CodeCharts.Lower.Hebrew());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Arabic), CodeCharts.Lower.Arabic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Syriac), CodeCharts.Lower.Syriac());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.ArabicSupplement), CodeCharts.Lower.ArabicSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Thaana), CodeCharts.Lower.Thaana());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Nko), CodeCharts.Lower.Nko());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Samaritan), CodeCharts.Lower.Samaritan());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Devanagari), CodeCharts.Lower.Devanagari());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Bengali), CodeCharts.Lower.Bengali());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Gurmukhi), CodeCharts.Lower.Gurmukhi());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Gujarati), CodeCharts.Lower.Gujarati());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Oriya), CodeCharts.Lower.Oriya());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Tamil), CodeCharts.Lower.Tamil());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Telugu), CodeCharts.Lower.Telugu());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Kannada), CodeCharts.Lower.Kannada());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Malayalam), CodeCharts.Lower.Malayalam());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Sinhala), CodeCharts.Lower.Sinhala());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Thai), CodeCharts.Lower.Thai());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Lao), CodeCharts.Lower.Lao());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Lower.IsFlagSet(codeCharts, LowerCodeCharts.Tibetan), CodeCharts.Lower.Tibetan());
        }
        /// <summary>
        /// Punch appropriate holes for the selected code charts.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="codeCharts">The code charts to punch.</param>
        private static void PunchCodeCharts(ref char[][] safeList, LowerMidCodeCharts codeCharts)
        {
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Myanmar), CodeCharts.LowerMiddle.Myanmar());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Georgian), CodeCharts.LowerMiddle.Georgian());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.HangulJamo), CodeCharts.LowerMiddle.HangulJamo());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Ethiopic), CodeCharts.LowerMiddle.Ethiopic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.EthiopicSupplement), CodeCharts.LowerMiddle.EthiopicSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Cherokee), CodeCharts.LowerMiddle.Cherokee());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.UnifiedCanadianAboriginalSyllabics), CodeCharts.LowerMiddle.UnifiedCanadianAboriginalSyllabics());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Ogham), CodeCharts.LowerMiddle.Ogham());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Runic), CodeCharts.LowerMiddle.Runic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Tagalog), CodeCharts.LowerMiddle.Tagalog());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Hanunoo), CodeCharts.LowerMiddle.Hanunoo());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Buhid), CodeCharts.LowerMiddle.Buhid());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Tagbanwa), CodeCharts.LowerMiddle.Tagbanwa());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Khmer), CodeCharts.LowerMiddle.Khmer());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Mongolian), CodeCharts.LowerMiddle.Mongolian());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.UnifiedCanadianAboriginalSyllabicsExtended), CodeCharts.LowerMiddle.UnifiedCanadianAboriginalSyllabicsExtended());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Limbu), CodeCharts.LowerMiddle.Limbu());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.TaiLe), CodeCharts.LowerMiddle.TaiLe());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.NewTaiLue), CodeCharts.LowerMiddle.NewTaiLue());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.KhmerSymbols), CodeCharts.LowerMiddle.KhmerSymbols());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Buginese), CodeCharts.LowerMiddle.Buginese());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.TaiTham), CodeCharts.LowerMiddle.TaiTham());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Balinese), CodeCharts.LowerMiddle.Balinese());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Sudanese), CodeCharts.LowerMiddle.Sudanese());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.Lepcha), CodeCharts.LowerMiddle.Lepcha());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.OlChiki), CodeCharts.LowerMiddle.OlChiki());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.VedicExtensions), CodeCharts.LowerMiddle.VedicExtensions());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.PhoneticExtensions), CodeCharts.LowerMiddle.PhoneticExtensions());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.PhoneticExtensionsSupplement), CodeCharts.LowerMiddle.PhoneticExtensionsSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.CombiningDiacriticalMarksSupplement), CodeCharts.LowerMiddle.CombiningDiacriticalMarksSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.LowerMiddle.IsFlagSet(codeCharts, LowerMidCodeCharts.LatinExtendedAdditional), CodeCharts.LowerMiddle.LatinExtendedAdditional());
        }
        /// <summary>
        /// Punch appropriate holes for the selected code charts.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="codeCharts">The code charts to punch.</param>
        private static void PunchCodeCharts(ref char[][] safeList, MidCodeCharts codeCharts)
        {
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GreekExtended), CodeCharts.Middle.GreekExtended());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GeneralPunctuation), CodeCharts.Middle.GeneralPunctuation());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SuperscriptsAndSubscripts), CodeCharts.Middle.SuperscriptsAndSubscripts());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.CurrencySymbols), CodeCharts.Middle.CurrencySymbols());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.CombiningDiacriticalMarksForSymbols), CodeCharts.Middle.CombiningDiacriticalMarksForSymbols());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.LetterlikeSymbols), CodeCharts.Middle.LetterlikeSymbols());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.NumberForms), CodeCharts.Middle.NumberForms());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Arrows), CodeCharts.Middle.Arrows());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MathematicalOperators), CodeCharts.Middle.MathematicalOperators());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousTechnical), CodeCharts.Middle.MiscellaneousTechnical());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.ControlPictures), CodeCharts.Middle.ControlPictures());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.OpticalCharacterRecognition), CodeCharts.Middle.OpticalCharacterRecognition());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.EnclosedAlphanumerics), CodeCharts.Middle.EnclosedAlphanumerics());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.BoxDrawing), CodeCharts.Middle.BoxDrawing());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.BlockElements), CodeCharts.Middle.BlockElements());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GeometricShapes), CodeCharts.Middle.GeometricShapes());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousSymbols), CodeCharts.Middle.MiscellaneousSymbols());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Dingbats), CodeCharts.Middle.Dingbats());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousMathematicalSymbolsA), CodeCharts.Middle.MiscellaneousMathematicalSymbolsA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SupplementalArrowsA), CodeCharts.Middle.SupplementalArrowsA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.BraillePatterns), CodeCharts.Middle.BraillePatterns());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SupplementalArrowsB), CodeCharts.Middle.SupplementalArrowsB());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousMathematicalSymbolsB), CodeCharts.Middle.MiscellaneousMathematicalSymbolsB());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.SupplementalMathematicalOperators), CodeCharts.Middle.SupplementalMathematicalOperators());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.MiscellaneousSymbolsAndArrows), CodeCharts.Middle.MiscellaneousSymbolsAndArrows());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Glagolitic), CodeCharts.Middle.Glagolitic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.LatinExtendedC), CodeCharts.Middle.LatinExtendedC());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Coptic), CodeCharts.Middle.Coptic());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.GeorgianSupplement), CodeCharts.Middle.GeorgianSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.Tifinagh), CodeCharts.Middle.Tifinagh());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Middle.IsFlagSet(codeCharts, MidCodeCharts.EthiopicExtended), CodeCharts.Middle.EthiopicExtended());
        }
        /// <summary>
        /// Punch appropriate holes for the selected code charts.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="codeCharts">The code charts to punch.</param>
        private static void PunchCodeCharts(ref char[][] safeList, UpperMidCodeCharts codeCharts)
        {
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CyrillicExtendedA), CodeCharts.UpperMiddle.CyrillicExtendedA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.SupplementalPunctuation), CodeCharts.UpperMiddle.SupplementalPunctuation());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkRadicalsSupplement), CodeCharts.UpperMiddle.CjkRadicalsSupplement());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.KangxiRadicals), CodeCharts.UpperMiddle.KangxiRadicals());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.IdeographicDescriptionCharacters), CodeCharts.UpperMiddle.IdeographicDescriptionCharacters());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkSymbolsAndPunctuation), CodeCharts.UpperMiddle.CjkSymbolsAndPunctuation());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Hiragana), CodeCharts.UpperMiddle.Hiragana());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Katakana), CodeCharts.UpperMiddle.Katakana());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Bopomofo), CodeCharts.UpperMiddle.Bopomofo());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.HangulCompatibilityJamo), CodeCharts.UpperMiddle.HangulCompatibilityJamo());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Kanbun), CodeCharts.UpperMiddle.Kanbun());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.BopomofoExtended), CodeCharts.UpperMiddle.BopomofoExtended());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkStrokes), CodeCharts.UpperMiddle.CjkStrokes());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.KatakanaPhoneticExtensions), CodeCharts.UpperMiddle.KatakanaPhoneticExtensions());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.EnclosedCjkLettersAndMonths), CodeCharts.UpperMiddle.EnclosedCjkLettersAndMonths());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkCompatibility), CodeCharts.UpperMiddle.CjkCompatibility());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkUnifiedIdeographsExtensionA), CodeCharts.UpperMiddle.CjkUnifiedIdeographsExtensionA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.YijingHexagramSymbols), CodeCharts.UpperMiddle.YijingHexagramSymbols());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CjkUnifiedIdeographs), CodeCharts.UpperMiddle.CjkUnifiedIdeographs());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.YiSyllables), CodeCharts.UpperMiddle.YiSyllables());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.YiRadicals), CodeCharts.UpperMiddle.YiRadicals());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Lisu), CodeCharts.UpperMiddle.Lisu());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Vai), CodeCharts.UpperMiddle.Vai());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CyrillicExtendedB), CodeCharts.UpperMiddle.CyrillicExtendedB());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Bamum), CodeCharts.UpperMiddle.Bamum());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.ModifierToneLetters), CodeCharts.UpperMiddle.ModifierToneLetters());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.LatinExtendedD), CodeCharts.UpperMiddle.LatinExtendedD());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.SylotiNagri), CodeCharts.UpperMiddle.SylotiNagri());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.CommonIndicNumberForms), CodeCharts.UpperMiddle.CommonIndicNumberForms());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Phagspa), CodeCharts.UpperMiddle.Phagspa());
            PunchHolesIfNeeded(ref safeList, CodeCharts.UpperMiddle.IsFlagSet(codeCharts, UpperMidCodeCharts.Saurashtra), CodeCharts.UpperMiddle.Saurashtra());
        }
        /// <summary>
        /// Punch appropriate holes for the selected code charts.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="codeCharts">The code charts to punch.</param>
        private static void PunchCodeCharts(ref char[][] safeList, UpperCodeCharts codeCharts)
        {
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.DevanagariExtended), CodeCharts.Upper.DevanagariExtended());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.KayahLi), CodeCharts.Upper.KayahLi());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Rejang), CodeCharts.Upper.Rejang());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HangulJamoExtendedA), CodeCharts.Upper.HangulJamoExtendedA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Javanese), CodeCharts.Upper.Javanese());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Cham), CodeCharts.Upper.Cham());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.MyanmarExtendedA), CodeCharts.Upper.MyanmarExtendedA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.TaiViet), CodeCharts.Upper.TaiViet());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.MeeteiMayek), CodeCharts.Upper.MeeteiMayek());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HangulSyllables), CodeCharts.Upper.HangulSyllables());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HangulJamoExtendedB), CodeCharts.Upper.HangulJamoExtendedB());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.CjkCompatibilityIdeographs), CodeCharts.Upper.CjkCompatibilityIdeographs());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.AlphabeticPresentationForms), CodeCharts.Upper.AlphabeticPresentationForms());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.ArabicPresentationFormsA), CodeCharts.Upper.ArabicPresentationFormsA());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.VariationSelectors), CodeCharts.Upper.VariationSelectors());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.VerticalForms), CodeCharts.Upper.VerticalForms());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.CombiningHalfMarks), CodeCharts.Upper.CombiningHalfMarks());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.CjkCompatibilityForms), CodeCharts.Upper.CjkCompatibilityForms());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.SmallFormVariants), CodeCharts.Upper.SmallFormVariants());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.ArabicPresentationFormsB), CodeCharts.Upper.ArabicPresentationFormsB());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.HalfWidthAndFullWidthForms), CodeCharts.Upper.HalfWidthAndFullWidthForms());
            PunchHolesIfNeeded(ref safeList, CodeCharts.Upper.IsFlagSet(codeCharts, UpperCodeCharts.Specials), CodeCharts.Upper.Specials());
        }
        /// <summary>
        /// Punches holes as necessary.
        /// </summary>
        /// <param name="safeList">The safe list to punch through.</param>
        /// <param name="isNeeded">Value indicating whether the holes should be punched.</param>
        /// <param name="whiteListedCharacters">The list of character positions to punch.</param>
        private static void PunchHolesIfNeeded(ref char[][] safeList, bool isNeeded, IEnumerable whiteListedCharacters)
        {
            if (!isNeeded)
            {
                return;
            }
            foreach (int offset in whiteListedCharacters)
            {
                safeList[offset] = null;
            }
        }
    }
}
namespace Microsoft.Security.Application
{
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UnicodeCharacterEncoder.cs" company="Microsoft Corporation">
//   Copyright (c) 2008, 2009, 2010 All Rights Reserved, Microsoft Corporation
//
//   This source is subject to the Microsoft Permissive License.
//   Please see the License.txt file for more information.
//   All other rights reserved.
//
//   THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
// </copyright>
// <summary>
//   Provides HTML Encoding methods.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
    using System.Threading;
    /// <summary>
    /// Provides HTML encoding methods.
    /// </summary>
    public static class UnicodeCharacterEncoder
    {
        /// <summary>
        /// A lock object to use when performing safe listing.
        /// </summary>
        private static readonly ReaderWriterLockSlim SyncLock = new ReaderWriterLockSlim();
        /// <summary>
        /// The HTML escaped value for a space, used in attribute encoding.
        /// </summary>
        private static readonly char[] UnicodeSpace = " ".ToCharArray();
        /// <summary>
        /// The Unicode value for an apostrophe, used in attribute encoding.
        /// </summary>
        private static readonly char[] UnicodeApostrophe = "'".ToCharArray();
        /// <summary>
        /// The XML named entity for an apostrophe, used in XML encoding.
        /// </summary>
        private static readonly char[] XmlApostrophe = "&apos;".ToCharArray();
        /// <summary>
        /// The current lower code chart settings.
        /// </summary>
        private static LowerCodeCharts currentLowerCodeChartSettings = LowerCodeCharts.None;
        /// <summary>
        /// The current lower middle code chart settings.
        /// </summary>
        private static LowerMidCodeCharts currentLowerMidCodeChartSettings = LowerMidCodeCharts.None;
        /// <summary>
        /// The current middle code chart settings.
        /// </summary>
        private static MidCodeCharts currentMidCodeChartSettings = MidCodeCharts.None;
        /// <summary>
        /// The current upper middle code chart settings.
        /// </summary>
        private static UpperMidCodeCharts currentUpperMidCodeChartSettings = UpperMidCodeCharts.None;
        /// <summary>
        /// The current upper code chart settings.
        /// </summary>
        private static UpperCodeCharts currentUpperCodeChartSettings = UpperCodeCharts.None;
        /// <summary>
        /// The values to output for each character.
        /// </summary>
        private static char[][] characterValues;
        /// <summary>
        /// The values to output for HTML named entities.
        /// </summary>
        private static char[][] namedEntities;
        /// <summary>
        /// Provides method specific encoding of characters.
        /// </summary>
        /// <param name="input">The character to encode</param>
        /// <param name="output">The encoded character, if it has been encoded.</param>
        /// <returns>True if the character has been encoded, otherwise false.</returns>
        private delegate bool MethodSpecificEncoder(char input, out char[] output);
        /// <summary>
        /// Marks characters from the specified languages as safe.
        /// </summary>
        /// <param name="lowerCodeCharts">The combination of lower code charts to use.</param>
        /// <param name="lowerMidCodeCharts">The combination of lower mid code charts to use.</param>
        /// <param name="midCodeCharts">The combination of mid code charts to use.</param>
        /// <param name="upperMidCodeCharts">The combination of upper mid code charts to use.</param>
        /// <param name="upperCodeCharts">The combination of upper code charts to use.</param>
        /// <remarks>The safe list affects all HTML and XML encoding functions.</remarks>
        public static void MarkAsSafe(
            LowerCodeCharts lowerCodeCharts,
            LowerMidCodeCharts lowerMidCodeCharts,
            MidCodeCharts midCodeCharts,
            UpperMidCodeCharts upperMidCodeCharts,
            UpperCodeCharts upperCodeCharts)
        {
            if (lowerCodeCharts == currentLowerCodeChartSettings &&
                lowerMidCodeCharts == currentLowerMidCodeChartSettings &&
                midCodeCharts == currentMidCodeChartSettings &&
                upperMidCodeCharts == currentUpperMidCodeChartSettings &&
                upperCodeCharts == currentUpperCodeChartSettings)
            {
                return;
            }
            SyncLock.EnterWriteLock();
            try
            {
                if (characterValues == null)
                {
                    characterValues = SafeList.Generate(65536, SafeList.HashThenValueGenerator);
                }
                SafeList.PunchUnicodeThrough(
                    ref characterValues,
                    lowerCodeCharts,
                    lowerMidCodeCharts,
                    midCodeCharts,
                    upperMidCodeCharts,
                    upperCodeCharts);
                ApplyHtmlSpecificValues();
                currentLowerCodeChartSettings = lowerCodeCharts;
                currentLowerMidCodeChartSettings = lowerMidCodeCharts;
                currentMidCodeChartSettings = midCodeCharts;
                currentUpperMidCodeChartSettings = upperMidCodeCharts;
                currentUpperCodeChartSettings = upperCodeCharts;
            }
            finally
            {
                SyncLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// Encodes input strings for use in XML.
        /// </summary>
        /// <param name="input">String to be encoded</param>
        /// <returns>
        /// Encoded string for use in XML.
        /// </returns>
        internal static string XmlEncode(string input)
        {
            return HtmlEncode(input, false, XmlTweak);
        }
        /// <summary>
        /// Encodes input strings for use in XML.
        /// </summary>
        /// <param name="input">String to be encoded</param>
        /// <returns>
        /// Encoded string for use in XML.
        /// </returns>
        internal static string XmlAttributeEncode(string input)
        {
            return HtmlEncode(input, false, XmlAttributeTweak);
        }
        /// <summary>
        /// Encodes input strings for use in HTML attributes.
        /// </summary>
        /// <param name="input">String to be encoded</param>
        /// <returns>
        /// Encoded string for use in HTML attributes.
        /// </returns>
        internal static string HtmlAttributeEncode(string input)
        {
            return HtmlEncode(input, false, HtmlAttributeTweak);
        }
        /// <summary>
        /// Encodes input strings for use in HTML.
        /// </summary>
        /// <param name="input">String to be encoded</param>
        /// <param name="useNamedEntities">Value indicating if the HTML 4.0 named entities should be used.</param>
        /// <returns>
        /// Encoded string for use in HTML.
        /// </returns>
        internal static string HtmlEncode(string input, bool useNamedEntities)
        {
            return HtmlEncode(input, useNamedEntities, null);
        }
        /// <summary>
        /// HTML Attribute Encoding specific tweaks.
        /// </summary>
        /// <param name="input">The character to potentially encode.</param>
        /// <param name="output">The encoded character, if any.</param>
        /// <returns>True if encoding took place, otherwise false.</returns>
        private static bool HtmlAttributeTweak(char input, out char[] output)
        {
            if (input == '\'')
            {
                output = UnicodeApostrophe;
                return true;
            }
            if (input == ' ')
            {
                output = UnicodeSpace;
                return true;
            }
            output = null;
            return false;
        }
        /// <summary>
        /// XML specific tweaks.
        /// </summary>
        /// <param name="input">The character to potentially encode.</param>
        /// <param name="output">The encoded character, if any.</param>
        /// <returns>True if encoding took place, otherwise false.</returns>
        private static bool XmlTweak(char input, out char[] output)
        {
            if (input == '\'')
            {
                output = XmlApostrophe;
                return true;
            }
            output = null;
            return false;
        }
        /// <summary>
        /// XML Attribute Encoding specific tweaks.
        /// </summary>
        /// <param name="input">The character to potentially encode.</param>
        /// <param name="output">The encoded character, if any.</param>
        /// <returns>True if encoding took place, otherwise false.</returns>
        private static bool XmlAttributeTweak(char input, out char[] output)
        {
            if (input == '\'')
            {
                output = XmlApostrophe;
                return true;
            }
            if (input == ' ')
            {
                output = UnicodeSpace;
                return true;
            }
            output = null;
            return false;
        }
        /// <summary>
        /// Encodes input strings for use in HTML.
        /// </summary>
        /// <param name="input">String to be encoded</param>
        /// <param name="useNamedEntities">Value indicating if the HTML 4.0 named entities should be used.</param>
        /// <param name="encoderTweak">A <see cref="MethodSpecificEncoder"/> function, if needed.</param>
        /// <returns>
        /// Encoded string for use in HTML.
        /// </returns>
        /// <exception cref="InvalidUnicodeValueException">Thrown if a character with an invalid Unicode value is encountered within the input string.</exception>
        /// <exception cref="InvalidSurrogatePairException">Thrown if a high surrogate code point is encoded without a following low surrogate code point, or a 
        /// low surrogate code point is encounter without having been preceded by a high surrogate code point.</exception>
        private static string HtmlEncode(string input, bool useNamedEntities, MethodSpecificEncoder encoderTweak)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }
            if (characterValues == null)
            {
                InitialiseSafeList();
            }
            if (useNamedEntities && namedEntities == null)
            {
                InitialiseNamedEntityList();
            }
            // Setup a new character array for output.
            char[] inputAsArray = input.ToCharArray();
            int outputLength = 0;
            int inputLength = inputAsArray.Length;
            char[] encodedInput = new char[inputLength * 10]; // Worse case scenario - the longest entity name, thetasym is 10 characters, including the & and ;.
            SyncLock.EnterReadLock();
            try
            {
                for (int i = 0; i < inputLength; i++)
                {
                    char currentCharacter = inputAsArray[i];
                    int currentCodePoint = inputAsArray[i];
                    char[] tweekedValue;
                    // Check for invalid values
                    if (currentCodePoint == 0xFFFE ||
                        currentCodePoint == 0xFFFF)
                    {
                        throw new InvalidUnicodeValueException(currentCodePoint);
                    }
                    else if (char.IsHighSurrogate(currentCharacter)) 
                    {
                        if (i + 1 == inputLength)
                        {
                            throw new InvalidSurrogatePairException(currentCharacter, '\0');                            
                        }
                        // Now peak ahead and check if the following character is a low surrogate.
                        char nextCharacter = inputAsArray[i + 1];
                        char nextCodePoint = inputAsArray[i + 1];
                        if (!char.IsLowSurrogate(nextCharacter))
                        {
                            throw new InvalidSurrogatePairException(currentCharacter, nextCharacter);
                        }
                        // Look-ahead was good, so skip.
                        i++;
                        // Calculate the combined code point
                        long combinedCodePoint =
                            0x10000 + ((currentCodePoint - 0xD800) * 0x400) + (nextCodePoint - 0xDC00);
                        char[] encodedCharacter = SafeList.HashThenValueGenerator(combinedCodePoint);
                        encodedInput[outputLength++] = '&';
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                        encodedInput[outputLength++] = ';';
                    }
                    else if (char.IsLowSurrogate(currentCharacter))
                    {
                        throw new InvalidSurrogatePairException('\0', currentCharacter);    
                    }
                    else if (encoderTweak != null && encoderTweak(currentCharacter, out tweekedValue))
                    {
                        for (int j = 0; j < tweekedValue.Length; j++)
                        {
                            encodedInput[outputLength++] = tweekedValue[j];
                        }
                    }
                    else if (useNamedEntities && namedEntities[currentCodePoint] != null)
                    {
                        char[] encodedCharacter = namedEntities[currentCodePoint];
                        encodedInput[outputLength++] = '&';
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                        encodedInput[outputLength++] = ';';
                    }
                    else if (characterValues[currentCodePoint] != null)
                    {
                        // character needs to be encoded
                        char[] encodedCharacter = characterValues[currentCodePoint];
                        encodedInput[outputLength++] = '&';
                        for (int j = 0; j < encodedCharacter.Length; j++)
                        {
                            encodedInput[outputLength++] = encodedCharacter[j];
                        }
                        encodedInput[outputLength++] = ';';
                    }
                    else
                    {
                        // character does not need encoding
                        encodedInput[outputLength++] = currentCharacter;
                    }
                }
            }
            finally
            {
                SyncLock.ExitReadLock();
            }
            return new string(encodedInput, 0, outputLength);
        }
        /// <summary>
        /// Initializes the HTML safe list.
        /// </summary>
        private static void InitialiseSafeList()
        {
            SyncLock.EnterWriteLock();
            try
            {
                if (characterValues == null)
                {
                    characterValues = SafeList.Generate(0xFFFF, SafeList.HashThenValueGenerator);
                    SafeList.PunchUnicodeThrough(
                        ref characterValues,
                        LowerCodeCharts.Default,
                        LowerMidCodeCharts.None,
                        MidCodeCharts.None,
                        UpperMidCodeCharts.None,
                        UpperCodeCharts.None);
                    ApplyHtmlSpecificValues();
                }
            }
            finally
            {
                SyncLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// Applies Html specific values to the internal value list.
        /// </summary>
        private static void ApplyHtmlSpecificValues()
        {
            characterValues['<'] = "lt".ToCharArray();
            characterValues['>'] = "gt".ToCharArray();
            characterValues['&'] = "amp".ToCharArray();
            characterValues['"'] = "quot".ToCharArray();
        }
        /// <summary>
        /// Initialises the HTML named entities list.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Maintainability", 
            "CA1505:AvoidUnmaintainableCode", 
            Justification = "Splitting or initialising via lookups has too large a performance increase.")]
        private static void InitialiseNamedEntityList()
        {
            namedEntities = new char[65536][];
            namedEntities[160] = "nbsp".ToCharArray();
            namedEntities[161] = "iexcl".ToCharArray();
            namedEntities[162] = "cent".ToCharArray();
            namedEntities[163] = "pound".ToCharArray();
            namedEntities[164] = "curren".ToCharArray();
            namedEntities[165] = "yen".ToCharArray();
            namedEntities[166] = "brvbar".ToCharArray();
            namedEntities[167] = "sect".ToCharArray();
            namedEntities[168] = "uml".ToCharArray();
            namedEntities[169] = "copy".ToCharArray();
            namedEntities[170] = "ordf".ToCharArray();
            namedEntities[171] = "laquo".ToCharArray();
            namedEntities[172] = "not".ToCharArray();
            namedEntities[173] = "shy".ToCharArray();
            namedEntities[174] = "reg".ToCharArray();
            namedEntities[175] = "macr".ToCharArray();
            namedEntities[176] = "deg".ToCharArray();
            namedEntities[177] = "plusmn".ToCharArray();
            namedEntities[178] = "sup2".ToCharArray();
            namedEntities[179] = "sup3".ToCharArray();
            namedEntities[180] = "acute".ToCharArray();
            namedEntities[181] = "micro".ToCharArray();
            namedEntities[182] = "para".ToCharArray();
            namedEntities[183] = "middot".ToCharArray();
            namedEntities[184] = "cedil".ToCharArray();
            namedEntities[185] = "sup1".ToCharArray();
            namedEntities[186] = "ordm".ToCharArray();
            namedEntities[187] = "raquo".ToCharArray();
            namedEntities[188] = "frac14".ToCharArray();
            namedEntities[189] = "frac12".ToCharArray();
            namedEntities[190] = "frac34".ToCharArray();
            namedEntities[191] = "iquest".ToCharArray();
            namedEntities[192] = "Agrave".ToCharArray();
            namedEntities[193] = "Aacute".ToCharArray();
            namedEntities[194] = "Acirc".ToCharArray();
            namedEntities[195] = "Atilde".ToCharArray();
            namedEntities[196] = "Auml".ToCharArray();
            namedEntities[197] = "Aring".ToCharArray();
            namedEntities[198] = "AElig".ToCharArray();
            namedEntities[199] = "Ccedil".ToCharArray();
            namedEntities[200] = "Egrave".ToCharArray();
            namedEntities[201] = "Eacute".ToCharArray();
            namedEntities[202] = "Ecirc".ToCharArray();
            namedEntities[203] = "Euml".ToCharArray();
            namedEntities[204] = "Igrave".ToCharArray();
            namedEntities[205] = "Iacute".ToCharArray();
            namedEntities[206] = "Icirc".ToCharArray();
            namedEntities[207] = "Iuml".ToCharArray();
            namedEntities[208] = "ETH".ToCharArray();
            namedEntities[209] = "Ntilde".ToCharArray();
            namedEntities[210] = "Ograve".ToCharArray();
            namedEntities[211] = "Oacute".ToCharArray();
            namedEntities[212] = "Ocirc".ToCharArray();
            namedEntities[213] = "Otilde".ToCharArray();
            namedEntities[214] = "Ouml".ToCharArray();
            namedEntities[215] = "times".ToCharArray();
            namedEntities[216] = "Oslash".ToCharArray();
            namedEntities[217] = "Ugrave".ToCharArray();
            namedEntities[218] = "Uacute".ToCharArray();
            namedEntities[219] = "Ucirc".ToCharArray();
            namedEntities[220] = "Uuml".ToCharArray();
            namedEntities[221] = "Yacute".ToCharArray();
            namedEntities[222] = "THORN".ToCharArray();
            namedEntities[223] = "szlig".ToCharArray();
            namedEntities[224] = "agrave".ToCharArray();
            namedEntities[225] = "aacute".ToCharArray();
            namedEntities[226] = "acirc".ToCharArray();
            namedEntities[227] = "atilde".ToCharArray();
            namedEntities[228] = "auml".ToCharArray();
            namedEntities[229] = "aring".ToCharArray();
            namedEntities[230] = "aelig".ToCharArray();
            namedEntities[231] = "ccedil".ToCharArray();
            namedEntities[232] = "egrave".ToCharArray();
            namedEntities[233] = "eacute".ToCharArray();
            namedEntities[234] = "ecirc".ToCharArray();
            namedEntities[235] = "euml".ToCharArray();
            namedEntities[236] = "igrave".ToCharArray();
            namedEntities[237] = "iacute".ToCharArray();
            namedEntities[238] = "icirc".ToCharArray();
            namedEntities[239] = "iuml".ToCharArray();
            namedEntities[240] = "eth".ToCharArray();
            namedEntities[241] = "ntilde".ToCharArray();
            namedEntities[242] = "ograve".ToCharArray();
            namedEntities[243] = "oacute".ToCharArray();
            namedEntities[244] = "ocirc".ToCharArray();
            namedEntities[245] = "otilde".ToCharArray();
            namedEntities[246] = "ouml".ToCharArray();
            namedEntities[247] = "divide".ToCharArray();
            namedEntities[248] = "oslash".ToCharArray();
            namedEntities[249] = "ugrave".ToCharArray();
            namedEntities[250] = "uacute".ToCharArray();
            namedEntities[251] = "ucirc".ToCharArray();
            namedEntities[252] = "uuml".ToCharArray();
            namedEntities[253] = "yacute".ToCharArray();
            namedEntities[254] = "thorn".ToCharArray();
            namedEntities[255] = "yuml".ToCharArray();
            namedEntities[338] = "OElig".ToCharArray();
            namedEntities[339] = "oelig".ToCharArray();
            namedEntities[352] = "Scaron".ToCharArray();
            namedEntities[353] = "scaron".ToCharArray();
            namedEntities[376] = "Yuml".ToCharArray();
            namedEntities[402] = "fnof".ToCharArray();
            namedEntities[710] = "circ".ToCharArray();
            namedEntities[732] = "tilde".ToCharArray();
            namedEntities[913] = "Alpha".ToCharArray();
            namedEntities[914] = "Beta".ToCharArray();
            namedEntities[915] = "Gamma".ToCharArray();
            namedEntities[916] = "Delta".ToCharArray();
            namedEntities[917] = "Epsilon".ToCharArray();
            namedEntities[918] = "Zeta".ToCharArray();
            namedEntities[919] = "Eta".ToCharArray();
            namedEntities[920] = "Theta".ToCharArray();
            namedEntities[921] = "Iota".ToCharArray();
            namedEntities[922] = "Kappa".ToCharArray();
            namedEntities[923] = "Lambda".ToCharArray();
            namedEntities[924] = "Mu".ToCharArray();
            namedEntities[925] = "Nu".ToCharArray();
            namedEntities[926] = "Xi".ToCharArray();
            namedEntities[927] = "Omicron".ToCharArray();
            namedEntities[928] = "Pi".ToCharArray();
            namedEntities[929] = "Rho".ToCharArray();
            namedEntities[931] = "Sigma".ToCharArray();
            namedEntities[932] = "Tau".ToCharArray();
            namedEntities[933] = "Upsilon".ToCharArray();
            namedEntities[934] = "Phi".ToCharArray();
            namedEntities[935] = "Chi".ToCharArray();
            namedEntities[936] = "Psi".ToCharArray();
            namedEntities[937] = "Omega".ToCharArray();
            namedEntities[945] = "alpha".ToCharArray();
            namedEntities[946] = "beta".ToCharArray();
            namedEntities[947] = "gamma".ToCharArray();
            namedEntities[948] = "delta".ToCharArray();
            namedEntities[949] = "epsilon".ToCharArray();
            namedEntities[950] = "zeta".ToCharArray();
            namedEntities[951] = "eta".ToCharArray();
            namedEntities[952] = "theta".ToCharArray();
            namedEntities[953] = "iota".ToCharArray();
            namedEntities[954] = "kappa".ToCharArray();
            namedEntities[955] = "lambda".ToCharArray();
            namedEntities[956] = "mu".ToCharArray();
            namedEntities[957] = "nu".ToCharArray();
            namedEntities[958] = "xi".ToCharArray();
            namedEntities[959] = "omicron".ToCharArray();
            namedEntities[960] = "pi".ToCharArray();
            namedEntities[961] = "rho".ToCharArray();
            namedEntities[962] = "sigmaf".ToCharArray();
            namedEntities[963] = "sigma".ToCharArray();
            namedEntities[964] = "tau".ToCharArray();
            namedEntities[965] = "upsilon".ToCharArray();
            namedEntities[966] = "phi".ToCharArray();
            namedEntities[967] = "chi".ToCharArray();
            namedEntities[968] = "psi".ToCharArray();
            namedEntities[969] = "omega".ToCharArray();
            namedEntities[977] = "thetasym".ToCharArray();
            namedEntities[978] = "upsih".ToCharArray();
            namedEntities[982] = "piv".ToCharArray();
            namedEntities[0x2002] = "ensp".ToCharArray();
            namedEntities[0x2003] = "emsp".ToCharArray();
            namedEntities[0x2009] = "thinsp".ToCharArray();
            namedEntities[0x200C] = "zwnj".ToCharArray();
            namedEntities[0x200D] = "zwj".ToCharArray();
            namedEntities[0x200E] = "lrm".ToCharArray();
            namedEntities[0x200F] = "rlm".ToCharArray();
            namedEntities[0x2013] = "ndash".ToCharArray();
            namedEntities[0x2014] = "mdash".ToCharArray();
            namedEntities[0x2018] = "lsquo".ToCharArray();
            namedEntities[0x2019] = "rsquo".ToCharArray();
            namedEntities[0x201A] = "sbquo".ToCharArray();
            namedEntities[0x201C] = "ldquo".ToCharArray();
            namedEntities[0x201D] = "rdquo".ToCharArray();
            namedEntities[0x201E] = "bdquo".ToCharArray();
            namedEntities[0x2020] = "dagger".ToCharArray();
            namedEntities[0x2021] = "Dagger".ToCharArray();
            namedEntities[0x2022] = "bull".ToCharArray();
            namedEntities[0x2026] = "hellip".ToCharArray();
            namedEntities[0x2030] = "permil".ToCharArray();
            namedEntities[0x2032] = "prime".ToCharArray();
            namedEntities[0x2033] = "Prime".ToCharArray();
            namedEntities[0x2039] = "lsaquo".ToCharArray();
            namedEntities[0x203A] = "rsaquo".ToCharArray();
            namedEntities[0x203E] = "oline".ToCharArray();
            namedEntities[0x2044] = "frasl".ToCharArray();
            namedEntities[0x20AC] = "euro".ToCharArray();
            namedEntities[0x2111] = "image".ToCharArray();
            namedEntities[0x2118] = "weierp".ToCharArray();
            namedEntities[0x211C] = "real".ToCharArray();
            namedEntities[0x2122] = "trade".ToCharArray();
            namedEntities[0x2135] = "alefsym".ToCharArray();
            namedEntities[0x2190] = "larr".ToCharArray();
            namedEntities[0x2191] = "uarr".ToCharArray();
            namedEntities[0x2192] = "rarr".ToCharArray();
            namedEntities[0x2193] = "darr".ToCharArray();
            namedEntities[0x2194] = "harr".ToCharArray();
            namedEntities[0x21B5] = "crarr".ToCharArray();
            namedEntities[0x21D0] = "lArr".ToCharArray();
            namedEntities[0x21D1] = "uArr".ToCharArray();
            namedEntities[0x21D2] = "rArr".ToCharArray();
            namedEntities[0x21D3] = "dArr".ToCharArray();
            namedEntities[0x21D4] = "hArr".ToCharArray();
            namedEntities[0x2200] = "forall".ToCharArray();
            namedEntities[0x2202] = "part".ToCharArray();
            namedEntities[0x2203] = "exist".ToCharArray();
            namedEntities[0x2205] = "empty".ToCharArray();
            namedEntities[0x2207] = "nabla".ToCharArray();
            namedEntities[0x2208] = "isin".ToCharArray();
            namedEntities[0x2209] = "notin".ToCharArray();
            namedEntities[0x220B] = "ni".ToCharArray();
            namedEntities[0x220F] = "prod".ToCharArray();
            namedEntities[0x2211] = "sum".ToCharArray();
            namedEntities[0x2212] = "minus".ToCharArray();
            namedEntities[0x2217] = "lowast".ToCharArray();
            namedEntities[0x221A] = "radic".ToCharArray();
            namedEntities[0x221D] = "prop".ToCharArray();
            namedEntities[0x221E] = "infin".ToCharArray();
            namedEntities[0x2220] = "ang".ToCharArray();
            namedEntities[0x2227] = "and".ToCharArray();
            namedEntities[0x2228] = "or".ToCharArray();
            namedEntities[0x2229] = "cap".ToCharArray();
            namedEntities[0x222A] = "cup".ToCharArray();
            namedEntities[0x222B] = "int".ToCharArray();
            namedEntities[0x2234] = "there4".ToCharArray();
            namedEntities[0x223C] = "sim".ToCharArray();
            namedEntities[0x2245] = "cong".ToCharArray();
            namedEntities[0x2248] = "asymp".ToCharArray();
            namedEntities[0x2260] = "ne".ToCharArray();
            namedEntities[0x2261] = "equiv".ToCharArray();
            namedEntities[0x2264] = "le".ToCharArray();
            namedEntities[0x2265] = "ge".ToCharArray();
            namedEntities[0x2282] = "sub".ToCharArray();
            namedEntities[0x2283] = "sup".ToCharArray();
            namedEntities[0x2284] = "nsub".ToCharArray();
            namedEntities[0x2286] = "sube".ToCharArray();
            namedEntities[0x2287] = "supe".ToCharArray();
            namedEntities[0x2295] = "oplus".ToCharArray();
            namedEntities[0x2297] = "otimes".ToCharArray();
            namedEntities[0x22A5] = "perp".ToCharArray();
            namedEntities[0x22C5] = "sdot".ToCharArray();
            namedEntities[0x2308] = "lceil".ToCharArray();
            namedEntities[0x2309] = "rceil".ToCharArray();
            namedEntities[0x230A] = "lfloor".ToCharArray();
            namedEntities[0x230B] = "rfloor".ToCharArray();
            namedEntities[0x2329] = "lang".ToCharArray();
            namedEntities[0x232A] = "rang".ToCharArray();
            namedEntities[0x25CA] = "loz".ToCharArray();
            namedEntities[0x2660] = "spades".ToCharArray();
            namedEntities[0x2663] = "clubs".ToCharArray();
            namedEntities[0x2665] = "hearts".ToCharArray();
            namedEntities[0x2666] = "diams".ToCharArray();
        }
    }
}
//namespace Microsoft.Security.Application
//{
//    using System;
//    using System.Collections.Generic;
//    using System.Linq;
//    using System.Text;
//    using System.Web.Mvc;
//    ///---------------------------------------------------------------------
//    /// <summary>
//    ///     Represents support for creating input and output HTML controls 
//    ///     with attributes and text encoded using Anti-XSS library 
//    ///     encoding methods.
//    /// </summary>
//    /// <remarks>
//    ///     This class provides a set of helper methods whose purpose is to 
//    ///     help you create HTML controls programmatically. These methods 
//    ///     generate HTML controls using the Principle of Inclusions, 
//    ///     sometimes referred to as "safe listing" to provide protection 
//    ///     against injection attacks.  With safe listing protection, 
//    ///     algorithms look for valid inputs and automatically treat 
//    ///     everything outside that set as a potential attack.  This library
//    ///     can be used as a defense in depth approach with other mitigation 
//    ///     techniques. It is suitable for applications with high security 
//    ///     requirements.
//    /// </remarks>
//    ///---------------------------------------------------------------------
//    ///
//    public static class MvcExtensions
//    {
//        /// <summary>
//        /// Returns a string of HTML with span element.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the span element</param>
//        /// <returns>HTML of span element</returns>
//        /// <remarks>
//        /// This method creates a span element with encoded text that is safe to
//        /// display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeLabel(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with span element.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the span element</param>
//        /// <param name="value">Inner text using Object.ToString</param>
//        /// <returns>HTML of span element</returns>
//        /// <remarks>
//        /// This method creates a span element with encoded text that is safe to
//        /// display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeLabel(this HtmlHelper helper, String name, Object value)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with span element.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the span element</param>
//        /// <param name="value">Inner text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of span element</returns>
//        /// <remarks>
//        /// This method creates a span element with encoded text that is safe to
//        /// display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeLabel(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of text type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type text with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeTextbox(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of text type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type text with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeTextbox(this HtmlHelper helper, String name, Object value)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of text type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type text with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeTextbox(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of check type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type check with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeCheckbox(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of check type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type check with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeCheckbox(this HtmlHelper helper, String name, Object value)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of check type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type check with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeCheckbox(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of radio type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type radio with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeRadioButton(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of radio type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type radio with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeRadioButton(this HtmlHelper helper, String name, Object value)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of radio type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type radio with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeRadioButton(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of button type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type button with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeButton(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of button type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type button with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeButton(this HtmlHelper helper, String name, Object value)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of button type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type button with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeButton(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of password type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type password with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafePassword(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of password type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type password with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafePassword(this HtmlHelper helper, String name, Object value)
//        {
//            return "";
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of password type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type password with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafePassword(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of hidden type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type hidden with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeHidden(this HtmlHelper helper, String name)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of hidden type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type hidden with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeHidden(this HtmlHelper helper, String name, Object value)
//        {
//            throw new NotImplementedException();
//        }
//        /// <summary>
//        /// Returns a string of HTML with input element of hidden type.
//        /// </summary>
//        /// <param name="helper">HtmlHelper class</param>
//        /// <param name="name">ID of the input element</param>
//        /// <param name="value">Element text using Object.ToString</param>
//        /// <param name="htmlAttributes">Additional attributes of the element</param>
//        /// <returns>HTML of input element</returns>
//        /// <remarks>
//        /// This method creates a Input element of type hidden with encoded text that 
//        /// is safe to display. Text and attributes are encoded using Anti-XSS Library's
//        /// HtmlEncode and HtmlAttributeEncode method respectively.
//        /// </remarks>
//        public static string SafeHidden(this HtmlHelper helper, String name, Object value, IDictionary<String, Object> htmlAttributes)
//        {
//            throw new NotImplementedException();
//        }
//    }
//}

posted @ 2011-09-10 21:19  于斯人也  阅读(1110)  评论(0编辑  收藏  举报