当前位置: 首页>>代码示例>>C#>>正文


C# NormalizationForm类代码示例

本文整理汇总了C#中NormalizationForm的典型用法代码示例。如果您正苦于以下问题:C# NormalizationForm类的具体用法?C# NormalizationForm怎么用?C# NormalizationForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NormalizationForm类属于命名空间,在下文中一共展示了NormalizationForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsNormalized

        public static bool IsNormalized(this string value, NormalizationForm normalizationForm)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            Contract.EndContractBlock();

            // The only way to know if IsNormalizedString failed is through checking the Win32 last error
            Interop.mincore.SetLastError(Interop.ERROR_SUCCESS);
            bool result = Interop.mincore.IsNormalizedString((int)normalizationForm, value, value.Length);

            int lastError = Marshal.GetLastWin32Error();
            switch (lastError)
            {
                case Interop.ERROR_SUCCESS:
                case Interop.LAST_ERROR_TRASH_VALUE:
                    break;

                case Interop.ERROR_INVALID_PARAMETER:
                case Interop.ERROR_NO_UNICODE_TRANSLATION:
                    throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(value));

                case Interop.ERROR_NOT_ENOUGH_MEMORY:
                    throw new OutOfMemoryException(SR.Arg_OutOfMemoryException);

                default:
                    throw new InvalidOperationException(SR.Format(SR.UnknownError_Num, lastError));
            }

            return result;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:32,代码来源:StringNormalizationExtensions.Windows.cs

示例2: InitializeForm

        [System.Security.SecurityCritical]  // auto-generated
        static private unsafe void InitializeForm(NormalizationForm form, String strDataFile)
        {
#if FEATURE_COREFX_GLOBALIZATION
            //TODO: Implement this fully.  We might need a PAL here.
            throw new NotImplementedException();
#else
            byte* pTables = null;

            // Normalization uses OS on Win8
            if (!Environment.IsWindows8OrAbove)
            {
                if (strDataFile == null)
                {
                    // They were supposed to have a form that we know about!
                    throw new ArgumentException(
                        Environment.GetResourceString("Argument_InvalidNormalizationForm"));
                }

                // Tell the DLL where to find our data
                pTables = GlobalizationAssembly.GetGlobalizationResourceBytePtr(
                   typeof(Normalization).Assembly, strDataFile);
                if (pTables == null)
                {
                    // Unable to load the specified normalizationForm,
                    // tables not loaded from file
                    throw new ArgumentException(
                        Environment.GetResourceString("Argument_InvalidNormalizationForm"));
                }
            }

            nativeNormalizationInitNormalization(form, pTables);
#endif
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:34,代码来源:Normalization.cs

示例3: IsAlwaysNormalized

	public override bool IsAlwaysNormalized (NormalizationForm form)
	{
		if (form != NormalizationForm.FormC)
			return false;

		if (isNormalized == null)
			isNormalized = new byte [0x10000 / 8];
		if (isNormalizedComputed == null)
			isNormalizedComputed = new byte [0x10000 / 8];

		if (normalization_bytes == null) {
			normalization_bytes = new byte [0x100];
			lock (normalization_bytes) {
				for (int i = 0; i < 0x100; i++)
					normalization_bytes [i] = (byte) i;
			}
		}

		byte offset = (byte) (1 << (CodePage % 8));
		if ((isNormalizedComputed [CodePage / 8] & offset) == 0) {
			Encoding e = Clone () as Encoding;
			e.DecoderFallback = new DecoderReplacementFallback ("");
			string s = e.GetString (normalization_bytes);
			// note that the flag only stores FormC information.
			if (s != s.Normalize (form))
				isNormalized [CodePage / 8] |= offset;
			isNormalizedComputed [CodePage / 8] |= offset;
		}

		return (isNormalized [CodePage / 8] & offset) == 0;
	}
开发者ID:Profit0004,项目名称:mono,代码行数:31,代码来源:ByteSafeEncoding.cs

示例4: InitializeForm

        static private unsafe void InitializeForm(NormalizationForm form, String strDataFile)
        {
            byte* pTables = null;

            // Normalization uses OS on Win8
            if (!Environment.IsWindows8OrAbove)
            {
                if (strDataFile == null)
                {
                    // They were supposed to have a form that we know about!
                    throw new ArgumentException(
                        Environment.GetResourceString("Argument_InvalidNormalizationForm"));
                }

                // Tell the DLL where to find our data
                pTables = GlobalizationAssembly.GetGlobalizationResourceBytePtr(
                   typeof(Normalization).Assembly, strDataFile);
                if (pTables == null)
                {
                    // Unable to load the specified normalizationForm,
                    // tables not loaded from file
                    throw new ArgumentException(
                        Environment.GetResourceString("Argument_InvalidNormalizationForm"));
                }
            }

            nativeNormalizationInitNormalization(form, pTables);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:28,代码来源:normalization.cs

示例5: Normalize

		public static String Normalize(this string value, NormalizationForm normalizationForm)
		{
			if (value == null)
				throw new ArgumentNullException (nameof (value));

			return value.Normalize (normalizationForm);
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:StringNormalizationExtensions.cs

示例6: Normalize

        public static string Normalize(this string strInput, NormalizationForm normalizationForm)
        {
            ValidateArguments(strInput, normalizationForm);

            char[] buf = new char[strInput.Length];

            for (int attempts = 2; attempts > 0; attempts--)
            {
                int realLen = Interop.GlobalizationNative.NormalizeString(normalizationForm, strInput, strInput.Length, buf, buf.Length);

                if (realLen == -1)
                {
                    throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
                }

                if (realLen <= buf.Length)
                {
                    return new string(buf, 0, realLen);
                }

                buf = new char[realLen];
            }

            throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:25,代码来源:StringNormalizationExtensions.Unix.cs

示例7: ClearForNormalize

        public static string ClearForNormalize(this string value, NormalizationForm form)
        {
            if (!string.IsNullOrEmpty(value))
            {
                value = value.Replace(":", ""); // removed for solr
                value = value.Replace("ø", "o");

                var sb = new StringBuilder();
                foreach (var c in value.Normalize(form))
                    switch (CharUnicodeInfo.GetUnicodeCategory(c))
                    {
                        case UnicodeCategory.NonSpacingMark:
                        case UnicodeCategory.SpacingCombiningMark:
                        case UnicodeCategory.EnclosingMark:
                            break;

                        default:
                            sb.Append(c);
                            break;
                    }

                return sb.ToString().ToLower();
            }

            return string.Empty;
        }
开发者ID:RossMerr,项目名称:Authentication,代码行数:26,代码来源:StringExtensions.cs

示例8: Normalization

        internal unsafe Normalization(NormalizationForm form, String strDataFile)
        {
            // Remember which form we are
            this.normalizationForm = form;
            // Load the DLL
            if (!nativeLoadNormalizationDLL())
            {
                // Unable to load the normalization DLL!
                throw new ArgumentException(
                    Environment.GetResourceString("Argument_InvalidNormalizationForm"));
            }

            // Tell the DLL where to find our data
            byte* pTables = GlobalizationAssembly.GetGlobalizationResourceBytePtr(
                typeof(Normalization).Assembly, strDataFile);
            if (pTables == null)
            {
                // Unable to load the specified normalizationForm,
                // tables not loaded from file
                throw new ArgumentException(
                    Environment.GetResourceString("Argument_InvalidNormalizationForm"));
            }

            // All we have to do is let the .dll know how to load it, then
            // we can ignore the returned pointer.
            byte* objNorm = nativeNormalizationInitNormalization(form, pTables);
            if (objNorm == null)
            {
                // Unable to load the specified normalizationForm
                // native library class not initialized correctly
                throw new OutOfMemoryException(
                    Environment.GetResourceString("Arg_OutOfMemoryException"));
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:34,代码来源:normalization.cs

示例9: Normalize

 public void Normalize(string value, NormalizationForm normalizationForm, string expected)
 {
     if (normalizationForm == NormalizationForm.FormC)
     {
         Assert.Equal(expected, value.Normalize());
     }
     Assert.Equal(expected, value.Normalize(normalizationForm));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:StringNormalizationTests.cs

示例10: IsNormalized

 public void IsNormalized(string value, NormalizationForm normalizationForm, bool expected)
 {
     if (normalizationForm == NormalizationForm.FormC)
     {
         Assert.Equal(expected, value.IsNormalized());
     }
     Assert.Equal(expected, value.IsNormalized(normalizationForm));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:StringNormalizationTests.cs

示例11: Normalize

        public static string Normalize(this string value, NormalizationForm normalizationForm)
        {
            if (IsNormalized(value, normalizationForm))
            {
                return value;
            }

            throw NotImplemented.ByDesign;
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:StringNormalizationExtensions.Unix.cs

示例12: Normalize

        public static string Normalize(this string strInput, NormalizationForm normalizationForm)
        {
            if (strInput == null)
            {
                throw new ArgumentNullException(nameof(strInput));
            }

            return strInput.Normalize(normalizationForm);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:StringNormalizationExtensions.cs

示例13: IsNormalized

        public static bool IsNormalized(this string value, NormalizationForm normalizationForm)
        {
            for (int i = 0; i < value.Length; i++)
            {
                if (value[i] > 0x7F)
                {
                    throw NotImplemented.ByDesign;
                }
            }

            return true;
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:StringNormalizationExtensions.Unix.cs

示例14: IsNormalized

        public static bool IsNormalized(this string value, NormalizationForm normalizationForm)
        {
            ValidateArguments(value, normalizationForm);

            int ret = Interop.GlobalizationNative.IsNormalized(normalizationForm, value, value.Length);

            if (ret == -1)
            {
                throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, "value");
            }

            return ret == 1;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:StringNormalizationExtensions.Unix.cs

示例15: IsNormalized

        public static bool IsNormalized(this string strInput, NormalizationForm normalizationForm)
        {
            ValidateArguments(strInput, normalizationForm);

            int ret = Interop.GlobalizationInterop.IsNormalized(normalizationForm, strInput, strInput.Length);

            if (ret == -1)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"), nameof(strInput));
            }

            return ret == 1;
        }
开发者ID:nietras,项目名称:coreclr,代码行数:13,代码来源:Normalization.Unix.cs


注:本文中的NormalizationForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。