1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.vcard;
18 
19 import java.util.HashMap;
20 import java.util.Map;
21 
22 /**
23  * TextUtils especially for Japanese.
24  */
25 /* package */ class JapaneseUtils {
26     static private final Map<Character, String> sHalfWidthMap =
27         new HashMap<Character, String>();
28 
29     static {
30         sHalfWidthMap.put('\u3001', "\uFF64");
31         sHalfWidthMap.put('\u3002', "\uFF61");
32         sHalfWidthMap.put('\u300C', "\uFF62");
33         sHalfWidthMap.put('\u300D', "\uFF63");
34         sHalfWidthMap.put('\u301C', "~");
35         sHalfWidthMap.put('\u3041', "\uFF67");
36         sHalfWidthMap.put('\u3042', "\uFF71");
37         sHalfWidthMap.put('\u3043', "\uFF68");
38         sHalfWidthMap.put('\u3044', "\uFF72");
39         sHalfWidthMap.put('\u3045', "\uFF69");
40         sHalfWidthMap.put('\u3046', "\uFF73");
41         sHalfWidthMap.put('\u3047', "\uFF6A");
42         sHalfWidthMap.put('\u3048', "\uFF74");
43         sHalfWidthMap.put('\u3049', "\uFF6B");
44         sHalfWidthMap.put('\u304A', "\uFF75");
45         sHalfWidthMap.put('\u304B', "\uFF76");
46         sHalfWidthMap.put('\u304C', "\uFF76\uFF9E");
47         sHalfWidthMap.put('\u304D', "\uFF77");
48         sHalfWidthMap.put('\u304E', "\uFF77\uFF9E");
49         sHalfWidthMap.put('\u304F', "\uFF78");
50         sHalfWidthMap.put('\u3050', "\uFF78\uFF9E");
51         sHalfWidthMap.put('\u3051', "\uFF79");
52         sHalfWidthMap.put('\u3052', "\uFF79\uFF9E");
53         sHalfWidthMap.put('\u3053', "\uFF7A");
54         sHalfWidthMap.put('\u3054', "\uFF7A\uFF9E");
55         sHalfWidthMap.put('\u3055', "\uFF7B");
56         sHalfWidthMap.put('\u3056', "\uFF7B\uFF9E");
57         sHalfWidthMap.put('\u3057', "\uFF7C");
58         sHalfWidthMap.put('\u3058', "\uFF7C\uFF9E");
59         sHalfWidthMap.put('\u3059', "\uFF7D");
60         sHalfWidthMap.put('\u305A', "\uFF7D\uFF9E");
61         sHalfWidthMap.put('\u305B', "\uFF7E");
62         sHalfWidthMap.put('\u305C', "\uFF7E\uFF9E");
63         sHalfWidthMap.put('\u305D', "\uFF7F");
64         sHalfWidthMap.put('\u305E', "\uFF7F\uFF9E");
65         sHalfWidthMap.put('\u305F', "\uFF80");
66         sHalfWidthMap.put('\u3060', "\uFF80\uFF9E");
67         sHalfWidthMap.put('\u3061', "\uFF81");
68         sHalfWidthMap.put('\u3062', "\uFF81\uFF9E");
69         sHalfWidthMap.put('\u3063', "\uFF6F");
70         sHalfWidthMap.put('\u3064', "\uFF82");
71         sHalfWidthMap.put('\u3065', "\uFF82\uFF9E");
72         sHalfWidthMap.put('\u3066', "\uFF83");
73         sHalfWidthMap.put('\u3067', "\uFF83\uFF9E");
74         sHalfWidthMap.put('\u3068', "\uFF84");
75         sHalfWidthMap.put('\u3069', "\uFF84\uFF9E");
76         sHalfWidthMap.put('\u306A', "\uFF85");
77         sHalfWidthMap.put('\u306B', "\uFF86");
78         sHalfWidthMap.put('\u306C', "\uFF87");
79         sHalfWidthMap.put('\u306D', "\uFF88");
80         sHalfWidthMap.put('\u306E', "\uFF89");
81         sHalfWidthMap.put('\u306F', "\uFF8A");
82         sHalfWidthMap.put('\u3070', "\uFF8A\uFF9E");
83         sHalfWidthMap.put('\u3071', "\uFF8A\uFF9F");
84         sHalfWidthMap.put('\u3072', "\uFF8B");
85         sHalfWidthMap.put('\u3073', "\uFF8B\uFF9E");
86         sHalfWidthMap.put('\u3074', "\uFF8B\uFF9F");
87         sHalfWidthMap.put('\u3075', "\uFF8C");
88         sHalfWidthMap.put('\u3076', "\uFF8C\uFF9E");
89         sHalfWidthMap.put('\u3077', "\uFF8C\uFF9F");
90         sHalfWidthMap.put('\u3078', "\uFF8D");
91         sHalfWidthMap.put('\u3079', "\uFF8D\uFF9E");
92         sHalfWidthMap.put('\u307A', "\uFF8D\uFF9F");
93         sHalfWidthMap.put('\u307B', "\uFF8E");
94         sHalfWidthMap.put('\u307C', "\uFF8E\uFF9E");
95         sHalfWidthMap.put('\u307D', "\uFF8E\uFF9F");
96         sHalfWidthMap.put('\u307E', "\uFF8F");
97         sHalfWidthMap.put('\u307F', "\uFF90");
98         sHalfWidthMap.put('\u3080', "\uFF91");
99         sHalfWidthMap.put('\u3081', "\uFF92");
100         sHalfWidthMap.put('\u3082', "\uFF93");
101         sHalfWidthMap.put('\u3083', "\uFF6C");
102         sHalfWidthMap.put('\u3084', "\uFF94");
103         sHalfWidthMap.put('\u3085', "\uFF6D");
104         sHalfWidthMap.put('\u3086', "\uFF95");
105         sHalfWidthMap.put('\u3087', "\uFF6E");
106         sHalfWidthMap.put('\u3088', "\uFF96");
107         sHalfWidthMap.put('\u3089', "\uFF97");
108         sHalfWidthMap.put('\u308A', "\uFF98");
109         sHalfWidthMap.put('\u308B', "\uFF99");
110         sHalfWidthMap.put('\u308C', "\uFF9A");
111         sHalfWidthMap.put('\u308D', "\uFF9B");
112         sHalfWidthMap.put('\u308E', "\uFF9C");
113         sHalfWidthMap.put('\u308F', "\uFF9C");
114         sHalfWidthMap.put('\u3090', "\uFF72");
115         sHalfWidthMap.put('\u3091', "\uFF74");
116         sHalfWidthMap.put('\u3092', "\uFF66");
117         sHalfWidthMap.put('\u3093', "\uFF9D");
118         sHalfWidthMap.put('\u309B', "\uFF9E");
119         sHalfWidthMap.put('\u309C', "\uFF9F");
120         sHalfWidthMap.put('\u30A1', "\uFF67");
121         sHalfWidthMap.put('\u30A2', "\uFF71");
122         sHalfWidthMap.put('\u30A3', "\uFF68");
123         sHalfWidthMap.put('\u30A4', "\uFF72");
124         sHalfWidthMap.put('\u30A5', "\uFF69");
125         sHalfWidthMap.put('\u30A6', "\uFF73");
126         sHalfWidthMap.put('\u30A7', "\uFF6A");
127         sHalfWidthMap.put('\u30A8', "\uFF74");
128         sHalfWidthMap.put('\u30A9', "\uFF6B");
129         sHalfWidthMap.put('\u30AA', "\uFF75");
130         sHalfWidthMap.put('\u30AB', "\uFF76");
131         sHalfWidthMap.put('\u30AC', "\uFF76\uFF9E");
132         sHalfWidthMap.put('\u30AD', "\uFF77");
133         sHalfWidthMap.put('\u30AE', "\uFF77\uFF9E");
134         sHalfWidthMap.put('\u30AF', "\uFF78");
135         sHalfWidthMap.put('\u30B0', "\uFF78\uFF9E");
136         sHalfWidthMap.put('\u30B1', "\uFF79");
137         sHalfWidthMap.put('\u30B2', "\uFF79\uFF9E");
138         sHalfWidthMap.put('\u30B3', "\uFF7A");
139         sHalfWidthMap.put('\u30B4', "\uFF7A\uFF9E");
140         sHalfWidthMap.put('\u30B5', "\uFF7B");
141         sHalfWidthMap.put('\u30B6', "\uFF7B\uFF9E");
142         sHalfWidthMap.put('\u30B7', "\uFF7C");
143         sHalfWidthMap.put('\u30B8', "\uFF7C\uFF9E");
144         sHalfWidthMap.put('\u30B9', "\uFF7D");
145         sHalfWidthMap.put('\u30BA', "\uFF7D\uFF9E");
146         sHalfWidthMap.put('\u30BB', "\uFF7E");
147         sHalfWidthMap.put('\u30BC', "\uFF7E\uFF9E");
148         sHalfWidthMap.put('\u30BD', "\uFF7F");
149         sHalfWidthMap.put('\u30BE', "\uFF7F\uFF9E");
150         sHalfWidthMap.put('\u30BF', "\uFF80");
151         sHalfWidthMap.put('\u30C0', "\uFF80\uFF9E");
152         sHalfWidthMap.put('\u30C1', "\uFF81");
153         sHalfWidthMap.put('\u30C2', "\uFF81\uFF9E");
154         sHalfWidthMap.put('\u30C3', "\uFF6F");
155         sHalfWidthMap.put('\u30C4', "\uFF82");
156         sHalfWidthMap.put('\u30C5', "\uFF82\uFF9E");
157         sHalfWidthMap.put('\u30C6', "\uFF83");
158         sHalfWidthMap.put('\u30C7', "\uFF83\uFF9E");
159         sHalfWidthMap.put('\u30C8', "\uFF84");
160         sHalfWidthMap.put('\u30C9', "\uFF84\uFF9E");
161         sHalfWidthMap.put('\u30CA', "\uFF85");
162         sHalfWidthMap.put('\u30CB', "\uFF86");
163         sHalfWidthMap.put('\u30CC', "\uFF87");
164         sHalfWidthMap.put('\u30CD', "\uFF88");
165         sHalfWidthMap.put('\u30CE', "\uFF89");
166         sHalfWidthMap.put('\u30CF', "\uFF8A");
167         sHalfWidthMap.put('\u30D0', "\uFF8A\uFF9E");
168         sHalfWidthMap.put('\u30D1', "\uFF8A\uFF9F");
169         sHalfWidthMap.put('\u30D2', "\uFF8B");
170         sHalfWidthMap.put('\u30D3', "\uFF8B\uFF9E");
171         sHalfWidthMap.put('\u30D4', "\uFF8B\uFF9F");
172         sHalfWidthMap.put('\u30D5', "\uFF8C");
173         sHalfWidthMap.put('\u30D6', "\uFF8C\uFF9E");
174         sHalfWidthMap.put('\u30D7', "\uFF8C\uFF9F");
175         sHalfWidthMap.put('\u30D8', "\uFF8D");
176         sHalfWidthMap.put('\u30D9', "\uFF8D\uFF9E");
177         sHalfWidthMap.put('\u30DA', "\uFF8D\uFF9F");
178         sHalfWidthMap.put('\u30DB', "\uFF8E");
179         sHalfWidthMap.put('\u30DC', "\uFF8E\uFF9E");
180         sHalfWidthMap.put('\u30DD', "\uFF8E\uFF9F");
181         sHalfWidthMap.put('\u30DE', "\uFF8F");
182         sHalfWidthMap.put('\u30DF', "\uFF90");
183         sHalfWidthMap.put('\u30E0', "\uFF91");
184         sHalfWidthMap.put('\u30E1', "\uFF92");
185         sHalfWidthMap.put('\u30E2', "\uFF93");
186         sHalfWidthMap.put('\u30E3', "\uFF6C");
187         sHalfWidthMap.put('\u30E4', "\uFF94");
188         sHalfWidthMap.put('\u30E5', "\uFF6D");
189         sHalfWidthMap.put('\u30E6', "\uFF95");
190         sHalfWidthMap.put('\u30E7', "\uFF6E");
191         sHalfWidthMap.put('\u30E8', "\uFF96");
192         sHalfWidthMap.put('\u30E9', "\uFF97");
193         sHalfWidthMap.put('\u30EA', "\uFF98");
194         sHalfWidthMap.put('\u30EB', "\uFF99");
195         sHalfWidthMap.put('\u30EC', "\uFF9A");
196         sHalfWidthMap.put('\u30ED', "\uFF9B");
197         sHalfWidthMap.put('\u30EE', "\uFF9C");
198         sHalfWidthMap.put('\u30EF', "\uFF9C");
199         sHalfWidthMap.put('\u30F0', "\uFF72");
200         sHalfWidthMap.put('\u30F1', "\uFF74");
201         sHalfWidthMap.put('\u30F2', "\uFF66");
202         sHalfWidthMap.put('\u30F3', "\uFF9D");
203         sHalfWidthMap.put('\u30F4', "\uFF73\uFF9E");
204         sHalfWidthMap.put('\u30F5', "\uFF76");
205         sHalfWidthMap.put('\u30F6', "\uFF79");
206         sHalfWidthMap.put('\u30FB', "\uFF65");
207         sHalfWidthMap.put('\u30FC', "\uFF70");
208         sHalfWidthMap.put('\uFF01', "!");
209         sHalfWidthMap.put('\uFF02', "\"");
210         sHalfWidthMap.put('\uFF03', "#");
211         sHalfWidthMap.put('\uFF04', "$");
212         sHalfWidthMap.put('\uFF05', "%");
213         sHalfWidthMap.put('\uFF06', "&");
214         sHalfWidthMap.put('\uFF07', "'");
215         sHalfWidthMap.put('\uFF08', "(");
216         sHalfWidthMap.put('\uFF09', ")");
217         sHalfWidthMap.put('\uFF0A', "*");
218         sHalfWidthMap.put('\uFF0B', "+");
219         sHalfWidthMap.put('\uFF0C', ",");
220         sHalfWidthMap.put('\uFF0D', "-");
221         sHalfWidthMap.put('\uFF0E', ".");
222         sHalfWidthMap.put('\uFF0F', "/");
223         sHalfWidthMap.put('\uFF10', "0");
224         sHalfWidthMap.put('\uFF11', "1");
225         sHalfWidthMap.put('\uFF12', "2");
226         sHalfWidthMap.put('\uFF13', "3");
227         sHalfWidthMap.put('\uFF14', "4");
228         sHalfWidthMap.put('\uFF15', "5");
229         sHalfWidthMap.put('\uFF16', "6");
230         sHalfWidthMap.put('\uFF17', "7");
231         sHalfWidthMap.put('\uFF18', "8");
232         sHalfWidthMap.put('\uFF19', "9");
233         sHalfWidthMap.put('\uFF1A', ":");
234         sHalfWidthMap.put('\uFF1B', ";");
235         sHalfWidthMap.put('\uFF1C', "<");
236         sHalfWidthMap.put('\uFF1D', "=");
237         sHalfWidthMap.put('\uFF1E', ">");
238         sHalfWidthMap.put('\uFF1F', "?");
239         sHalfWidthMap.put('\uFF20', "@");
240         sHalfWidthMap.put('\uFF21', "A");
241         sHalfWidthMap.put('\uFF22', "B");
242         sHalfWidthMap.put('\uFF23', "C");
243         sHalfWidthMap.put('\uFF24', "D");
244         sHalfWidthMap.put('\uFF25', "E");
245         sHalfWidthMap.put('\uFF26', "F");
246         sHalfWidthMap.put('\uFF27', "G");
247         sHalfWidthMap.put('\uFF28', "H");
248         sHalfWidthMap.put('\uFF29', "I");
249         sHalfWidthMap.put('\uFF2A', "J");
250         sHalfWidthMap.put('\uFF2B', "K");
251         sHalfWidthMap.put('\uFF2C', "L");
252         sHalfWidthMap.put('\uFF2D', "M");
253         sHalfWidthMap.put('\uFF2E', "N");
254         sHalfWidthMap.put('\uFF2F', "O");
255         sHalfWidthMap.put('\uFF30', "P");
256         sHalfWidthMap.put('\uFF31', "Q");
257         sHalfWidthMap.put('\uFF32', "R");
258         sHalfWidthMap.put('\uFF33', "S");
259         sHalfWidthMap.put('\uFF34', "T");
260         sHalfWidthMap.put('\uFF35', "U");
261         sHalfWidthMap.put('\uFF36', "V");
262         sHalfWidthMap.put('\uFF37', "W");
263         sHalfWidthMap.put('\uFF38', "X");
264         sHalfWidthMap.put('\uFF39', "Y");
265         sHalfWidthMap.put('\uFF3A', "Z");
266         sHalfWidthMap.put('\uFF3B', "[");
267         sHalfWidthMap.put('\uFF3C', "\\");
268         sHalfWidthMap.put('\uFF3D', "]");
269         sHalfWidthMap.put('\uFF3E', "^");
270         sHalfWidthMap.put('\uFF3F', "_");
271         sHalfWidthMap.put('\uFF41', "a");
272         sHalfWidthMap.put('\uFF42', "b");
273         sHalfWidthMap.put('\uFF43', "c");
274         sHalfWidthMap.put('\uFF44', "d");
275         sHalfWidthMap.put('\uFF45', "e");
276         sHalfWidthMap.put('\uFF46', "f");
277         sHalfWidthMap.put('\uFF47', "g");
278         sHalfWidthMap.put('\uFF48', "h");
279         sHalfWidthMap.put('\uFF49', "i");
280         sHalfWidthMap.put('\uFF4A', "j");
281         sHalfWidthMap.put('\uFF4B', "k");
282         sHalfWidthMap.put('\uFF4C', "l");
283         sHalfWidthMap.put('\uFF4D', "m");
284         sHalfWidthMap.put('\uFF4E', "n");
285         sHalfWidthMap.put('\uFF4F', "o");
286         sHalfWidthMap.put('\uFF50', "p");
287         sHalfWidthMap.put('\uFF51', "q");
288         sHalfWidthMap.put('\uFF52', "r");
289         sHalfWidthMap.put('\uFF53', "s");
290         sHalfWidthMap.put('\uFF54', "t");
291         sHalfWidthMap.put('\uFF55', "u");
292         sHalfWidthMap.put('\uFF56', "v");
293         sHalfWidthMap.put('\uFF57', "w");
294         sHalfWidthMap.put('\uFF58', "x");
295         sHalfWidthMap.put('\uFF59', "y");
296         sHalfWidthMap.put('\uFF5A', "z");
297         sHalfWidthMap.put('\uFF5B', "{");
298         sHalfWidthMap.put('\uFF5C', "|");
299         sHalfWidthMap.put('\uFF5D', "}");
300         sHalfWidthMap.put('\uFF5E', "~");
301         sHalfWidthMap.put('\uFF61', "\uFF61");
302         sHalfWidthMap.put('\uFF62', "\uFF62");
303         sHalfWidthMap.put('\uFF63', "\uFF63");
304         sHalfWidthMap.put('\uFF64', "\uFF64");
305         sHalfWidthMap.put('\uFF65', "\uFF65");
306         sHalfWidthMap.put('\uFF66', "\uFF66");
307         sHalfWidthMap.put('\uFF67', "\uFF67");
308         sHalfWidthMap.put('\uFF68', "\uFF68");
309         sHalfWidthMap.put('\uFF69', "\uFF69");
310         sHalfWidthMap.put('\uFF6A', "\uFF6A");
311         sHalfWidthMap.put('\uFF6B', "\uFF6B");
312         sHalfWidthMap.put('\uFF6C', "\uFF6C");
313         sHalfWidthMap.put('\uFF6D', "\uFF6D");
314         sHalfWidthMap.put('\uFF6E', "\uFF6E");
315         sHalfWidthMap.put('\uFF6F', "\uFF6F");
316         sHalfWidthMap.put('\uFF70', "\uFF70");
317         sHalfWidthMap.put('\uFF71', "\uFF71");
318         sHalfWidthMap.put('\uFF72', "\uFF72");
319         sHalfWidthMap.put('\uFF73', "\uFF73");
320         sHalfWidthMap.put('\uFF74', "\uFF74");
321         sHalfWidthMap.put('\uFF75', "\uFF75");
322         sHalfWidthMap.put('\uFF76', "\uFF76");
323         sHalfWidthMap.put('\uFF77', "\uFF77");
324         sHalfWidthMap.put('\uFF78', "\uFF78");
325         sHalfWidthMap.put('\uFF79', "\uFF79");
326         sHalfWidthMap.put('\uFF7A', "\uFF7A");
327         sHalfWidthMap.put('\uFF7B', "\uFF7B");
328         sHalfWidthMap.put('\uFF7C', "\uFF7C");
329         sHalfWidthMap.put('\uFF7D', "\uFF7D");
330         sHalfWidthMap.put('\uFF7E', "\uFF7E");
331         sHalfWidthMap.put('\uFF7F', "\uFF7F");
332         sHalfWidthMap.put('\uFF80', "\uFF80");
333         sHalfWidthMap.put('\uFF81', "\uFF81");
334         sHalfWidthMap.put('\uFF82', "\uFF82");
335         sHalfWidthMap.put('\uFF83', "\uFF83");
336         sHalfWidthMap.put('\uFF84', "\uFF84");
337         sHalfWidthMap.put('\uFF85', "\uFF85");
338         sHalfWidthMap.put('\uFF86', "\uFF86");
339         sHalfWidthMap.put('\uFF87', "\uFF87");
340         sHalfWidthMap.put('\uFF88', "\uFF88");
341         sHalfWidthMap.put('\uFF89', "\uFF89");
342         sHalfWidthMap.put('\uFF8A', "\uFF8A");
343         sHalfWidthMap.put('\uFF8B', "\uFF8B");
344         sHalfWidthMap.put('\uFF8C', "\uFF8C");
345         sHalfWidthMap.put('\uFF8D', "\uFF8D");
346         sHalfWidthMap.put('\uFF8E', "\uFF8E");
347         sHalfWidthMap.put('\uFF8F', "\uFF8F");
348         sHalfWidthMap.put('\uFF90', "\uFF90");
349         sHalfWidthMap.put('\uFF91', "\uFF91");
350         sHalfWidthMap.put('\uFF92', "\uFF92");
351         sHalfWidthMap.put('\uFF93', "\uFF93");
352         sHalfWidthMap.put('\uFF94', "\uFF94");
353         sHalfWidthMap.put('\uFF95', "\uFF95");
354         sHalfWidthMap.put('\uFF96', "\uFF96");
355         sHalfWidthMap.put('\uFF97', "\uFF97");
356         sHalfWidthMap.put('\uFF98', "\uFF98");
357         sHalfWidthMap.put('\uFF99', "\uFF99");
358         sHalfWidthMap.put('\uFF9A', "\uFF9A");
359         sHalfWidthMap.put('\uFF9B', "\uFF9B");
360         sHalfWidthMap.put('\uFF9C', "\uFF9C");
361         sHalfWidthMap.put('\uFF9D', "\uFF9D");
362         sHalfWidthMap.put('\uFF9E', "\uFF9E");
363         sHalfWidthMap.put('\uFF9F', "\uFF9F");
364         sHalfWidthMap.put('\uFFE5', "\u005C\u005C");
365     }
366 
367     /**
368      * Returns half-width version of that character if possible. Returns null if not possible
369      * @param ch input character
370      * @return CharSequence object if the mapping for ch exists. Return null otherwise.
371      */
tryGetHalfWidthText(final char ch)372     public static String tryGetHalfWidthText(final char ch) {
373         if (sHalfWidthMap.containsKey(ch)) {
374             return sHalfWidthMap.get(ch);
375         } else {
376             return null;
377         }
378     }
379 }
380