IdnMapping クラス
アセンブリ: mscorlib (mscorlib.dll 内)
構文
解説
インターネット ドメイン名は、ラベル区切り記号で区切られた、ドメイン名ラベルと呼ばれる 1 つまたは複数の部分から構成されます。たとえば、ドメイン名 "www.microsoft.com" は、ピリオドで区切られた、"www"、"microsoft"、および "com" の各ラベルから構成されます。
IDNA (Internationalizing Domain Names in Applications) 機構は、US-ASCII 文字の範囲外の Unicode 文字を含む国際ドメイン名を、表示可能な US-ASCII 文字範囲の Unicode 文字からのみ構成される IDNA ドメイン名に割り当てます。IDNA 機構はドメイン名だけを変換するために使用され、インターネット上で転送されるデータは変換の対象となりません。
IdnMapping クラスは、IDNA 機構を統合および拡張します。GetAscii メソッドは、ドメイン名を正規化し、正規化された名前を US-ASCII コード ポイント範囲 (U+0020 ~ U+007E) の表示可能な Unicode 文字から構成される表現に変換し、ASCII Compatible Encoding プレフィックス ("xn--") をそれぞれのラベルの前に付加します。
ラベル区切り記号文字の IDEOGRAPHIC FULL STOP (U+3002)、FULLWIDTH FULL STOP (U+FF0E)、および HALFWIDTH IDEOGRAPHIC FULL STOP (U+FF61) は、ラベル区切り記号の FULL STOP (ピリオド : U+002E) に変換されます。
詳細については、Request for Comments (RFC) の RFC 3490 標準「Internationalizing Domain Names in Applications」を参照してください。
GetAscii(String,Int32,Int32) メソッドを使用して、ドメイン名を IDNA 標準に準拠したドメイン名に変換するコード例を次に示します。次に、GetUnicode(String,Int32,Int32) メソッドは、標準化されたドメイン名を元のドメイン名に戻しますが、元のラベル区切り記号は標準のラベル区切り記号に置き換えられます。
' This example demonstrates the GetAscii and GetUnicode methods. ' For sake of illustration, this example uses the most complex ' form of those methods, not the most convenient. Imports System Imports System.Globalization Class Sample Public Shared Sub Main() ' Define a domain name consisting of the labels: GREEK SMALL LETTER ' PI (U+03C0); IDEOGRAPHIC FULL STOP (U+3002); GREEK SMALL LETTER ' THETA (U+03B8); FULLWIDTH FULL STOP (U+FF0E); and "com". Dim name As String = "π。θ.com" Dim international As String Dim nonInternational As String Dim msg1 As String = "the original non-internationalized " & vbCrLf & "domain name:" Dim msg2 As String = "Allow unassigned characters?: {0}" Dim msg3 As String = "Use non-internationalized rules?: {0}" Dim msg4 As String = "Convert the non-internationalized domain name to international format..." Dim msg5 As String = "Display the encoded domain name:" & vbCrLf & """{0}""" Dim msg6 As String = "the encoded domain name:" Dim msg7 As String = "Convert the internationalized domain name to non-international format..." Dim msg8 As String = "the reconstituted non-internationalized " & vbCrLf & "domain name:" Dim msg9 As String = "Visually compare the code points of the reconstituted string to the " & _ "original." & vbCrLf & _ "Note that the reconstituted string contains standard label " & _ "separators (U+002e)." ' ---------------------------------------------------------------------------- Console.Clear() CodePoints(name, msg1) ' ---------------------------------------------------------------------------- Dim idn As New IdnMapping() Console.WriteLine(msg2, idn.AllowUnassigned) Console.WriteLine(msg3, idn.UseStd3AsciiRules) Console.WriteLine() ' ---------------------------------------------------------------------------- Console.WriteLine(msg4) international = idn.GetAscii(name, 0, name.Length) Console.WriteLine(msg5, international) Console.WriteLine() CodePoints(international, msg6) ' ---------------------------------------------------------------------------- Console.WriteLine(msg7) nonInternational = idn.GetUnicode(international, 0, international.Length) CodePoints(nonInternational, msg8) Console.WriteLine(msg9) End Sub 'Main ' ---------------------------------------------------------------------------- Shared Sub CodePoints(ByVal value As String, ByVal title As String) Console.WriteLine("Display the Unicode code points of {0}", title) Dim c As Char For Each c In value Console.Write("{0:x4} ", Convert.ToInt32(c)) Next c Console.WriteLine() Console.WriteLine() End Sub 'CodePoints End Class 'Sample ' 'This code example produces the following results: ' 'Display the Unicode code points of the original non-internationalized 'domain name: '03c0 3002 03b8 ff0e 0063 006f 006d ' 'Allow unassigned characters?: False 'Use non-internationalized rules?: False ' 'Convert the non-internationalized domain name to international format... 'Display the encoded domain name: '"xn--1xa.xn--txa.com" ' 'Display the Unicode code points of the encoded domain name: '0078 006e 002d 002d 0031 0078 0061 002e 0078 006e 002d 002d 0074 0078 0061 002e 0063 006f '006d ' 'Convert the internationalized domain name to non-international format... 'Display the Unicode code points of the reconstituted non-internationalized 'domain name: '03c0 002e 03b8 002e 0063 006f 006d ' 'Visually compare the code points of the reconstituted string to the original. 'Note that the reconstituted string contains standard label separators (U+002e). '
// This example demonstrates the GetAscii and GetUnicode methods. // For sake of illustration, this example uses the most complex // form of those methods, not the most convenient. using System; using System.Globalization; class Sample { public static void Main() { /* Define a domain name consisting of the labels: GREEK SMALL LETTER PI (U+03C0); IDEOGRAPHIC FULL STOP (U+3002); GREEK SMALL LETTER THETA (U+03B8); FULLWIDTH FULL STOP (U+FF0E); and "com". */ string name = "\u03C0\u3002\u03B8\uFF0Ecom"; string international; string nonInternational; string msg1 = "the original non-internationalized \ndomain name:"; string msg2 = "Allow unassigned characters?: {0}"; string msg3 = "Use non-internationalized rules?: {0}"; string msg4 = "Convert the non-internationalized domain name to international format..."; string msg5 = "Display the encoded domain name:\n\"{0}\""; string msg6 = "the encoded domain name:"; string msg7 = "Convert the internationalized domain name to non-international format..."; string msg8 = "the reconstituted non-internationalized \ndomain name:"; string msg9 = "Visually compare the code points of the reconstituted string to the " + "original.\n" + "Note that the reconstituted string contains standard label " + "separators (U+002e)."; // ---------------------------------------------------------------------------- Console.Clear(); CodePoints(name, msg1); // ---------------------------------------------------------------------------- IdnMapping idn = new IdnMapping(); Console.WriteLine(msg2, idn.AllowUnassigned); Console.WriteLine(msg3, idn.UseStd3AsciiRules); Console.WriteLine(); // ---------------------------------------------------------------------------- Console.WriteLine(msg4); international = idn.GetAscii(name, 0, name.Length); Console.WriteLine(msg5, international); Console.WriteLine(); CodePoints(international, msg6); // ---------------------------------------------------------------------------- Console.WriteLine(msg7); nonInternational = idn.GetUnicode(international, 0, international.Length); CodePoints(nonInternational, msg8); Console.WriteLine(msg9); } // ---------------------------------------------------------------------------- static void CodePoints(string value, string title) { Console.WriteLine("Display the Unicode code points of {0}", title); foreach (char c in value) { Console.Write("{0:x4} ", Convert.ToInt32(c)); } Console.WriteLine(); Console.WriteLine(); } } /* This code example produces the following results: Display the Unicode code points of the original non-internationalized domain name: 03c0 3002 03b8 ff0e 0063 006f 006d Allow unassigned characters?: False Use non-internationalized rules?: False Convert the non-internationalized domain name to international format... Display the encoded domain name: "xn--1xa.xn--txa.com" Display the Unicode code points of the encoded domain name: 0078 006e 002d 002d 0031 0078 0061 002e 0078 006e 002d 002d 0074 0078 0061 002e 0063 006f 006d Convert the internationalized domain name to non-international format... Display the Unicode code points of the reconstituted non-internationalized domain name: 03c0 002e 03b8 002e 0063 006f 006d Visually compare the code points of the reconstituted string to the original. Note that the reconstituted string contains standard label separators (U+002e). */
System.Globalization.IdnMapping
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- IdnMapping クラスのページへのリンク