Skip to content

Commit 35a94b7

Browse files
committed
8339803: Acknowledge case insensitive unambiguous keywords in tzdata files
Reviewed-by: jlu, coffeys
1 parent 51b85a1 commit 35a94b7

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ private static Map<Locale, String> coverageLevelsMap() throws Exception {
13721372
private static void generateTZDBShortNamesMap() throws IOException {
13731373
Files.walk(Path.of(tzDataDir), 1, FileVisitOption.FOLLOW_LINKS)
13741374
.filter(p -> p.toFile().isFile())
1375+
.filter(p -> p.getFileName().toString().matches("africa|antarctica|asia|australasia|backward|etcetera|europe|northamerica|southamerica"))
13751376
.forEach(p -> {
13761377
try {
13771378
String zone = null;
@@ -1394,43 +1395,41 @@ private static void generateTZDBShortNamesMap() throws IOException {
13941395
}
13951396
// remove comments in-line
13961397
line = line.replaceAll("[ \t]*#.*", "");
1397-
1398+
var tokens = line.split("[ \t]+", -1);
1399+
var token0len = tokens.length > 0 ? tokens[0].length() : 0;
13981400
// Zone line
1399-
if (line.startsWith("Zone")) {
1401+
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Zone", 0, token0len)) {
14001402
if (zone != null) {
14011403
tzdbShortNamesMap.put(zone, format + NBSP + rule);
14021404
}
1403-
var zl = line.split("[ \t]+", -1);
1404-
zone = zl[1];
1405-
rule = zl[3];
1406-
format = flipIfNeeded(inVanguard, zl[4]);
1405+
zone = tokens[1];
1406+
rule = tokens[3];
1407+
format = flipIfNeeded(inVanguard, tokens[4]);
14071408
} else {
14081409
if (zone != null) {
1409-
if (line.startsWith("Rule") ||
1410-
line.startsWith("Link")) {
1410+
if (token0len > 0 &&
1411+
(tokens[0].regionMatches(true, 0, "Rule", 0, token0len) ||
1412+
tokens[0].regionMatches(true, 0, "Link", 0, token0len))) {
14111413
tzdbShortNamesMap.put(zone, format + NBSP + rule);
14121414
zone = null;
14131415
rule = null;
14141416
format = null;
14151417
} else {
1416-
var s = line.split("[ \t]+", -1);
1417-
rule = s[2];
1418-
format = flipIfNeeded(inVanguard, s[3]);
1418+
rule = tokens[2];
1419+
format = flipIfNeeded(inVanguard, tokens[3]);
14191420
}
14201421
}
14211422
}
14221423

14231424
// Rule line
1424-
if (line.startsWith("Rule")) {
1425-
var rl = line.split("[ \t]+", -1);
1426-
tzdbSubstLetters.put(rl[1] + NBSP + (rl[8].equals("0") ? STD : DST),
1427-
rl[9].replace(NO_SUBST, ""));
1425+
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Rule", 0, token0len)) {
1426+
tzdbSubstLetters.put(tokens[1] + NBSP + (tokens[8].equals("0") ? STD : DST),
1427+
tokens[9].replace(NO_SUBST, ""));
14281428
}
14291429

14301430
// Link line
1431-
if (line.startsWith("Link")) {
1432-
var ll = line.split("[ \t]+", -1);
1433-
tzdbLinks.put(ll[2], ll[1]);
1431+
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Link", 0, token0len)) {
1432+
tzdbLinks.put(tokens[2], tokens[1]);
14341433
}
14351434
}
14361435

make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesProvider.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ private void load(List<Path> files) throws IOException {
164164
}
165165
continue;
166166
}
167-
if (line.startsWith("Zone")) { // parse Zone line
167+
int token0len = tokens.length > 0 ? tokens[0].length() : line.length();
168+
if (line.regionMatches(true, 0, "Zone", 0, token0len)) { // parse Zone line
168169
String name = tokens[1];
169170
if (excludedZones.contains(name)){
170171
continue;
@@ -182,13 +183,13 @@ private void load(List<Path> files) throws IOException {
182183
if (zLine.parse(tokens, 2)) {
183184
openZone = null;
184185
}
185-
} else if (line.startsWith("Rule")) { // parse Rule line
186+
} else if (line.regionMatches(true, 0, "Rule", 0, token0len)) { // parse Rule line
186187
String name = tokens[1];
187188
if (!rules.containsKey(name)) {
188189
rules.put(name, new ArrayList<RuleLine>(10));
189190
}
190191
rules.get(name).add(new RuleLine().parse(tokens));
191-
} else if (line.startsWith("Link")) { // parse link line
192+
} else if (line.regionMatches(true, 0, "Link", 0, token0len)) { // parse link line
192193
if (tokens.length >= 3) {
193194
String realId = tokens[1];
194195
String aliasId = tokens[2];
@@ -304,7 +305,7 @@ private void parse(String[] tokens, int off) {
304305
month = parseMonth(tokens[off++]);
305306
if (off < tokens.length) {
306307
String dayRule = tokens[off++];
307-
if (dayRule.startsWith("last")) {
308+
if (dayRule.regionMatches(true, 0, "last", 0, 4)) {
308309
dayOfMonth = -1;
309310
dayOfWeek = parseDayOfWeek(dayRule.substring(4));
310311
adjustForwards = false;
@@ -355,11 +356,12 @@ private void parse(String[] tokens, int off) {
355356
}
356357

357358
int parseYear(String year, int defaultYear) {
358-
switch (year.toLowerCase()) {
359-
case "min": return 1900;
360-
case "max": return Year.MAX_VALUE;
361-
case "only": return defaultYear;
362-
}
359+
int len = year.length();
360+
361+
if (year.regionMatches(true, 0, "minimum", 0, len)) return 1900;
362+
if (year.regionMatches(true, 0, "maximum", 0, len)) return Year.MAX_VALUE;
363+
if (year.regionMatches(true, 0, "only", 0, len)) return defaultYear;
364+
363365
return Integer.parseInt(year);
364366
}
365367

test/jdk/sun/util/calendar/zi/RuleRec.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -168,12 +168,13 @@ static RuleRec parse(StringTokenizer tokens) {
168168
rec.toYear = Integer.parseInt(token);
169169
} catch (NumberFormatException e) {
170170
// it's not integer
171-
if ("min".equals(token) || "minimum".equals(token)) {
171+
int len = token.length();
172+
if (token.regionMatches(true, 0, "minimum", 0, len)) {
172173
rec.fromYear = Zoneinfo.getMinYear();
173-
} else if ("max".equals(token) || "maximum".equals(token)) {
174+
} else if (token.regionMatches(true, 0, "maximum", 0, len)) {
174175
rec.toYear = Integer.MAX_VALUE;
175176
rec.isLastRule = true;
176-
} else if ("only".equals(token)) {
177+
} else if (token.regionMatches(true, 0, "only", 0, len)) {
177178
rec.toYear = rec.fromYear;
178179
} else {
179180
Main.panic("invalid year value: "+token);

test/jdk/sun/util/calendar/zi/Zoneinfo.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ static Zoneinfo parse(String fname) {
240240
continue;
241241
}
242242
String token = tokens.nextToken();
243+
int len = token.length();
243244

244-
if (continued || "Zone".equals(token)) {
245+
if (continued || token.regionMatches(true, 0, "Zone", 0, len)){
245246
if (zone == null) {
246247
if (!tokens.hasMoreTokens()) {
247248
panic("syntax error: zone no more token");
@@ -268,7 +269,7 @@ static Zoneinfo parse(String fname) {
268269
}
269270
zone = null;
270271
}
271-
} else if ("Rule".equals(token)) {
272+
} else if (token.regionMatches(true, 0, "Rule", 0, len)) {
272273
if (!tokens.hasMoreTokens()) {
273274
panic("syntax error: rule no more token");
274275
}
@@ -281,7 +282,7 @@ static Zoneinfo parse(String fname) {
281282
RuleRec rrec = RuleRec.parse(tokens);
282283
rrec.setLine(line);
283284
rule.add(rrec);
284-
} else if ("Link".equals(token)) {
285+
} else if (token.regionMatches(true, 0, "Link", 0, len)) {
285286
// Link <newname> <oldname>
286287
try {
287288
String name1 = tokens.nextToken();

0 commit comments

Comments
 (0)