--- old/make/jdk/src/classes/build/tools/cldrconverter/LDMLParseHandler.java 2018-12-03 17:32:39.271293568 +0530 +++ new/make/jdk/src/classes/build/tools/cldrconverter/LDMLParseHandler.java 2018-12-03 17:32:38.991293568 +0530 @@ -52,6 +52,8 @@ private final String id; private String currentContext = ""; // "format"/"stand-alone" private String currentWidth = ""; // "wide"/"narrow"/"abbreviated" + private String currentStyle = ""; // short, long for decimalFormat + private String compactCount = ""; // one or other for decimalFormat LDMLParseHandler(String id) { this.id = id; @@ -503,13 +505,85 @@ // Number format information // case "decimalFormatLength": - if (attributes.getValue("type") == null) { - // skipping type="short" data - // for FormatData - // copy string for later assembly into NumberPatterns + String type = attributes.getValue("type"); + if (null == type) { + // format data for decimal number format pushStringEntry(qName, attributes, "NumberPatterns/decimal"); + currentStyle = type; } else { - pushIgnoredContainer(qName); + switch (type) { + case "short": + case "long": + // considering "short" and long for + // compact number formatting patterns + pushKeyContainer(qName, attributes, type); + currentStyle = type; + break; + default: + pushIgnoredContainer(qName); + break; + } + } + break; + case "decimalFormat": + if(currentStyle == null) { + pushContainer(qName, attributes); + } else { + switch (currentStyle) { + case "short": + pushStringListEntry(qName, attributes, + currentStyle+".CompactNumberPatterns"); + break; + case "long": + pushStringListEntry(qName, attributes, + currentStyle+".CompactNumberPatterns"); + break; + default: + pushIgnoredContainer(qName); + break; + } + } + break; + case "pattern": + String containerName = currentContainer.getqName(); + if (containerName.equals("decimalFormat")) { + if (currentStyle == null) { + pushContainer(qName, attributes); + } else { + // The compact number patterns parsing assumes that the order + // of patterns are always in the increasing order of their + // type attribute i.e. type = 1000... + // Between the inflectional forms for a type (e.g. + // count = "one" and count = "other" for type = 1000), it is + // assumed that the count = "one" always appears before + // count = "other" + switch (currentStyle) { + case "short": + case "long": + String count = attributes.getValue("count"); + // first pattern of count = "one" or count = "other" + if ((count.equals("one") || count.equals("other")) + && compactCount.equals("")) { + compactCount = count; + pushStringListElement(qName, attributes, + (int) Math.log10(Double.parseDouble(attributes.getValue("type")))); + } else if ((count.equals("one") || count.equals("other")) + && compactCount.equals(count)) { + // extract patterns with similar "count" + // attribute value + pushStringListElement(qName, attributes, + (int) Math.log10(Double.parseDouble(attributes.getValue("type")))); + } else { + pushIgnoredContainer(qName); + } + break; + default: + pushIgnoredContainer(qName); + break; + } + } + } else { + pushContainer(qName, attributes); } break; case "currencyFormatLength": @@ -676,10 +750,9 @@ // "alias" for root case "alias": { - if (id.equals("root") && - !isIgnored(attributes) && - currentCalendarType != null && - !currentCalendarType.lname().startsWith("islamic-")) { // ignore Islamic variants + if (id.equals("root") && !isIgnored(attributes) + && ((currentContainer.getqName().equals("decimalFormatLength")) + || (currentCalendarType != null && !currentCalendarType.lname().startsWith("islamic-")))) { // ignore islamic variants pushAliasEntry(qName, attributes, attributes.getValue("path")); } else { pushIgnoredContainer(qName); @@ -831,6 +904,9 @@ case "dayPeriods": case "eras": break; + case "decimalFormatLength": // used for compact number formatting patterns + keyName = type + ".CompactNumberPatterns"; + break; default: keyName = ""; break; @@ -868,6 +944,14 @@ if (start != -1) { width = path.substring(start+typeKey.length(), path.indexOf("']", start)); } + + // used for compact number formatting patterns aliases + typeKey = "decimalFormatLength[@type='"; + start = path.indexOf(typeKey); + if (start != -1) { + String style = path.substring(start + typeKey.length(), path.indexOf("']", start)); + return toJDKKey(qName, "", style); + } return calType + "." + toJDKKey(qName, context, width); } @@ -926,7 +1010,11 @@ currentContext = ""; putIfEntry(); break; - + case "decimalFormatLength": + currentStyle = ""; + compactCount = ""; + putIfEntry(); + break; default: putIfEntry(); } @@ -937,22 +1025,28 @@ if (currentContainer instanceof AliasEntry) { Entry entry = (Entry) currentContainer; String containerqName = entry.getParent().getqName(); - Set keyNames = populateAliasKeys(containerqName, currentContext, currentWidth); - if (!keyNames.isEmpty()) { - for (String keyName : keyNames) { - String[] tmp = keyName.split(",", 3); - String calType = currentCalendarType.lname(); - String src = calType+"."+tmp[0]; - String target = getTarget( - entry.getKey(), - calType, - tmp[1].length()>0 ? tmp[1] : currentContext, - tmp[2].length()>0 ? tmp[2] : currentWidth); - if (target.substring(target.lastIndexOf('.')+1).equals(containerqName)) { - target = target.substring(0, target.indexOf('.'))+"."+tmp[0]; + if (containerqName.equals("decimalFormatLength")) { + String srcKey = toJDKKey(containerqName, "", currentStyle); + String targetKey = getTarget(entry.getKey(), "", "", ""); + CLDRConverter.aliases.put(srcKey, targetKey); + } else { + Set keyNames = populateAliasKeys(containerqName, currentContext, currentWidth); + if (!keyNames.isEmpty()) { + for (String keyName : keyNames) { + String[] tmp = keyName.split(",", 3); + String calType = currentCalendarType.lname(); + String src = calType+"."+tmp[0]; + String target = getTarget( + entry.getKey(), + calType, + tmp[1].length()>0 ? tmp[1] : currentContext, + tmp[2].length()>0 ? tmp[2] : currentWidth); + if (target.substring(target.lastIndexOf('.')+1).equals(containerqName)) { + target = target.substring(0, target.indexOf('.'))+"."+tmp[0]; + } + CLDRConverter.aliases.put(src.replaceFirst("^gregorian.", ""), + target.replaceFirst("^gregorian.", "")); } - CLDRConverter.aliases.put(src.replaceFirst("^gregorian.", ""), - target.replaceFirst("^gregorian.", "")); } } } else if (currentContainer instanceof Entry) {