Search in sources :

Example 6 with Collator

use of com.ibm.icu.text.Collator 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);
            }
        }
    }
}
Also used : TimeZone(com.ibm.icu.util.TimeZone) java.util(java.util) Function(java.util.function.Function) DirectoryStream(java.nio.file.DirectoryStream) Matcher(java.util.regex.Matcher) ULocale(com.ibm.icu.util.ULocale) Document(org.w3c.dom.Document) StreamSupport(java.util.stream.StreamSupport) Collator(com.ibm.icu.text.Collator) Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) NodeList(org.w3c.dom.NodeList) Files(java.nio.file.Files) SystemTimeZoneType(com.ibm.icu.util.TimeZone.SystemTimeZoneType) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) Pattern(java.util.regex.Pattern) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) ULocale(com.ibm.icu.util.ULocale) Reader(java.io.Reader) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Document(org.w3c.dom.Document) Collator(com.ibm.icu.text.Collator) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator)

Aggregations

Collator (com.ibm.icu.text.Collator)6 RuleBasedCollator (com.ibm.icu.text.RuleBasedCollator)3 ULocale (com.ibm.icu.util.ULocale)2 Pattern (java.util.regex.Pattern)2 TimeZone (com.ibm.icu.util.TimeZone)1 SystemTimeZoneType (com.ibm.icu.util.TimeZone.SystemTimeZoneType)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 UncheckedIOException (java.io.UncheckedIOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 DirectoryStream (java.nio.file.DirectoryStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Function (java.util.function.Function)1 Matcher (java.util.regex.Matcher)1