Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/StringTokenizer/Supplementary.java
41152 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
*I
26
* @test
27
* @bug 4900727
28
* @summary Unit test for supplementary characters (JSR-204)
29
*/
30
31
import java.util.StringTokenizer;
32
33
public class Supplementary {
34
public static void main(String[] args) {
35
String text =
36
"ab\uD800\uDC00\uD800\uDC01cd\uD800\uDC00\uD800xy \uD801\uDC00z\t123\uDCFF456";
37
String delims = " \t\r\n\f.\uD800\uDC00,:;";
38
String[] expected =
39
{"ab", "\uD800\uDC01cd", "\uD800xy", "\uD801\uDC00z", "123\uDCFF456" };
40
testTokenizer(text, delims, expected);
41
42
delims = " \t\r\n\f.,:;\uDCFF";
43
expected = new String[] { "ab\uD800\uDC00\uD800\uDC01cd\uD800\uDC00\uD800xy",
44
"\uD801\uDC00z",
45
"123",
46
"456" };
47
testTokenizer(text, delims, expected);
48
49
delims = "\uD800";
50
expected = new String[] { "ab\uD800\uDC00\uD800\uDC01cd\uD800\uDC00",
51
"xy \uD801\uDC00z\t123\uDCFF456" };
52
testTokenizer(text, delims, expected);
53
}
54
55
static void testTokenizer(String text, String delims, String[] expected) {
56
StringTokenizer tokenizer = new StringTokenizer(text, delims);
57
int n = tokenizer.countTokens();
58
if (n != expected.length) {
59
throw new RuntimeException("countToken(): wrong value " + n
60
+ ", expected " + expected.length);
61
}
62
int i = 0;
63
while (tokenizer.hasMoreTokens()) {
64
String token = tokenizer.nextToken();
65
if (!token.equals(expected[i++])) {
66
throw new RuntimeException("nextToken(): wrong token. got \""
67
+ token + "\", expected \"" + expected[i-1]);
68
}
69
}
70
if (i != expected.length) {
71
throw new RuntimeException("unexpected the number of tokens: " + i
72
+ ", expected " + expected.length);
73
}
74
}
75
}
76
77