8339803: Acknowledge case insensitive unambiguous keywords in tzdata files
Reviewed-by: jlu, coffeys
This commit is contained in:
parent
51b85a1f69
commit
35a94b7697
@ -1372,6 +1372,7 @@ public class CLDRConverter {
|
||||
private static void generateTZDBShortNamesMap() throws IOException {
|
||||
Files.walk(Path.of(tzDataDir), 1, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(p -> p.toFile().isFile())
|
||||
.filter(p -> p.getFileName().toString().matches("africa|antarctica|asia|australasia|backward|etcetera|europe|northamerica|southamerica"))
|
||||
.forEach(p -> {
|
||||
try {
|
||||
String zone = null;
|
||||
@ -1394,43 +1395,41 @@ public class CLDRConverter {
|
||||
}
|
||||
// remove comments in-line
|
||||
line = line.replaceAll("[ \t]*#.*", "");
|
||||
|
||||
var tokens = line.split("[ \t]+", -1);
|
||||
var token0len = tokens.length > 0 ? tokens[0].length() : 0;
|
||||
// Zone line
|
||||
if (line.startsWith("Zone")) {
|
||||
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Zone", 0, token0len)) {
|
||||
if (zone != null) {
|
||||
tzdbShortNamesMap.put(zone, format + NBSP + rule);
|
||||
}
|
||||
var zl = line.split("[ \t]+", -1);
|
||||
zone = zl[1];
|
||||
rule = zl[3];
|
||||
format = flipIfNeeded(inVanguard, zl[4]);
|
||||
zone = tokens[1];
|
||||
rule = tokens[3];
|
||||
format = flipIfNeeded(inVanguard, tokens[4]);
|
||||
} else {
|
||||
if (zone != null) {
|
||||
if (line.startsWith("Rule") ||
|
||||
line.startsWith("Link")) {
|
||||
if (token0len > 0 &&
|
||||
(tokens[0].regionMatches(true, 0, "Rule", 0, token0len) ||
|
||||
tokens[0].regionMatches(true, 0, "Link", 0, token0len))) {
|
||||
tzdbShortNamesMap.put(zone, format + NBSP + rule);
|
||||
zone = null;
|
||||
rule = null;
|
||||
format = null;
|
||||
} else {
|
||||
var s = line.split("[ \t]+", -1);
|
||||
rule = s[2];
|
||||
format = flipIfNeeded(inVanguard, s[3]);
|
||||
rule = tokens[2];
|
||||
format = flipIfNeeded(inVanguard, tokens[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rule line
|
||||
if (line.startsWith("Rule")) {
|
||||
var rl = line.split("[ \t]+", -1);
|
||||
tzdbSubstLetters.put(rl[1] + NBSP + (rl[8].equals("0") ? STD : DST),
|
||||
rl[9].replace(NO_SUBST, ""));
|
||||
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Rule", 0, token0len)) {
|
||||
tzdbSubstLetters.put(tokens[1] + NBSP + (tokens[8].equals("0") ? STD : DST),
|
||||
tokens[9].replace(NO_SUBST, ""));
|
||||
}
|
||||
|
||||
// Link line
|
||||
if (line.startsWith("Link")) {
|
||||
var ll = line.split("[ \t]+", -1);
|
||||
tzdbLinks.put(ll[2], ll[1]);
|
||||
if (token0len > 0 && tokens[0].regionMatches(true, 0, "Link", 0, token0len)) {
|
||||
tzdbLinks.put(tokens[2], tokens[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,8 @@ class TzdbZoneRulesProvider {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("Zone")) { // parse Zone line
|
||||
int token0len = tokens.length > 0 ? tokens[0].length() : line.length();
|
||||
if (line.regionMatches(true, 0, "Zone", 0, token0len)) { // parse Zone line
|
||||
String name = tokens[1];
|
||||
if (excludedZones.contains(name)){
|
||||
continue;
|
||||
@ -182,13 +183,13 @@ class TzdbZoneRulesProvider {
|
||||
if (zLine.parse(tokens, 2)) {
|
||||
openZone = null;
|
||||
}
|
||||
} else if (line.startsWith("Rule")) { // parse Rule line
|
||||
} else if (line.regionMatches(true, 0, "Rule", 0, token0len)) { // parse Rule line
|
||||
String name = tokens[1];
|
||||
if (!rules.containsKey(name)) {
|
||||
rules.put(name, new ArrayList<RuleLine>(10));
|
||||
}
|
||||
rules.get(name).add(new RuleLine().parse(tokens));
|
||||
} else if (line.startsWith("Link")) { // parse link line
|
||||
} else if (line.regionMatches(true, 0, "Link", 0, token0len)) { // parse link line
|
||||
if (tokens.length >= 3) {
|
||||
String realId = tokens[1];
|
||||
String aliasId = tokens[2];
|
||||
@ -304,7 +305,7 @@ class TzdbZoneRulesProvider {
|
||||
month = parseMonth(tokens[off++]);
|
||||
if (off < tokens.length) {
|
||||
String dayRule = tokens[off++];
|
||||
if (dayRule.startsWith("last")) {
|
||||
if (dayRule.regionMatches(true, 0, "last", 0, 4)) {
|
||||
dayOfMonth = -1;
|
||||
dayOfWeek = parseDayOfWeek(dayRule.substring(4));
|
||||
adjustForwards = false;
|
||||
@ -355,11 +356,12 @@ class TzdbZoneRulesProvider {
|
||||
}
|
||||
|
||||
int parseYear(String year, int defaultYear) {
|
||||
switch (year.toLowerCase()) {
|
||||
case "min": return 1900;
|
||||
case "max": return Year.MAX_VALUE;
|
||||
case "only": return defaultYear;
|
||||
}
|
||||
int len = year.length();
|
||||
|
||||
if (year.regionMatches(true, 0, "minimum", 0, len)) return 1900;
|
||||
if (year.regionMatches(true, 0, "maximum", 0, len)) return Year.MAX_VALUE;
|
||||
if (year.regionMatches(true, 0, "only", 0, len)) return defaultYear;
|
||||
|
||||
return Integer.parseInt(year);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -168,12 +168,13 @@ class RuleRec {
|
||||
rec.toYear = Integer.parseInt(token);
|
||||
} catch (NumberFormatException e) {
|
||||
// it's not integer
|
||||
if ("min".equals(token) || "minimum".equals(token)) {
|
||||
int len = token.length();
|
||||
if (token.regionMatches(true, 0, "minimum", 0, len)) {
|
||||
rec.fromYear = Zoneinfo.getMinYear();
|
||||
} else if ("max".equals(token) || "maximum".equals(token)) {
|
||||
} else if (token.regionMatches(true, 0, "maximum", 0, len)) {
|
||||
rec.toYear = Integer.MAX_VALUE;
|
||||
rec.isLastRule = true;
|
||||
} else if ("only".equals(token)) {
|
||||
} else if (token.regionMatches(true, 0, "only", 0, len)) {
|
||||
rec.toYear = rec.fromYear;
|
||||
} else {
|
||||
Main.panic("invalid year value: "+token);
|
||||
|
@ -240,8 +240,9 @@ class Zoneinfo {
|
||||
continue;
|
||||
}
|
||||
String token = tokens.nextToken();
|
||||
int len = token.length();
|
||||
|
||||
if (continued || "Zone".equals(token)) {
|
||||
if (continued || token.regionMatches(true, 0, "Zone", 0, len)){
|
||||
if (zone == null) {
|
||||
if (!tokens.hasMoreTokens()) {
|
||||
panic("syntax error: zone no more token");
|
||||
@ -268,7 +269,7 @@ class Zoneinfo {
|
||||
}
|
||||
zone = null;
|
||||
}
|
||||
} else if ("Rule".equals(token)) {
|
||||
} else if (token.regionMatches(true, 0, "Rule", 0, len)) {
|
||||
if (!tokens.hasMoreTokens()) {
|
||||
panic("syntax error: rule no more token");
|
||||
}
|
||||
@ -281,7 +282,7 @@ class Zoneinfo {
|
||||
RuleRec rrec = RuleRec.parse(tokens);
|
||||
rrec.setLine(line);
|
||||
rule.add(rrec);
|
||||
} else if ("Link".equals(token)) {
|
||||
} else if (token.regionMatches(true, 0, "Link", 0, len)) {
|
||||
// Link <newname> <oldname>
|
||||
try {
|
||||
String name1 = tokens.nextToken();
|
||||
|
Loading…
Reference in New Issue
Block a user