01: /*
02: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License version
07: * 2 only, as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful, but
10: * WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * General Public License version 2 for more details (a copy is
13: * included at /legal/license.txt).
14: *
15: * You should have received a copy of the GNU General Public License
16: * version 2 along with this work; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18: * 02110-1301 USA
19: *
20: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21: * Clara, CA 95054 or visit www.sun.com if you need additional
22: * information or have any questions.
23: */
24:
25: /*
26: * @(#)NormalizerUtilities.java 1.7 06/10/10
27: */
28:
29: package sun.text;
30:
31: public class NormalizerUtilities {
32:
33: public static int toLegacyMode(Normalizer.Mode mode) {
34: // find the index of the legacy mode in the table;
35: // if it's not there, default to Collator.NO_DECOMPOSITION (0)
36: int legacyMode = legacyModeMap.length;
37: while (legacyMode > 0) {
38: --legacyMode;
39: if (legacyModeMap[legacyMode] == mode) {
40: break;
41: }
42: }
43: return legacyMode;
44: }
45:
46: public static Normalizer.Mode toNormalizerMode(int mode) {
47: Normalizer.Mode normalizerMode;
48:
49: try {
50: normalizerMode = legacyModeMap[mode];
51: } catch (ArrayIndexOutOfBoundsException e) {
52: normalizerMode = Normalizer.NO_OP;
53: }
54: return normalizerMode;
55:
56: }
57:
58: static Normalizer.Mode[] legacyModeMap = { Normalizer.NO_OP, // Collator.NO_DECOMPOSITION
59: Normalizer.DECOMP, // Collator.CANONICAL_DECOMPOSITION
60: Normalizer.DECOMP_COMPAT, // Collator.FULL_DECOMPOSITION
61: };
62:
63: }
|