[msvc] Update csproj files (#4846)
[mono.git] / mcs / class / I18N / CJK / JISConvert.cs
1 /*
2  * JISConvert.cs - Implementation of the "System.Text.JISConvert" class.
3  *
4  * Copyright (c) 2002  Southern Storm Software, Pty Ltd
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 namespace I18N.CJK
26 {
27
28 using System;
29
30 // This class assists other encoding classes in converting back
31 // and forth between JIS character sets and Unicode.  It uses
32 // several large tables to do this, some of which are stored in
33 // the resource section of the assembly for efficient access.
34
35 internal unsafe sealed class JISConvert
36 {
37         // Table identifiers.
38         private const int JISX0208_To_Unicode = 1;
39         private const int JISX0212_To_Unicode = 2;
40         private const int CJK_To_JIS          = 3;
41         private const int Greek_To_JIS        = 4;
42         private const int Extra_To_JIS        = 5;
43
44         // Public access to the conversion tables.
45 #if __PNET__
46         public byte *jisx0208ToUnicode;
47         public byte *jisx0212ToUnicode;
48         public byte *cjkToJis;
49         public byte *greekToJis;
50         public byte *extraToJis;
51 #else
52         public byte[] jisx0208ToUnicode;
53         public byte[] jisx0212ToUnicode;
54         public byte[] cjkToJis;
55         public byte[] greekToJis;
56         public byte[] extraToJis;
57 #endif
58
59         // Constructor.
60         private JISConvert()
61                         {
62                                 // Load the conversion tables.
63                                 CodeTable table = new CodeTable("jis.table");
64                                 jisx0208ToUnicode = table.GetSection(JISX0208_To_Unicode);
65                                 jisx0212ToUnicode = table.GetSection(JISX0212_To_Unicode);
66                                 cjkToJis = table.GetSection(CJK_To_JIS);
67                                 greekToJis = table.GetSection(Greek_To_JIS);
68                                 extraToJis = table.GetSection(Extra_To_JIS);
69                                 table.Dispose();
70                         }
71
72         // The one and only JIS conversion object in the system.
73         private static JISConvert convert;
74         static readonly object lockobj = new object ();
75         // Get the primary JIS conversion object.
76         public static JISConvert Convert
77                         {
78                                 get
79                                 {
80                                         lock(lockobj)
81                                         {
82                                                 if(convert != null)
83                                                 {
84                                                         return convert;
85                                                 }
86                                                 else
87                                                 {
88                                                         convert = new JISConvert();
89                                                         return convert;
90                                                 }
91                                         }
92                                 }
93                         }
94
95 }; // class JISConvert
96
97 }; // namespace I18N.CJK