OSDN Git Service

CVS最新版の全ファイルを追加
[spring-ext/ozacc-mail.git] / src / java / com / ozacc / mail / impl / Cp932.java
1 package com.ozacc.mail.impl;\r
2 \r
3 import java.util.Locale;\r
4 \r
5 /**\r
6  * The Cp932 class contains a utility method for converting Microsoft's\r
7  * Cp 932 into JIS.\r
8  * <p>\r
9  * <strong>注:</strong> このクラスはpublicですが、ozacc-mail library外からは使用しないでください。\r
10  *\r
11  * @author Kazuhiro Kazama\r
12  * @version 1.0 01/06/97\r
13  * \r
14  * @since 1.0.2\r
15  */\r
16 public class Cp932 {\r
17 \r
18         private static boolean isCp932 = false;\r
19 \r
20         static {\r
21                 String p = System.getProperty("iscp932");\r
22                 String os = System.getProperty("os.name");\r
23                 if (Locale.getDefault().getLanguage().equals("ja")) {\r
24                         if (p != null && Boolean.getBoolean(p))\r
25                                 isCp932 = true;\r
26                         else if (os != null && (os.startsWith("Win")))\r
27                                 isCp932 = true;\r
28                 }\r
29         }\r
30 \r
31         /*\r
32          * You can't use this constructor.\r
33          */\r
34         private Cp932() {}\r
35 \r
36         /*\r
37          * This method converts Cp932 to JIS.\r
38          */\r
39         public static String toJIS(String s) {\r
40 \r
41                 /* commented by otsuka\r
42                  * \r
43                  * if (!isCp932)\r
44                  * return s;\r
45                  */\r
46 \r
47                 StringBuffer sb = new StringBuffer();\r
48                 char c;\r
49                 for (int i = 0; i < s.length(); i++) {\r
50                         c = s.charAt(i);\r
51 \r
52                         switch (c) {\r
53                                 case 0xff3c: // FULLWIDTH REVERSE SOLIDUS ->\r
54                                         c = 0x005c; // REVERSE SOLIDUS\r
55                                         break;\r
56                                 case 0xff5e: // FULLWIDTH TILDE ->\r
57                                         c = 0x301c; // WAVE DASH\r
58                                         break;\r
59                                 case 0x2225: // PARALLEL TO ->\r
60                                         c = 0x2016; // DOUBLE VERTICAL LINE\r
61                                         break;\r
62                                 case 0xff0d: // FULLWIDTH HYPHEN-MINUS ->\r
63                                         c = 0x2212; // MINUS SIGN\r
64                                         break;\r
65                                 case 0xffe0: // FULLWIDTH CENT SIGN ->\r
66                                         c = 0x00a2; // CENT SIGN\r
67                                         break;\r
68                                 case 0xffe1: // FULLWIDTH POUND SIGN ->\r
69                                         c = 0x00a3; // POUND SIGN\r
70                                         break;\r
71                                 case 0xffe2: // FULLWIDTH NOT SIGN ->\r
72                                         c = 0x00ac; // NOT SIGN\r
73                                         break;\r
74                         }\r
75                         sb.append(c);\r
76                 }\r
77                 return new String(sb);\r
78         }\r
79 \r
80         /*\r
81          * This method convert JIS to Cp932.\r
82          */\r
83         public static String toCp932(String s) {\r
84                 if (!isCp932)\r
85                         return s;\r
86                 StringBuffer sb = new StringBuffer();\r
87                 char c;\r
88                 for (int i = 0; i < s.length(); i++) {\r
89                         c = s.charAt(i);\r
90 \r
91                         switch (c) {\r
92                                 case 0x005c: // REVERSE SOLIDUS ->\r
93                                         c = 0xff3c; // FULLWIDTH REVERSE SOLIDUS\r
94                                         break;\r
95                                 case 0x301c: // WAVE DASH ->\r
96                                         c = 0xff5e; // FULLWIDTH TILDE\r
97                                         break;\r
98                                 case 0x2016: // DOUBLE VERTICAL LINE ->\r
99                                         c = 0x2225; // PARALLEL TO\r
100                                         break;\r
101                                 case 0x2212: // MINUS SIGN ->\r
102                                         c = 0xff0d; // FULLWIDTH HYPHEN-MINUS\r
103                                         break;\r
104                                 case 0x00a2: // CENT SIGN ->\r
105                                         c = 0xffe0; // FULLWIDTH CENT SIGN\r
106                                         break;\r
107                                 case 0x00a3: // POUND SIGN ->\r
108                                         c = 0xffe1; // FULLWIDTH POUND SIGN\r
109                                         break;\r
110                                 case 0x00ac: // NOT SIGN ->\r
111                                         c = 0xffe2; // FULLWIDTH NOT SIGN\r
112                                         break;\r
113                         }\r
114                         sb.append(c);\r
115                 }\r
116                 return new String(sb);\r
117         }\r
118 }