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


C# IdnMapping.GetAscii方法代码示例

本文整理汇总了C#中System.Globalization.IdnMapping.GetAscii方法的典型用法代码示例。如果您正苦于以下问题:C# IdnMapping.GetAscii方法的具体用法?C# IdnMapping.GetAscii怎么用?C# IdnMapping.GetAscii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.IdnMapping的用法示例。


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

示例1: FullyQualifiedDomainNameVsIndividualLabels

        public void FullyQualifiedDomainNameVsIndividualLabels()
        {
            var idn = new IdnMapping();

            // ASCII only code points
            Assert.Equal("\u0061\u0062\u0063", idn.GetAscii("\u0061\u0062\u0063"));
            // non-ASCII only code points
            Assert.Equal("xn--d9juau41awczczp", idn.GetAscii("\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067"));
            // ASCII and non-ASCII code points
            Assert.Equal("xn--de-jg4avhby1noc0d", idn.GetAscii("\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0"));
            // Fully Qualified Domain Name
            Assert.Equal("abc.xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0"));
        }
开发者ID:hitomi333,项目名称:corefx,代码行数:13,代码来源:GetAsciiTests.cs

示例2: EmbeddedNulls

        public void EmbeddedNulls()
        {
            var idn = new IdnMapping();

            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0, 2));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0, 3));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0, 4));
        }
开发者ID:jsalvadorp,项目名称:corefx,代码行数:14,代码来源:GetAsciiTests.cs

示例3: DomainMapper

 private static string DomainMapper(Match match)
 {
     var idn = new IdnMapping();
     var domainName = match.Groups[2].Value;
     domainName = idn.GetAscii(domainName);
     return match.Groups[1].Value + domainName;
 }
开发者ID:softrick-solution,项目名称:framework,代码行数:7,代码来源:StringExtensions.cs

示例4: IsValidEmail

        public bool IsValidEmail(string strIn)
        {
            var invalid = false;
            if (String.IsNullOrEmpty(strIn))
                return false;

            MatchEvaluator DomainMapper = match =>
            {
                // IdnMapping class with default property values.
                IdnMapping idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    invalid = true;
                }
                return match.Groups[1].Value + domainName;
            };

            // Use IdnMapping class to convert Unicode domain names.
            strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
            if (invalid)
                return false;

            // Return true if strIn is in valid e-mail format.
            return Regex.IsMatch(strIn,
                      @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                      @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$",
                      RegexOptions.IgnoreCase);
        }
开发者ID:rotmgkillroyx,项目名称:rotmg_svr_OLD,代码行数:34,代码来源:register.cs

示例5: IsValidUsername

        public bool IsValidUsername(string strIn)
        {
            bool invalid = false;
            if (String.IsNullOrEmpty(strIn))
                return false;

            MatchEvaluator DomainMapper = match =>
            {
                // IdnMapping class with default property values.
                var idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    invalid = true;
                }
                return match.Groups[1].Value + domainName;
            };

            // Use IdnMapping class to convert Unicode domain names. 
            // strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
            if (invalid)
                return false;

            // Return true if strIn is in valid e-mail format. 
            return Regex.IsMatch(strIn,
                @"^[a-z][a-zA-Z]*$",
                RegexOptions.IgnoreCase);
        }
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:33,代码来源:register.cs

示例6: IsEmail

        public bool IsEmail(string src)
        {
            if (string.IsNullOrWhiteSpace(src))
                return false;

            try
            {
                // Use IdnMapping class to convert Unicode domain names.
                var idn = new IdnMapping();
                src = Regex.Replace(
                    src, 
                    @"(@)(.+)$", 
                    match => match.Groups[1].Value + idn.GetAscii(match.Groups[2].Value), 
                    RegexOptions.None, 
                    TimeSpan.FromMilliseconds(200));

                // Validate email address using Regex.
                return Regex.IsMatch(
                    src,
                    @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                    RegexOptions.IgnoreCase, 
                    TimeSpan.FromMilliseconds(250));
            }
            catch (Exception ex)
            {
                this.loggingService.Exception(ex, "Error while validation email address:", src);
                return false;
            }
        }
开发者ID:Campr,项目名称:Server,代码行数:30,代码来源:TextHelpers.cs

示例7: GetAsciiInvalid

		void GetAsciiInvalid (IdnMapping m, string s, object label)
		{
			try {
				m.GetAscii (s);
				Assert.Fail (label != null ? label.ToString () + ":" + s : s);
			} catch (ArgumentException) {
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:IdnMappingTest.cs

示例8: VerifyStd3AsciiRules

        private void VerifyStd3AsciiRules(string unicode)
        {
            var idnStd3False = new IdnMapping { UseStd3AsciiRules = false };
            var idnStd3True = new IdnMapping { UseStd3AsciiRules = true };

            Assert.Equal(unicode, idnStd3False.GetAscii(unicode));
            Assert.Throws<ArgumentException>(() => idnStd3True.GetAscii(unicode));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:UseStd3AsciiRules.cs

示例9: DomainMapper

 private string DomainMapper(Match match)
 {
     IdnMapping idn = new IdnMapping();
     string domainName = match.Groups[2].Value;
     try { domainName = idn.GetAscii(domainName); }
     catch (ArgumentException) { _emailIsInvalid = true; }
     return match.Groups[1].Value + domainName;
 }
开发者ID:JJarczyk12,项目名称:SocialNetwork,代码行数:8,代码来源:EmailHelper.cs

示例10: DomainMapper

        public static string DomainMapper(Match match)
        {
            // IdnMapping class with default property values.
            var idn = new IdnMapping();

            var domainName = match.Groups[2].Value;
            domainName = idn.GetAscii(domainName);
            return match.Groups[1].Value + domainName;
        }
开发者ID:jfairchild,项目名称:pitchtrack,代码行数:9,代码来源:StringExtensions.cs

示例11: DomainMapper

		private string DomainMapper(Match match) {
			// IdnMapping class with default property values.
			IdnMapping idn = new IdnMapping();

			string domainName = match.Groups[2].Value;
			try {
				domainName = idn.GetAscii(domainName);
			} catch(ArgumentException) {
				this._invalid = true;      
			}      
			return match.Groups[1].Value + domainName;
		}
开发者ID:CodeFork,项目名称:eMailServer.NET,代码行数:12,代码来源:RegexUtilities.cs

示例12: DomainMapper

        private string DomainMapper(string strIn)
        {
            string ret = Regex.Replace(strIn, @"(@)(.+)$", (match) =>
            {
                IdnMapping idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                    domainName = idn.GetAscii(domainName);
                return match.Groups[1].Value + domainName;
            }, RegexOptions.None, TimeSpan.FromMilliseconds(200));

            return ret;
        }
开发者ID:Kemyke,项目名称:StepMap.net,代码行数:13,代码来源:RegexHelper.cs

示例13: IsValidEmail

        public static bool IsValidEmail(string email)
        {
            bool invalid = false;
            if (String.IsNullOrEmpty(email))
            {
                return false;
            }

            try
            {
                email = Regex.Replace(email, @"(@)(.+)$", match =>
                    {
                        //use IdnMapping class to convert Unicode domain names.
                        var idn = new IdnMapping();

                        string domainName = match.Groups[2].Value;
                        try
                        {
                            domainName = idn.GetAscii(domainName);
                        }
                        catch (ArgumentException)
                        {
                            invalid = true;
                        }

                        return match.Groups[1].Value + domainName;
                    },
                    RegexOptions.Compiled, TimeSpan.FromMilliseconds(200));
            }
            catch (RegexMatchTimeoutException)
            {
                return false;
            }

            if (invalid)
            {
                return false;
            }

            //return true if input is in valid e-mail format.
            try
            {
                return EmailRegex.IsMatch(email);
            }
            catch (RegexMatchTimeoutException)
            {
                return false;
            }
        }
开发者ID:denno-secqtinstien,项目名称:web,代码行数:49,代码来源:RegexUtilities.cs

示例14: ConvertUnicodeToPunycodeDomain

		private static string ConvertUnicodeToPunycodeDomain(Match match)
		{
			string str;
			IdnMapping idnMapping = new IdnMapping();
			string value = match.Groups[2].Value;
			try
			{
				value = idnMapping.GetAscii(value);
				return string.Concat(match.Groups[1].Value, value);
			}
			catch
			{
				str = null;
			}
			return str;
		}
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:16,代码来源:StringExtensions.cs

示例15: SimpleValidationTests

        public void SimpleValidationTests()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--yda", idn.GetAscii("\u0101"));
            Assert.Equal("xn--yda", idn.GetAscii("\u0101", 0));
            Assert.Equal("xn--yda", idn.GetAscii("\u0101", 0, 1));

            Assert.Equal("xn--aa-cla", idn.GetAscii("\u0101\u0061\u0041"));
            Assert.Equal("xn--ab-dla", idn.GetAscii("\u0061\u0101\u0062"));
            Assert.Equal("xn--ab-ela", idn.GetAscii("\u0061\u0062\u0101"));
        }
开发者ID:hitomi333,项目名称:corefx,代码行数:12,代码来源:GetAsciiTests.cs


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