Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/nio/cs/OLD/DBCSDecoderMapping.java
41154 views
1
/*
2
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
*
28
* package private helper class which provides decoder (native->ucs)
29
* mapping capability for the benefit of compound encoders/decoders
30
* whose individual component submappings do not need an association with
31
* an enclosing charset
32
*
33
*/
34
35
36
public class DBCSDecoderMapping {
37
38
/* 1rst level index */
39
private short[] index1;
40
/*
41
* 2nd level index, provided by subclass
42
* every string has 0x10*(end-start+1) characters.
43
*/
44
private String[] index2;
45
46
protected int start;
47
protected int end;
48
49
protected static final char REPLACE_CHAR='\uFFFD';
50
51
public DBCSDecoderMapping(short[] index1, String[] index2,
52
int start, int end) {
53
this.index1 = index1;
54
this.index2 = index2;
55
this.start = start;
56
this.end = end;
57
}
58
59
/*
60
* Can be changed by subclass
61
*/
62
protected char decodeSingle(int b) {
63
if (b >= 0)
64
return (char) b;
65
return REPLACE_CHAR;
66
}
67
68
protected char decodeDouble(int byte1, int byte2) {
69
if (((byte1 < 0) || (byte1 > index1.length))
70
|| ((byte2 < start) || (byte2 > end)))
71
return REPLACE_CHAR;
72
73
int n = (index1[byte1] & 0xf) * (end - start + 1) + (byte2 - start);
74
return index2[index1[byte1] >> 4].charAt(n);
75
}
76
}
77
78