We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
-
Expand
Microsoft.Win32
-
Expand
Microsoft.Win32.SafeHandles
-
Expand
System
-
Expand
System.Runtime.Hosting
-
Expand
System.Runtime.InteropServices
-
Expand
System.Runtime.CompilerServices
-
Expand
System.Collections
-
Expand
System.Collections.Generic
-
Expand
System.Collections.ObjectModel
-
Expand
System.Configuration.Assemblies
-
Expand
System.Diagnostics
-
Expand
System.Diagnostics.CodeAnalysis
-
Expand
System.Diagnostics.SymbolStore
-
Expand
System.Globalization
-
Expand
__DateBuffer
-
Expand
BaseInfoTable
-
Expand
BidiCategory
-
Expand
Calendar
-
Expand
CalendarAlgorithmType
-
Expand
CalendarId
-
Expand
CalendarTable
-
Expand
CalendarTableData
-
Expand
CalendarWeekRule
-
Expand
CharUnicodeInfo
-
Expand
ChineseLunisolarCalendar
-
Expand
CodePageDataItem
-
Expand
CompareInfo
-
Expand
CompareOptions
-
Expand
CultureData
-
Expand
CultureFlags
-
Expand
CultureInfo
-
Expand
CultureNameOffsetItem
-
Expand
CultureTable
-
Expand
CultureTableData
-
Expand
CultureTableHeader
-
Expand
CultureTableItem
-
Expand
CultureTableRecord
-
Expand
CultureTypes
-
Expand
DateMapping
-
Expand
DateTimeFormatFlags
-
Expand
DateTimeFormatInfo
-
Expand
DateTimeFormatInfoScanner
-
Expand
DateTimeStyles
-
Expand
DaylightTime
-
Expand
DigitShapes
-
Expand
DigitValues
-
Expand
DTFIUserOverrideValues
-
Expand
EastAsianLunisolarCalendar
-
Expand
EncodingTable
-
Expand
EndianessHeader
-
Expand
EraInfo
-
Expand
ExceptionTableItem
-
Expand
FORMATFLAGS
-
Expand
FoundDatePattern
-
Expand
GlobalizationAssembly
-
Expand
GregorianCalendar
-
Expand
GregorianCalendarHelper
-
Expand
GregorianCalendarTypes
-
Expand
HebrewCalendar
-
Expand
HebrewNumber
-
Expand
HebrewNumberParsingContext
-
Expand
HebrewNumberParsingState
-
Expand
HebrewToken
-
Expand
HebrewValue
-
Expand
HijriCalendar
-
Expand
HS
-
Expand
IdnMapping
-
adapt(int, int, bool)
-
AllowUnassigned()
-
basic(uint)
-
decode_digit(char)
-
encode_basic(char)
-
encode_digit(int)
-
Equals(object)
-
GetAscii(string)
-
GetAscii(string, int)
-
GetAscii(string, int, int)
-
GetHashCode()
-
GetUnicode(string)
-
GetUnicode(string, int)
-
GetUnicode(string, int, int)
-
HasUpperCaseFlag(char)
-
IdnMapping()
-
IsDot(char)
-
IsSupplementary(int)
-
punycode_decode(string)
-
punycode_encode(string)
-
UseStd3AsciiRules()
-
ValidateStd3(char, bool)
-
ValidateStd3AndAscii(string, bool, bool)
-
Expand
IDOffsetItem
-
Expand
IetfNameOffsetItem
-
Expand
InternalCodePageDataItem
-
Expand
InternalEncodingDataItem
-
Expand
JapaneseCalendar
-
Expand
JapaneseLunisolarCalendar
-
Expand
JulianCalendar
-
Expand
KoreanCalendar
-
Expand
KoreanLunisolarCalendar
-
Expand
MemoryMapFile
-
Expand
MonthNameStyles
-
Expand
NumberFormatInfo
-
Expand
NumberStyles
-
Expand
PersianCalendar
-
Expand
RegionInfo
-
Expand
RegionNameOffsetItem
-
Expand
SortKey
-
Expand
StringInfo
-
Expand
TaiwanCalendar
-
Expand
TaiwanLunisolarCalendar
-
Expand
TextElementEnumerator
-
Expand
TextInfo
-
Expand
TextInfoDataHeader
-
Expand
ThaiBuddhistCalendar
-
Expand
TokenHashValue
-
Expand
UmAlQuraCalendar
-
Expand
UnicodeCategory
-
Expand
UnicodeDataHeader
-
Expand
System.IO
-
Expand
System.IO.IsolatedStorage
-
Expand
System.Reflection
-
Expand
System.Reflection.Cache
-
Expand
System.Reflection.Emit
-
Expand
System.Resources
-
Expand
System.Runtime
-
Expand
System.Runtime.InteropServices.Expando
-
Expand
System.Runtime.ConstrainedExecution
-
Expand
System.Runtime.Remoting.Activation
-
Expand
System.Runtime.Remoting.Messaging
-
Expand
System.Runtime.Remoting.Channels
-
Expand
System.Runtime.Remoting.Lifetime
-
Expand
System.Runtime.Remoting
-
Expand
System.Runtime.Remoting.Contexts
-
Expand
System.Runtime.Remoting.Proxies
-
Expand
System.Runtime.Remoting.Metadata
-
Expand
System.Runtime.Remoting.Metadata.W3cXsd2001
-
Expand
System.Runtime.Remoting.Services
-
Expand
System.Runtime.Serialization
-
Expand
System.Runtime.Serialization.Formatters
-
Expand
System.Runtime.Serialization.Formatters.Binary
-
Expand
System.Runtime.Versioning
-
Expand
System.Security
-
Expand
System.Security.Cryptography
-
Expand
System.Security.Cryptography.X509Certificates
-
Expand
System.Security.Permissions
-
Expand
System.Security.Policy
-
Expand
System.Security.Principal
-
Expand
System.Security.Util
-
Expand
System.Text
-
Expand
System.Threading
-
Expand
System.Runtime.Remoting.Channels.Http
-
Expand
System.Runtime.Remoting.Channels.Tcp
-
Expand
System.Runtime.Remoting.MetadataServices
-
Expand
System.Runtime.Serialization.Formatters.Soap.Xml
-
Expand
System.Runtime.Serialization.Formatters.Soap
-
Expand
Microsoft.Tools.Caspol
-
Expand
Microsoft.Tools.Build
-
Expand
Microsoft.CSharp
-
Expand
System.CodeDom
-
Expand
System.CodeDom.Compiler
-
Expand
System.Collections.Specialized
-
Expand
System.ComponentModel
-
Expand
System.ComponentModel.Design
-
Expand
System.ComponentModel.Design.Serialization
-
Expand
System.Configuration
-
Expand
System.Web
-
Expand
System.Configuration.Provider
-
Expand
System.Configuration.Internal
-
Expand
System.Internal
-
Expand
System.Windows.Forms
-
Expand
System.Net
-
Expand
System.Net.Sockets
-
Expand
System.Net.NetworkInformation
-
Expand
System.Net.ComImports
-
Expand
System.Net.Security
-
Expand
System.Net.Cache
-
Expand
System.Net.Configuration
-
Expand
System.Text.RegularExpressions
-
Expand
System.Tools
-
Expand
System.IO.Compression
-
Expand
System.IO.Ports
-
Expand
System.Security.AccessControl
-
Expand
System.Xml
-
Expand
System.Xml.XPath.DataBinding
-
Expand
System.Xml.Schema
-
Expand
System.Xml.Serialization
-
Expand
System.Xml.Serialization.Advanced
-
Expand
System.Xml.Serialization.Configuration
-
Expand
System.Xml.XPath
-
Expand
System.Xml.Xsl
-
Expand
System.Xml.Xsl.IlGen
-
Expand
System.Xml.Xsl.Qil
-
Expand
System.Xml.Xsl.Runtime
-
Expand
System.Xml.Xsl.XPath
-
Expand
System.Xml.Xsl.Xslt
-
Expand
System.Xml.Xsl.XsltOld
-
Expand
System.Xml.Xsl.XsltOld.Debugger
-
Expand
Microsoft.JScript
-
Expand
Microsoft.Vsa
-
Expand
Microsoft.JScript.Vsa
- namespace System.Globalization
- {
- using System;
- using System.Globalization;
- using System.Text;
-
-
-
- public sealed class IdnMapping
- {
-
- const int M_labelLimit = 63;
-
- const int M_defaultNameLimit = 255;
-
-
- const string M_strAcePrefix = "xn--";
-
-
- static char[] M_Dots = {'.', '。', '.', '。'};
-
- bool m_bAllowUnassigned;
- bool m_bUseStd3AsciiRules;
-
- public IdnMapping()
- {
- this.m_bAllowUnassigned = false;
- this.m_bUseStd3AsciiRules = false;
- }
-
- public bool AllowUnassigned {
- get { return this.m_bAllowUnassigned; }
-
- set { this.m_bAllowUnassigned = value; }
- }
-
- public bool UseStd3AsciiRules {
- get { return this.m_bUseStd3AsciiRules; }
-
- set { this.m_bUseStd3AsciiRules = value; }
- }
-
-
- public string GetAscii(string unicode)
- {
- return GetAscii(unicode, 0);
- }
-
- public string GetAscii(string unicode, int index)
- {
- if (unicode == null)
- throw new ArgumentNullException("unicode");
- return GetAscii(unicode, index, unicode.Length - index);
- }
-
- public string GetAscii(string unicode, int index, int count)
- {
- if (unicode == null)
- throw new ArgumentNullException("unicode");
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
- if (index > unicode.Length)
- throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- if (index > unicode.Length - count)
- throw new ArgumentOutOfRangeException("unicode", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
-
- unicode = unicode.Substring(index, count);
-
-
- if (ValidateStd3AndAscii(unicode, UseStd3AsciiRules, true)) {
- return unicode;
- }
-
-
-
- BCLDebug.Assert(unicode.Length >= 1, "[IdnMapping.GetAscii]Expected 0 length strings to fail before now.");
- if (unicode[unicode.Length - 1] <= 31) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequence", unicode.Length - 1), "unicode");
- }
-
-
- bool bHasLastDot = (unicode.Length > 0) && IsDot(unicode[unicode.Length - 1]);
- unicode = unicode.Normalize((NormalizationForm)(m_bAllowUnassigned ? ExtendedNormalizationForms.FormIdna : ExtendedNormalizationForms.FormIdnaDisallowUnassigned));
-
-
- if ((!bHasLastDot) && unicode.Length > 0 && IsDot(unicode[unicode.Length - 1])) {
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
- }
-
-
- if (UseStd3AsciiRules) {
- ValidateStd3AndAscii(unicode, true, false);
- }
-
-
- return punycode_encode(unicode);
- }
-
-
-
- public string GetUnicode(string ascii)
- {
- return GetUnicode(ascii, 0);
- }
-
- public string GetUnicode(string ascii, int index)
- {
- if (ascii == null)
- throw new ArgumentNullException("unicode");
- return GetUnicode(ascii, index, ascii.Length - index);
- }
-
- public string GetUnicode(string ascii, int index, int count)
- {
- if (ascii == null)
- throw new ArgumentNullException("ascii");
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
- if (index > ascii.Length)
- throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- if (index > ascii.Length - count)
- throw new ArgumentOutOfRangeException("ascii", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
-
- ascii = ascii.Substring(index, count);
-
-
- string strUnicode = punycode_decode(ascii);
-
-
- if (!ascii.Equals(GetAscii(strUnicode), StringComparison.OrdinalIgnoreCase))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), "ascii");
-
- return strUnicode;
- }
-
- public override bool Equals(object obj)
- {
- IdnMapping that = obj as IdnMapping;
-
- if (that != null) {
- return this.m_bAllowUnassigned == that.m_bAllowUnassigned && this.m_bUseStd3AsciiRules == that.m_bUseStd3AsciiRules;
- }
-
- return (false);
- }
-
- public override int GetHashCode()
- {
- return (this.m_bAllowUnassigned ? 100 : 200) + (this.m_bUseStd3AsciiRules ? 1000 : 2000);
- }
-
-
- bool IsSupplementary(int cTest)
- {
- return cTest >= 65536;
- }
-
-
-
-
-
- bool IsDot(char c)
- {
- return c == '.' || c == '。' || c == '.' || c == '。';
- }
-
-
-
- bool ValidateStd3AndAscii(string unicode, bool bUseStd3, bool bCheckAscii)
- {
- int iLastDot = -1;
-
-
- if (unicode.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
-
-
- for (int i = 0; i < unicode.Length; i++) {
-
- if (unicode[i] <= 31) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequence", i), "unicode");
- }
-
-
- if (bCheckAscii && unicode[i] >= 127)
- return false;
-
-
- if (IsDot(unicode[i])) {
-
- if (i == iLastDot + 1)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
-
-
- if (i - iLastDot > M_labelLimit + 1)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "Unicode");
-
-
- if (bUseStd3 && i > 0)
- ValidateStd3(unicode[i - 1], true);
-
-
- iLastDot = i;
- continue;
- }
-
-
- if (bUseStd3) {
- ValidateStd3(unicode[i], (i == iLastDot + 1));
- }
- }
-
-
- if (iLastDot == -1 && unicode.Length > M_labelLimit)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
-
-
- if (unicode.Length > M_defaultNameLimit - (IsDot(unicode[unicode.Length - 1]) ? 0 : 1))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", M_defaultNameLimit - (IsDot(unicode[unicode.Length - 1]) ? 0 : 1)), "unicode");
-
-
- if (bUseStd3 && !IsDot(unicode[unicode.Length - 1]))
- ValidateStd3(unicode[unicode.Length - 1], true);
-
- return true;
- }
-
-
- void ValidateStd3(char c, bool bNextToDot)
- {
-
- if ((c <= ',' || c == '/' || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= (char)127)) || (c == '-' && bNextToDot))
-
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadStd3", c), "Unicode");
- }
-
-
-
-
-
-
-
-
- static bool HasUpperCaseFlag(char punychar)
- {
- return (punychar >= 'A' && punychar <= 'Z');
- }
-
-
-
-
-
-
- const int punycodeBase = 36;
- const int tmin = 1;
- const int tmax = 26;
- const int skew = 38;
- const int damp = 700;
- const int initial_bias = 72;
- const int initial_n = 128;
- const char delimiter = '-';
-
-
- static bool basic(uint cp)
- {
-
- return cp < 128;
- }
-
-
-
-
-
- static int decode_digit(char cp)
- {
- if (cp >= '0' && cp <= '9')
- return cp - '0' + 26;
-
-
- if (cp >= 'a' && cp <= 'z')
- return cp - 'a';
-
- if (cp >= 'A' && cp <= 'Z')
- return cp - 'A';
-
-
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
- }
-
-
-
-
-
-
- static char encode_digit(int d)
- {
- BCLDebug.Assert(d >= 0 && d < punycodeBase, "[IdnMapping.encode_digit]Expected 0 <= d < punycodeBase");
-
- if (d > 25)
- return (char)(d - 26 + '0');
-
-
- return (char)(d + 'a');
- }
-
-
-
-
-
-
-
-
-
- static char encode_basic(char bcp)
- {
- if (HasUpperCaseFlag(bcp))
- bcp += (char)('a' - 'A');
-
- return bcp;
- }
-
-
-
-
- const int maxint = 134217727;
-
-
-
- static int adapt(int delta, int numpoints, bool firsttime)
- {
- uint k;
-
- delta = firsttime ? delta / damp : delta / 2;
- BCLDebug.Assert(numpoints != 0, "[IdnMapping.adapt]Expected non-zero numpoints.");
- delta += delta / numpoints;
-
- for (k = 0; delta > ((punycodeBase - tmin) * tmax) / 2; k += punycodeBase) {
- delta /= punycodeBase - tmin;
- }
-
- BCLDebug.Assert(delta + skew != 0, "[IdnMapping.adapt]Expected non-zero delta+skew.");
- return (int)(k + (punycodeBase - tmin + 1) * delta / (delta + skew));
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string punycode_encode(string unicode)
- {
- StringBuilder output = new StringBuilder(unicode.Length);
- int iNextDot = 0;
- int iAfterLastDot = 0;
- int iOutputAfterLastDot = 0;
-
-
- if (unicode.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
-
-
- while (iNextDot < unicode.Length) {
-
- iNextDot = unicode.IndexOfAny(M_Dots, iAfterLastDot);
- BCLDebug.Assert(iNextDot <= unicode.Length, "[IdnMapping.punycode_encode]IndexOfAny is broken");
- if (iNextDot < 0)
- iNextDot = unicode.Length;
-
-
- if (iNextDot == iAfterLastDot) {
-
- if (iNextDot != unicode.Length)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
-
- break;
- }
-
-
- output.Append(M_strAcePrefix);
-
-
- bool bRightToLeft = false;
-
-
- BidiCategory eBidi = CharUnicodeInfo.GetBidiCategory(unicode, iAfterLastDot);
- if (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic) {
-
- bRightToLeft = true;
-
-
- int iTest = iNextDot - 1;
- if (Char.IsLowSurrogate(unicode, iTest)) {
- iTest--;
- }
-
- eBidi = CharUnicodeInfo.GetBidiCategory(unicode, iTest);
- if (eBidi != BidiCategory.RightToLeft && eBidi != BidiCategory.RightToLeftArabic) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode");
- }
- }
-
-
- int basicCount;
- int numProcessed = 0;
-
- for (basicCount = iAfterLastDot; basicCount < iNextDot; basicCount++) {
-
- BCLDebug.Assert(Char.IsLowSurrogate(unicode, basicCount) == false, "[IdnMapping.punycode_encode]Unexpected low surrogate");
-
-
- BidiCategory testBidi = CharUnicodeInfo.GetBidiCategory(unicode, basicCount);
-
-
- if (bRightToLeft && testBidi == BidiCategory.LeftToRight) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode");
- }
-
-
- if (!bRightToLeft && (testBidi == BidiCategory.RightToLeft || testBidi == BidiCategory.RightToLeftArabic)) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode");
- }
-
-
- if (basic(unicode[basicCount])) {
- output.Append(encode_basic(unicode[basicCount]));
- numProcessed++;
- }
- else if (Char.IsSurrogatePair(unicode, basicCount))
-
- basicCount++;
- }
-
- int numBasicCodePoints = numProcessed;
-
-
- if (numBasicCodePoints == iNextDot - iAfterLastDot) {
-
- output.Remove(iOutputAfterLastDot, M_strAcePrefix.Length);
- }
- else {
-
- if (unicode.Length - iAfterLastDot >= M_strAcePrefix.Length && unicode.Substring(iAfterLastDot, M_strAcePrefix.Length).Equals(M_strAcePrefix, StringComparison.OrdinalIgnoreCase))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "unicode");
-
-
- int numSurrogatePairs = 0;
-
-
- if (numBasicCodePoints > 0) {
- output.Append(delimiter);
- }
-
-
- int n = initial_n;
- int delta = 0;
- int bias = initial_bias;
-
-
- while (numProcessed < (iNextDot - iAfterLastDot)) {
-
-
- int j;
- int m;
- int test = 0;
- for (m = maxint,j = iAfterLastDot; j < iNextDot; j += IsSupplementary(test) ? 2 : 1) {
- test = Char.ConvertToUtf32(unicode, j);
- if (test >= n && test < m)
- m = test;
- }
-
-
-
- delta += (int)((m - n) * ((numProcessed - numSurrogatePairs) + 1));
- BCLDebug.Assert(delta > 0, "[IdnMapping.cs]1 punicode_encode - delta overflowed int");
- n = m;
-
- for (j = iAfterLastDot; j < iNextDot; j += IsSupplementary(test) ? 2 : 1) {
-
- test = Char.ConvertToUtf32(unicode, j);
-
-
-
-
- if (test < n) {
- delta++;
- BCLDebug.Assert(delta > 0, "[IdnMapping.cs]2 punicode_encode - delta overflowed int");
- }
-
- if (test == n) {
-
- int q;
- int k;
- for (q = delta,k = punycodeBase;; k += punycodeBase) {
- int t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias;
- if (q < t)
- break;
- BCLDebug.Assert(punycodeBase != t, "[IdnMapping.punycode_encode]Expected punycodeBase (36) to be != t");
- output.Append(encode_digit(t + (q - t) % (punycodeBase - t)));
- q = (q - t) / (punycodeBase - t);
- }
-
- output.Append(encode_digit(q));
- bias = adapt(delta, (numProcessed - numSurrogatePairs) + 1, numProcessed == numBasicCodePoints);
- delta = 0;
- numProcessed++;
-
- if (IsSupplementary(m)) {
- numProcessed++;
- numSurrogatePairs++;
- }
- }
- }
- ++delta;
- ++n;
- BCLDebug.Assert(delta > 0, "[IdnMapping.cs]3 punicode_encode - delta overflowed int");
- }
- }
-
-
- if (output.Length - iOutputAfterLastDot > M_labelLimit)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode");
-
-
- if (iNextDot != unicode.Length)
- output.Append('.');
-
- iAfterLastDot = iNextDot + 1;
- iOutputAfterLastDot = output.Length;
- }
-
-
- if (output.Length > M_defaultNameLimit - (IsDot(unicode[unicode.Length - 1]) ? 0 : 1))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", M_defaultNameLimit - (IsDot(unicode[unicode.Length - 1]) ? 0 : 1)), "unicode");
-
-
- return output.ToString();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string punycode_decode(string ascii)
- {
-
- if (ascii.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
-
-
- if (ascii.Length > M_defaultNameLimit - (IsDot(ascii[ascii.Length - 1]) ? 0 : 1))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", M_defaultNameLimit - (IsDot(ascii[ascii.Length - 1]) ? 0 : 1)), "ascii");
-
-
- StringBuilder output = new StringBuilder(ascii.Length);
-
-
- int iNextDot = 0;
- int iAfterLastDot = 0;
- int iOutputAfterLastDot = 0;
-
- while (iNextDot < ascii.Length) {
-
- iNextDot = ascii.IndexOf('.', iAfterLastDot);
- if (iNextDot < 0 || iNextDot > ascii.Length)
- iNextDot = ascii.Length;
-
-
- if (iNextDot == iAfterLastDot) {
-
- if (iNextDot != ascii.Length)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
-
-
- break;
- }
-
-
- if (iNextDot - iAfterLastDot > M_labelLimit)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
-
-
- if (ascii.Length < M_strAcePrefix.Length + iAfterLastDot || !ascii.Substring(iAfterLastDot, M_strAcePrefix.Length).Equals(M_strAcePrefix, StringComparison.OrdinalIgnoreCase)) {
-
-
-
-
-
-
-
-
-
-
-
- output.Append(ascii.Substring(iAfterLastDot, iNextDot - iAfterLastDot));
-
-
- }
- else {
-
- iAfterLastDot += M_strAcePrefix.Length;
-
-
-
- int iTemp = ascii.LastIndexOf(delimiter, iNextDot - 1);
-
-
- if (iTemp == iNextDot - 1)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
-
- int numBasicCodePoints;
- if (iTemp <= iAfterLastDot)
- numBasicCodePoints = 0;
- else {
- numBasicCodePoints = iTemp - iAfterLastDot;
-
-
-
- for (int copyAscii = iAfterLastDot; copyAscii < iAfterLastDot + numBasicCodePoints; copyAscii++) {
-
- if (ascii[copyAscii] > 127)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
-
-
- output.Append((char)(ascii[copyAscii] >= 'A' && ascii[copyAscii] <= 'Z' ? ascii[copyAscii] - 'A' + 'a' : ascii[copyAscii]));
- }
- }
-
-
-
-
- int asciiIndex = iAfterLastDot + (numBasicCodePoints > 0 ? numBasicCodePoints + 1 : 0);
-
-
- int n = initial_n;
- int bias = initial_bias;
- int i = 0;
-
- int w;
- int k;
-
-
- int numSurrogatePairs = 0;
-
-
- while (asciiIndex < iNextDot) {
-
-
-
-
- int oldi = i;
-
- for (w = 1,k = punycodeBase;; k += punycodeBase) {
-
- if (asciiIndex >= iNextDot)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
-
-
- int digit = decode_digit(ascii[asciiIndex++]);
-
- BCLDebug.Assert(w > 0, "[IdnMapping.punycode_decode]Expected w > 0");
- if (digit > (maxint - i) / w)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
-
- i += (int)(digit * w);
- int t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias;
- if (digit < t)
- break;
- BCLDebug.Assert(punycodeBase != t, "[IdnMapping.punycode_decode]Expected t != punycodeBase (36)");
- if (w > maxint / (punycodeBase - t))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
- w *= (punycodeBase - t);
- }
-
- bias = adapt(i - oldi, (output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1, oldi == 0);
-
-
-
- BCLDebug.Assert((output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1 > 0, "[IdnMapping.punycode_decode]Expected to have added > 0 characters this segment");
- if (i / ((output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1) > maxint - n)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
- n += (int)(i / (output.Length - iOutputAfterLastDot - numSurrogatePairs + 1));
- i %= (output.Length - iOutputAfterLastDot - numSurrogatePairs + 1);
-
-
-
-
-
-
-
-
-
-
-
- if ((n < 0 || n > 1114111) || (n >= 55296 && n <= 57343))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
-
-
- int iUseInsertLocation;
- string strTemp = Char.ConvertFromUtf32(n);
-
-
- if (numSurrogatePairs > 0) {
-
- int iCount;
- for (iCount = i,iUseInsertLocation = iOutputAfterLastDot; iCount > 0; iCount--,iUseInsertLocation++) {
-
- if (iUseInsertLocation >= output.Length)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
- if (Char.IsSurrogate(output[iUseInsertLocation]))
- iUseInsertLocation++;
- }
- }
- else {
-
- iUseInsertLocation = iOutputAfterLastDot + i;
- }
-
-
- output.Insert(iUseInsertLocation, strTemp);
-
-
- if (IsSupplementary(n))
- numSurrogatePairs++;
-
-
- i++;
- }
-
-
- bool bRightToLeft = false;
-
-
- BidiCategory eBidi = CharUnicodeInfo.GetBidiCategory(output.ToString(), iOutputAfterLastDot);
- if (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic) {
-
- bRightToLeft = true;
- }
-
-
- for (int iTest = iOutputAfterLastDot; iTest < output.Length; iTest++) {
-
- if (Char.IsLowSurrogate(output.ToString(), iTest))
- continue;
-
-
- eBidi = CharUnicodeInfo.GetBidiCategory(output.ToString(), iTest);
- if ((bRightToLeft && eBidi == BidiCategory.LeftToRight) || (!bRightToLeft && (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic)))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii");
-
-
-
-
- }
-
-
- if (bRightToLeft && eBidi != BidiCategory.RightToLeft && eBidi != BidiCategory.RightToLeftArabic) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii");
- }
- }
-
-
- if (iNextDot - iAfterLastDot > M_labelLimit)
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
-
-
- if (iNextDot != ascii.Length)
- output.Append('.');
-
- iAfterLastDot = iNextDot + 1;
- iOutputAfterLastDot = output.Length;
- }
-
-
- if (output.Length > M_defaultNameLimit - (IsDot(output[output.Length - 1]) ? 0 : 1))
- throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", M_defaultNameLimit - (IsDot(output[output.Length - 1]) ? 0 : 1)), "ascii");
-
-
- return output.ToString();
- }
-
-
-
- }
- }