Skip to content

Commit d0be73a

Browse files
committedSep 11, 2023
8041488: Locale-Dependent List Patterns
Reviewed-by: joehw, rriggs
1 parent dd214d0 commit d0be73a

File tree

7 files changed

+1019
-8
lines changed

7 files changed

+1019
-8
lines changed
 

‎make/jdk/src/classes/build/tools/cldrconverter/Bundle.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, 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
@@ -108,6 +108,12 @@ static enum Type {
108108
"narrow.Eras"
109109
};
110110

111+
static final String[] LIST_PATTERN_KEYS = {
112+
"ListPatterns_standard",
113+
"ListPatterns_or",
114+
"ListPatterns_unit",
115+
};
116+
111117
// DateFormatItem prefix
112118
static final String DATEFORMATITEM_KEY_PREFIX = "DateFormatItem.";
113119
static final String DATEFORMATITEM_INPUT_REGIONS_PREFIX = "DateFormatItemInputRegions.";

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,14 @@ private static void convertBundles(List<Bundle> bundles) throws Exception {
621621
*/
622622
static void handleAliases(Map<String, Object> bundleMap) {
623623
for (String key : aliases.keySet()) {
624-
var source = bundleMap.get(aliases.get(key));
624+
var sourceKey = aliases.get(key);
625+
if (key.startsWith("ListPatterns_")) {
626+
String k;
627+
while ((k = aliases.get(sourceKey)) != null) {
628+
sourceKey = k;
629+
}
630+
}
631+
var source = bundleMap.get(sourceKey);
625632
if (source != null) {
626633
if (bundleMap.get(key) instanceof String[] sa) {
627634
// fill missing elements in case of String array
@@ -871,6 +878,7 @@ private static Map<String, Object> extractCalendarData(Map<String, Object> map,
871878
"DayPeriodRules",
872879
"DateFormatItemInputRegions.allowed",
873880
"DateFormatItemInputRegions.preferred",
881+
"ListPatterns",
874882
};
875883

876884
static final Set<String> availableSkeletons = new HashSet<>();
@@ -935,6 +943,14 @@ private static Map<String, Object> extractFormatData(Map<String, Object> map, St
935943
formatData.put(k + ".NumberElements", neNew);
936944
});
937945
}
946+
947+
// ListPatterns
948+
for (var lpKey : Bundle.LIST_PATTERN_KEYS) {
949+
copyIfPresent(map, lpKey, formatData);
950+
copyIfPresent(map, lpKey + "-short", formatData);
951+
copyIfPresent(map, lpKey + "-narrow", formatData);
952+
}
953+
938954
return formatData;
939955
}
940956

‎make/jdk/src/classes/build/tools/cldrconverter/LDMLParseHandler.java

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, 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
@@ -35,6 +35,7 @@
3535
import java.util.List;
3636
import java.util.Locale;
3737
import java.util.Map;
38+
import java.util.Optional;
3839
import java.util.Set;
3940
import org.xml.sax.Attributes;
4041
import org.xml.sax.InputSource;
@@ -812,6 +813,7 @@ public void startElement(String uri, String localName, String qName, Attributes
812813
&& ((currentContainer.getqName().equals("decimalFormatLength"))
813814
|| (currentContainer.getqName().equals("currencyFormat"))
814815
|| (currentContainer.getqName().equals("percentFormat"))
816+
|| (currentContainer.getqName().equals("listPattern"))
815817
|| (currentCalendarType != null && !currentCalendarType.lname().startsWith("islamic-")))) { // ignore islamic variants
816818
pushAliasEntry(qName, attributes, attributes.getValue("path"));
817819
} else {
@@ -820,6 +822,28 @@ public void startElement(String uri, String localName, String qName, Attributes
820822
}
821823
break;
822824

825+
// ListPatterns
826+
case "listPattern":
827+
currentStyle = Optional.ofNullable(attributes.getValue("type")).orElse("standard");
828+
pushStringArrayEntry(qName, attributes, "ListPatterns_" + currentStyle, 5);
829+
break;
830+
case "listPatternPart":
831+
type = attributes.getValue("type");
832+
pushStringArrayElement(qName, attributes,
833+
switch (type) {
834+
case "start" -> 0;
835+
case "middle" -> 1;
836+
case "end" -> 2;
837+
case "2" -> 3;
838+
case "3" -> 4;
839+
default -> throw new IllegalArgumentException(
840+
"""
841+
The "type" attribute value for "listPatternPart" element is not recognized: %s
842+
""".formatted(type)
843+
);
844+
});
845+
break;
846+
823847
default:
824848
// treat anything else as a container
825849
pushContainer(qName, attributes);
@@ -973,6 +997,9 @@ private String toJDKKey(String containerqName, String context, String type) {
973997
"NumberPatterns/" +
974998
(type.equals("standard") ? containerqName.replaceFirst("Format", "") : type);
975999
break;
1000+
case "listPattern":
1001+
keyName = type;
1002+
break;
9761003
default:
9771004
keyName = "";
9781005
break;
@@ -1035,6 +1062,19 @@ private String getTarget(String path, String calType, String context, String wid
10351062
return toJDKKey(qName, "", style);
10361063
}
10371064

1065+
// listPattern
1066+
if (path.indexOf("../listPattern") != -1) {
1067+
typeKey = "[@type='";
1068+
start = path.indexOf(typeKey);
1069+
String style;
1070+
if (start != -1) {
1071+
style = "ListPatterns_" + path.substring(start + typeKey.length(), path.indexOf("']", start));
1072+
} else {
1073+
style = "ListPatterns_standard";
1074+
}
1075+
return toJDKKey(qName, "", style);
1076+
}
1077+
10381078
return calType + "." + toJDKKey(qName, context, width);
10391079
}
10401080

@@ -1107,6 +1147,10 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
11071147
case "timeFormatLength":
11081148
currentStyle = "";
11091149
break;
1150+
case "listPattern":
1151+
currentStyle = "";
1152+
putIfEntry();
1153+
break;
11101154
default:
11111155
putIfEntry();
11121156
}
@@ -1128,6 +1172,12 @@ private Object putIfEntry() {
11281172
toJDKKey(containerqName, "", kc.getKey()),
11291173
getTarget(entry.getKey(), "", "", "")
11301174
);
1175+
} else if (containerqName.equals("listPattern")) {
1176+
var sae = (StringArrayEntry)entry.getParent();
1177+
CLDRConverter.aliases.put(
1178+
toJDKKey(containerqName, "", sae.getKey()),
1179+
getTarget(entry.getKey(), "", "", "")
1180+
);
11311181
} else {
11321182
Set<String> keyNames = populateAliasKeys(containerqName, currentContext, currentWidth);
11331183
if (!keyNames.isEmpty()) {

‎src/java.base/share/classes/java/text/Format.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2023, 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
@@ -42,7 +42,7 @@
4242

4343
/**
4444
* {@code Format} is an abstract base class for formatting locale-sensitive
45-
* information such as dates, messages, and numbers.
45+
* information such as dates, messages, numbers, and lists.
4646
*
4747
* <p>
4848
* {@code Format} defines the programming interface for formatting
@@ -61,9 +61,9 @@
6161
* <h2>Subclassing</h2>
6262
*
6363
* <p>
64-
* The Java Platform provides three specialized subclasses of {@code Format}--
65-
* {@code DateFormat}, {@code MessageFormat}, and
66-
* {@code NumberFormat}--for formatting dates, messages, and numbers,
64+
* The Java Platform provides specialized subclasses of {@code Format}--
65+
* {@code DateFormat}, {@code MessageFormat}, {@code NumberFormat}, and
66+
* {@code ListFormat}--for formatting dates, messages, numbers, and lists
6767
* respectively.
6868
* <p>
6969
* Concrete subclasses must implement three methods:
@@ -128,6 +128,7 @@
128128
* @see java.text.NumberFormat
129129
* @see java.text.DateFormat
130130
* @see java.text.MessageFormat
131+
* @see java.text.ListFormat
131132
* @author Mark Davis
132133
* @since 1.1
133134
*/

0 commit comments

Comments
 (0)
Please sign in to comment.