• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# NormalizationForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: IsNormalized

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

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

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

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


示例17: Normalization

 internal unsafe Normalization(NormalizationForm form, string strDataFile)
 {
     this.normalizationForm = form;
     if (!nativeLoadNormalizationDLL())
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNormalizationForm"));
     }
     byte* globalizationResourceBytePtr = GlobalizationAssembly.GetGlobalizationResourceBytePtr(typeof(Normalization).Assembly, strDataFile);
     if (globalizationResourceBytePtr == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNormalizationForm"));
     }
     if (nativeNormalizationInitNormalization(form, globalizationResourceBytePtr) == null)
     {
         throw new OutOfMemoryException(Environment.GetResourceString("Arg_OutOfMemoryException"));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:Normalization.cs


示例18: ValidateArguments

        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        private static void ValidateArguments(string value, NormalizationForm normalizationForm)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (normalizationForm != NormalizationForm.FormC && normalizationForm != NormalizationForm.FormD &&
                normalizationForm != NormalizationForm.FormKC && normalizationForm != NormalizationForm.FormKD)
            {
                throw new ArgumentException(SR.Argument_InvalidNormalizationForm, "normalizationForm");
            }

            if (HasInvalidUnicodeSequence(value))
            {
                throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, "value");
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:22,代码来源:StringNormalizationExtensions.Unix.cs


示例19: ValidateArguments

        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        private static void ValidateArguments(string strInput, NormalizationForm normalizationForm)
        {
            if (strInput == null)
            {
                throw new ArgumentNullException(nameof(strInput));
            }

            if (normalizationForm != NormalizationForm.FormC && normalizationForm != NormalizationForm.FormD &&
                normalizationForm != NormalizationForm.FormKC && normalizationForm != NormalizationForm.FormKD)
            {
                throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
            }

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


示例20: TestString

		void TestString (Testcase tc, string expected, NormalizationForm f)
		{
			string input = tc.Source;
			string actual = null;
			switch (f) {
			default:
				actual = Normalization.Normalize (input, 0); break;
			case NormalizationForm.FormD:
				actual = Normalization.Normalize (input, 1); break;
			case NormalizationForm.FormKC:
				actual = Normalization.Normalize (input, 2); break;
			case NormalizationForm.FormKD:
				actual = Normalization.Normalize (input, 3); break;
			}

			if (actual != expected)
				Console.WriteLine ("Error: expected {0} but was {1} (for {2},type{3} form {4})",
				expected, actual, tc.Source, tc.TestType, f);
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:19,代码来源:StringNormalizationTestSource.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NormalizedSnapshotSpanCollection类代码示例发布时间:2022-05-24
下一篇:
C# NormalizationAction类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap