use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class IntlDataTools method collationCase.
static void collationCase(Path cldr) throws IOException {
Files.walk(cldr.resolve("collation")).filter(Files::isRegularFile).forEach(p -> {
try (Reader reader = Files.newBufferedReader(p, StandardCharsets.UTF_8)) {
Document document = document(reader);
elementsByTagName(document, "collation").filter(e -> "standard".equals(e.getAttribute("type"))).forEach(e -> {
elementByTagName(e, "cr").ifPresent(cr -> {
String text = cr.getTextContent();
if (text.contains("caseFirst")) {
System.out.println(p.getFileName());
}
});
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
for (ULocale locale : Collator.getAvailableULocales()) {
Collator collator = Collator.getInstance(locale);
if (collator instanceof RuleBasedCollator) {
RuleBasedCollator ruleBasedCollator = (RuleBasedCollator) collator;
if (ruleBasedCollator.isUpperCaseFirst()) {
System.out.printf("upper-first = %s%n", locale);
} else if (ruleBasedCollator.isLowerCaseFirst()) {
System.out.printf("lower-first = %s%n", locale);
}
}
}
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class LanguageData method addDerivedLanguages.
private static Set<String> addDerivedLanguages(List<String> available) {
HashSet<String> availableSet = new HashSet<>(available);
HashSet<String> derivedSet = new HashSet<>(available);
for (ULocale locale : ULocale.getAvailableLocales()) {
String languageTag = locale.toLanguageTag();
if (derivedSet.contains(languageTag)) {
continue;
}
if (!(locale.getVariant().isEmpty() && locale.getUnicodeLocaleKeys().isEmpty())) {
// Ignore locales with variants or unicode extension sequences.
continue;
}
String language = locale.getLanguage();
if (availableSet.contains(language)) {
derivedSet.add(languageTag);
continue;
}
String script = locale.getScript();
if (!script.isEmpty()) {
String languageScript = language + "-" + script;
if (availableSet.contains(languageScript)) {
derivedSet.add(languageTag);
continue;
}
}
String country = locale.getCountry();
if (!country.isEmpty()) {
String languageCountry = language + "-" + country;
if (availableSet.contains(languageCountry)) {
derivedSet.add(languageTag);
continue;
}
}
}
return derivedSet;
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class ListFormatObject method createListFormatter.
@SuppressWarnings("deprecation")
private ListFormatter createListFormatter() {
ULocale locale = ULocale.forLanguageTag(this.locale);
ICUResourceBundle r = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
String resourceStyle = resourceStyle();
return new ListFormatter(r.getWithFallback("listPattern/" + resourceStyle + "/2").getString(), r.getWithFallback("listPattern/" + resourceStyle + "/start").getString(), r.getWithFallback("listPattern/" + resourceStyle + "/middle").getString(), r.getWithFallback("listPattern/" + resourceStyle + "/end").getString());
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class PluralRulesObject method createNumberFormat.
private NumberFormat createNumberFormat() {
ULocale locale = ULocale.forLanguageTag(this.locale);
locale = locale.setKeywordValue("numbers", "latn");
DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, NumberFormat.NUMBERSTYLE);
if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) {
numberFormat.setSignificantDigitsUsed(true);
numberFormat.setMinimumSignificantDigits(minimumSignificantDigits);
numberFormat.setMaximumSignificantDigits(maximumSignificantDigits);
} else {
numberFormat.setSignificantDigitsUsed(false);
numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
numberFormat.setMinimumFractionDigits(minimumFractionDigits);
numberFormat.setMaximumFractionDigits(maximumFractionDigits);
}
// as required by ToRawPrecision/ToRawFixed
numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP);
return numberFormat;
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class CollatorObject method createCollator.
private Collator createCollator() {
ULocale locale = ULocale.forLanguageTag(this.locale);
if ("search".equals(usage)) {
// "search" usage cannot be set through unicode extensions (u-co-search), handle here:
locale = locale.setKeywordValue("collation", "search");
}
RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(locale);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
collator.setNumericCollation(numeric);
switch(caseFirst) {
case "upper":
collator.setUpperCaseFirst(true);
break;
case "lower":
collator.setLowerCaseFirst(true);
break;
case "false":
if (collator.isLowerCaseFirst()) {
collator.setLowerCaseFirst(false);
}
if (collator.isUpperCaseFirst()) {
collator.setUpperCaseFirst(false);
}
break;
default:
throw new AssertionError();
}
switch(sensitivity) {
case "base":
collator.setStrength(Collator.PRIMARY);
break;
case "accent":
collator.setStrength(Collator.SECONDARY);
break;
case "case":
collator.setStrength(Collator.PRIMARY);
collator.setCaseLevel(true);
break;
case "variant":
collator.setStrength(Collator.TERTIARY);
break;
default:
throw new AssertionError();
}
collator.setAlternateHandlingShifted(ignorePunctuation);
return collator;
}
Aggregations