本文整理汇总了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"));
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例7: GetAsciiInvalid
void GetAsciiInvalid (IdnMapping m, string s, object label)
{
try {
m.GetAscii (s);
Assert.Fail (label != null ? label.ToString () + ":" + s : s);
} catch (ArgumentException) {
}
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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"));
}