using System;
using System.Text;
namespace System.Globalization
{
/// Supports the use of non-ASCII characters for Internet domain names. This class cannot be inherited.
// Token: 0x0200018A RID: 394
public sealed class IdnMapping
{
/// Gets or sets a value indicating whether unassigned Unicode code points are used in operations performed by members of the current object.
/// true if unassigned code points are used in operations; otherwise, false.
// Token: 0x1700035E RID: 862
// (get) Token: 0x0600139F RID: 5023 RVA: 0x0004C0FC File Offset: 0x0004A2FC
// (set) Token: 0x060013A0 RID: 5024 RVA: 0x0004C104 File Offset: 0x0004A304
public bool AllowUnassigned
{
get
{
return this.allow_unassigned;
}
set
{
this.allow_unassigned = value;
}
}
/// Gets or sets a value indicating whether standard or nonstandard naming conventions are used in operations performed by members of the current object.
/// true if nonstandard naming conventions are used in operations; otherwise, false.
// Token: 0x1700035F RID: 863
// (get) Token: 0x060013A1 RID: 5025 RVA: 0x0004C110 File Offset: 0x0004A310
// (set) Token: 0x060013A2 RID: 5026 RVA: 0x0004C118 File Offset: 0x0004A318
public bool UseStd3AsciiRules
{
get
{
return this.use_std3;
}
set
{
this.use_std3 = value;
}
}
/// Indicates whether a specified object and this object are equal.
/// true if the parameter is derived from and its and properties are equal; otherwise, false.
/// An object.
// Token: 0x060013A3 RID: 5027 RVA: 0x0004C124 File Offset: 0x0004A324
public override bool Equals(object obj)
{
IdnMapping idnMapping = obj as IdnMapping;
return idnMapping != null && this.allow_unassigned == idnMapping.allow_unassigned && this.use_std3 == idnMapping.use_std3;
}
/// Returns a hash code for this object.
/// One of four 32-bit signed constants derived from the properties of a object. The return value has no special meaning and is not suitable for use in a hash code algorithm.
// Token: 0x060013A4 RID: 5028 RVA: 0x0004C160 File Offset: 0x0004A360
public override int GetHashCode()
{
return ((!this.allow_unassigned) ? 0 : 2) + ((!this.use_std3) ? 0 : 1);
}
/// Encodes a string of one or more domain name labels that consist of Unicode characters to a string of Unicode characters in the US-ASCII character range.
/// The equivalent of the string specified by the parameter, consisting of displayable Unicode characters in the US-ASCII character range (U+0020 to U+007E) and formatted according to the Internationalizing Domain Names in Applications (IDNA) standard.
/// An input string to convert, which consists of one or more domain name labels delimited with label separators.
///
/// is null.
///
/// is invalid based on the and properties, and the IDNA standard.-or-A label contains one or more of the Unicode control characters from U+0001 through U+001F, or U+007F.
// Token: 0x060013A5 RID: 5029 RVA: 0x0004C188 File Offset: 0x0004A388
public string GetAscii(string unicode)
{
if (unicode == null)
{
throw new ArgumentNullException("unicode");
}
return this.GetAscii(unicode, 0, unicode.Length);
}
/// Encodes a substring of one or more domain name labels that consist of Unicode characters to a string of Unicode characters in the US-ASCII character range.
/// The equivalent of the substring specified by the and parameters, consisting of displayable Unicode characters in the US-ASCII character range (U+0020 to U+007E) and formatted according to the Internationalizing Domain Names in Applications (IDNA) standard.
/// An input string to convert, which consists of one or more domain name labels delimited with label separators.
/// A zero-based offset into that specifies the start of the substring. The conversion operation continues to the end of .
///
/// is null.
///
/// or is less than zero.-or- is greater than the length of .
///
/// is invalid based on the and properties, and the IDNA standard.-or-A label contains one or more of the Unicode control characters from U+0001 through U+001F, or U+007F.
// Token: 0x060013A6 RID: 5030 RVA: 0x0004C1AC File Offset: 0x0004A3AC
public string GetAscii(string unicode, int index)
{
if (unicode == null)
{
throw new ArgumentNullException("unicode");
}
return this.GetAscii(unicode, index, unicode.Length - index);
}
/// Encodes a substring of one or more domain name labels that consist of Unicode characters to a string of Unicode characters in the US-ASCII character range. The string is formatted according to the Internationalizing Domain Names in Applications (IDNA) standard.
/// The equivalent of the substring specified by the , , and parameters, consisting of displayable Unicode characters in the US-ASCII character range (U+0020 to U+007E) and formatted according to the IDNA standard.
/// An input string to convert, which consists of one or more domain name labels delimited with label separators.
/// A zero-based offset into that specifies the start of the substring.
/// The number of characters to convert in the substring that starts at the position specified by and .
///
/// is null.
///
/// or is less than zero.-or- is greater than the length of .-or- is greater than the length of minus .
///
/// is invalid based on the and properties, and the IDNA standard.-or-A label contains one or more of the Unicode control characters from U+0001 through U+001F, or U+007F.
// Token: 0x060013A7 RID: 5031 RVA: 0x0004C1D0 File Offset: 0x0004A3D0
public string GetAscii(string unicode, int index, int count)
{
if (unicode == null)
{
throw new ArgumentNullException("unicode");
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index must be non-negative value");
}
if (count < 0 || index + count > unicode.Length)
{
throw new ArgumentOutOfRangeException("index + count must point inside the argument unicode string");
}
return this.Convert(unicode, index, count, true);
}
// Token: 0x060013A8 RID: 5032 RVA: 0x0004C22C File Offset: 0x0004A42C
private string Convert(string input, int index, int count, bool toAscii)
{
string text = input.Substring(index, count);
for (int i = 0; i < text.Length; i++)
{
if (text[i] >= '\u0080')
{
text = text.ToLower(CultureInfo.InvariantCulture);
break;
}
}
string[] array = text.Split(new char[] { '.', '。', '.', '。' });
int num = 0;
for (int j = 0; j < array.Length; j++)
{
if (array[j].Length != 0 || j + 1 != array.Length)
{
if (toAscii)
{
array[j] = this.ToAscii(array[j], num);
}
else
{
array[j] = this.ToUnicode(array[j], num);
}
}
num += array[j].Length;
}
return string.Join(".", array);
}
// Token: 0x060013A9 RID: 5033 RVA: 0x0004C310 File Offset: 0x0004A510
private string ToAscii(string s, int offset)
{
for (int i = 0; i < s.Length; i++)
{
if (s[i] < ' ' || s[i] == '\u007f')
{
throw new ArgumentException(string.Format("Not allowed character was found, at {0}", offset + i));
}
if (s[i] >= '\u0080')
{
s = this.NamePrep(s, offset);
break;
}
}
if (this.use_std3)
{
this.VerifyStd3AsciiRules(s, offset);
}
int j = 0;
while (j < s.Length)
{
if (s[j] >= '\u0080')
{
if (s.StartsWith("xn--", StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException(string.Format("The input string must not start with ACE (xn--), at {0}", offset + j));
}
s = this.puny.Encode(s, offset);
s = "xn--" + s;
break;
}
else
{
j++;
}
}
this.VerifyLength(s, offset);
return s;
}
// Token: 0x060013AA RID: 5034 RVA: 0x0004C418 File Offset: 0x0004A618
private void VerifyLength(string s, int offset)
{
if (s.Length == 0)
{
throw new ArgumentException(string.Format("A label in the input string resulted in an invalid zero-length string, at {0}", offset));
}
if (s.Length > 63)
{
throw new ArgumentException(string.Format("A label in the input string exceeded the length in ASCII representation, at {0}", offset));
}
}
// Token: 0x060013AB RID: 5035 RVA: 0x0004C46C File Offset: 0x0004A66C
private string NamePrep(string s, int offset)
{
s = s.Normalize(NormalizationForm.FormKC);
this.VerifyProhibitedCharacters(s, offset);
if (!this.allow_unassigned)
{
for (int i = 0; i < s.Length; i++)
{
if (char.GetUnicodeCategory(s, i) == UnicodeCategory.OtherNotAssigned)
{
throw new ArgumentException(string.Format("Use of unassigned Unicode characer is prohibited in this IdnMapping, at {0}", offset + i));
}
}
}
return s;
}
// Token: 0x060013AC RID: 5036 RVA: 0x0004C4D4 File Offset: 0x0004A6D4
private void VerifyProhibitedCharacters(string s, int offset)
{
int i = 0;
while (i < s.Length)
{
switch (char.GetUnicodeCategory(s, i))
{
case UnicodeCategory.SpaceSeparator:
if (s[i] >= '\u0080')
{
goto IL_164;
}
break;
case UnicodeCategory.LineSeparator:
case UnicodeCategory.ParagraphSeparator:
case UnicodeCategory.Format:
goto IL_80;
case UnicodeCategory.Control:
if (s[i] == '\0' || s[i] >= '\u0080')
{
goto IL_164;
}
break;
case UnicodeCategory.Surrogate:
case UnicodeCategory.PrivateUse:
goto IL_164;
default:
goto IL_80;
}
IL_17C:
i++;
continue;
IL_80:
char c = s[i];
if (('\ufddf' > c || c > '\ufdef') && ((c & '\uffff') != '\ufffe' && ('\ufff9' > c || c > '\ufffd')) && ('⿰' > c || c > '⿻') && ('\u202a' > c || c > '\u202e') && ('\u206a' > c || c > '\u206f'))
{
char c2 = c;
if (c2 != '\u0340' && c2 != '\u0341' && c2 != '\u200e' && c2 != '\u200f' && c2 != '\u2028' && c2 != '\u2029')
{
goto IL_17C;
}
}
IL_164:
throw new ArgumentException(string.Format("Not allowed character was in the input string, at {0}", offset + i));
}
}
// Token: 0x060013AD RID: 5037 RVA: 0x0004C670 File Offset: 0x0004A870
private void VerifyStd3AsciiRules(string s, int offset)
{
if (s.Length > 0 && s[0] == '-')
{
throw new ArgumentException(string.Format("'-' is not allowed at head of a sequence in STD3 mode, found at {0}", offset));
}
if (s.Length > 0 && s[s.Length - 1] == '-')
{
throw new ArgumentException(string.Format("'-' is not allowed at tail of a sequence in STD3 mode, found at {0}", offset + s.Length - 1));
}
for (int i = 0; i < s.Length; i++)
{
char c = s[i];
if (c != '-')
{
if (c <= '/' || (':' <= c && c <= '@') || ('[' <= c && c <= '`') || ('{' <= c && c <= '\u007f'))
{
throw new ArgumentException(string.Format("Not allowed character in STD3 mode, found at {0}", offset + i));
}
}
}
}
/// Decodes a string of one or more domain name labels encoded according to the Internationalizing Domain Names in Applications (IDNA) standard to a string of Unicode characters.
/// The Unicode equivalent of the IDNA substring specified by the parameter.
/// One or more labels in the US-ASCII character range (U+0020 to U+007E) encoded according to the IDNA standard.
///
/// is null.
///
/// is invalid based on the and properties, and the IDNA standard.
// Token: 0x060013AE RID: 5038 RVA: 0x0004C76C File Offset: 0x0004A96C
public string GetUnicode(string ascii)
{
if (ascii == null)
{
throw new ArgumentNullException("ascii");
}
return this.GetUnicode(ascii, 0, ascii.Length);
}
/// Decodes a substring of one or more domain name labels encoded according to the Internationalizing Domain Names in Applications (IDNA) standard to a string of Unicode characters.
/// The Unicode equivalent of the IDNA substring specified by the and parameters.
/// One or more labels in the US-ASCII character range (U+0020 to U+007E) encoded according to the IDNA standard.
/// A zero-based offset into that specifies the start of the substring.
///
/// is null.
///
/// is less than zero.-or- is greater than the length of .
///
/// is invalid based on the and properties, and the IDNA standard.
// Token: 0x060013AF RID: 5039 RVA: 0x0004C790 File Offset: 0x0004A990
public string GetUnicode(string ascii, int index)
{
if (ascii == null)
{
throw new ArgumentNullException("ascii");
}
return this.GetUnicode(ascii, index, ascii.Length - index);
}
/// Decodes a substring of one or more domain name labels encoded according to the Internationalizing Domain Names in Applications (IDNA) standard to a string of Unicode characters.
/// The Unicode equivalent of the IDNA substring specified by the , , and parameters.
/// One or more labels in the US-ASCII character range (U+0020 to U+007E) encoded according to the IDNA standard.
/// A zero-based offset into that specifies the start of the substring.
/// The number of characters to convert in the substring that starts at the position specified by and .
///
/// is null.
///
/// or is less than zero.-or- is greater than the length of .-or- is greater than the length of minus .
///
/// is invalid based on the and properties, and the IDNA standard.
// Token: 0x060013B0 RID: 5040 RVA: 0x0004C7B4 File Offset: 0x0004A9B4
public string GetUnicode(string ascii, int index, int count)
{
if (ascii == null)
{
throw new ArgumentNullException("ascii");
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index must be non-negative value");
}
if (count < 0 || index + count > ascii.Length)
{
throw new ArgumentOutOfRangeException("index + count must point inside the argument ascii string");
}
return this.Convert(ascii, index, count, false);
}
// Token: 0x060013B1 RID: 5041 RVA: 0x0004C810 File Offset: 0x0004AA10
private string ToUnicode(string s, int offset)
{
for (int i = 0; i < s.Length; i++)
{
if (s[i] >= '\u0080')
{
s = this.NamePrep(s, offset);
break;
}
}
if (!s.StartsWith("xn--", StringComparison.OrdinalIgnoreCase))
{
return s;
}
s = s.ToLower(CultureInfo.InvariantCulture);
string text = s;
s = s.Substring(4);
s = this.puny.Decode(s, offset);
string text2 = s;
s = this.ToAscii(s, offset);
if (string.Compare(text, s, StringComparison.OrdinalIgnoreCase) != 0)
{
throw new ArgumentException(string.Format("ToUnicode() failed at verifying the result, at label part from {0}", offset));
}
return text2;
}
// Token: 0x04000571 RID: 1393
private bool allow_unassigned;
// Token: 0x04000572 RID: 1394
private bool use_std3;
// Token: 0x04000573 RID: 1395
private Punycode puny = new Punycode();
}
}