Skip to content

Commit 2273ff9

Browse files
johnyjose30Paul Hohensee
authored andcommitted
8339803: Acknowledge case insensitive unambiguous keywords in tzdata files
Backport-of: 35a94b7
1 parent f9c82e4 commit 2273ff9

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,7 @@ private static Map<Locale, String> coverageLevelsMap() throws Exception {
13751375
private static void generateTZDBShortNamesMap() throws IOException {
13761376
Files.walk(Path.of(tzDataDir), 1, FileVisitOption.FOLLOW_LINKS)
13771377
.filter(p -> p.toFile().isFile())
1378+
.filter(p -> p.getFileName().toString().matches("africa|antarctica|asia|australasia|backward|etcetera|europe|northamerica|southamerica"))
13781379
.forEach(p -> {
13791380
try {
13801381
String zone = null;
@@ -1397,43 +1398,41 @@ private static void generateTZDBShortNamesMap() throws IOException {
13971398
}
13981399
// remove comments in-line
13991400
line = line.replaceAll("[ \t]*#.*", "");
1400-
1401+
var tokens = line.split("[ \t]+", -1);
1402+
var token0len = tokens.length > 0 ? tokens[0].length() : 0;
14011403
// Zone line
1402-
if (line.startsWith("Zone")) {
1404+
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Zone", 0, token0len)) {
14031405
if (zone != null) {
14041406
tzdbShortNamesMap.put(zone, format + NBSP + rule);
14051407
}
1406-
var zl = line.split("[ \t]+", -1);
1407-
zone = zl[1];
1408-
rule = zl[3];
1409-
format = flipIfNeeded(inVanguard, zl[4]);
1408+
zone = tokens[1];
1409+
rule = tokens[3];
1410+
format = flipIfNeeded(inVanguard, tokens[4]);
14101411
} else {
14111412
if (zone != null) {
1412-
if (line.startsWith("Rule") ||
1413-
line.startsWith("Link")) {
1413+
if (token0len > 0 &&
1414+
(tokens[0].regionMatches(true, 0, "Rule", 0, token0len) ||
1415+
tokens[0].regionMatches(true, 0, "Link", 0, token0len))) {
14141416
tzdbShortNamesMap.put(zone, format + NBSP + rule);
14151417
zone = null;
14161418
rule = null;
14171419
format = null;
14181420
} else {
1419-
var s = line.split("[ \t]+", -1);
1420-
rule = s[2];
1421-
format = flipIfNeeded(inVanguard, s[3]);
1421+
rule = tokens[2];
1422+
format = flipIfNeeded(inVanguard, tokens[3]);
14221423
}
14231424
}
14241425
}
14251426

14261427
// Rule line
1427-
if (line.startsWith("Rule")) {
1428-
var rl = line.split("[ \t]+", -1);
1429-
tzdbSubstLetters.put(rl[1] + NBSP + (rl[8].equals("0") ? STD : DST),
1430-
rl[9].replace(NO_SUBST, ""));
1428+
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Rule", 0, token0len)) {
1429+
tzdbSubstLetters.put(tokens[1] + NBSP + (tokens[8].equals("0") ? STD : DST),
1430+
tokens[9].replace(NO_SUBST, ""));
14311431
}
14321432

14331433
// Link line
1434-
if (line.startsWith("Link")) {
1435-
var ll = line.split("[ \t]+", -1);
1436-
tzdbLinks.put(ll[2], ll[1]);
1434+
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Link", 0, token0len)) {
1435+
tzdbLinks.put(tokens[2], tokens[1]);
14371436
}
14381437
}
14391438

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

Lines changed: 11 additions & 9 deletions
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 4 additions & 3 deletions
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)