• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.test;
2 
3 import java.util.List;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6 
7 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
8 import org.unicode.cldr.util.PatternCache;
9 
10 import com.ibm.icu.text.UnicodeSet;
11 
12 public class CheckQuotes extends CheckCLDR {
13     private static final Pattern ASCII_QUOTES = PatternCache.get("[\'\"]");
14     private static final Pattern UNITS = PatternCache.get("//ldml/units/.*");
15     private static final Pattern DELIMITERS = PatternCache.get("//ldml/delimiters/.*");
16     private static final UnicodeSet VALID_DELIMITERS = new UnicodeSet()
17         .add(0x2018, 0x201A)
18         .add(0x201C, 0x201E)
19         .add(0x300C, 0x300F)
20         .add(0x2039, 0x203A)
21         .add(0x00AB)
22         .add(0x00BB);
23 
24     @Override
handleCheck(String path, String fullPath, String value, Options options, List<CheckStatus> result)25     public CheckCLDR handleCheck(String path, String fullPath, String value, Options options,
26         List<CheckStatus> result) {
27         if (value == null) {
28             return this;
29         }
30 
31         if (UNITS.matcher(path).matches()) {
32             Matcher matcher = ASCII_QUOTES.matcher(value);
33             CheckStatus.Type type = CheckStatus.warningType;
34             if (this.getCldrFileToCheck().getLocaleID().equals("en")) {
35                 type = CheckStatus.errorType;
36             }
37             if (matcher.find()) {
38                 result.add(new CheckStatus().setCause(this)
39                     .setMainType(type)
40                     .setSubtype(Subtype.asciiQuotesNotAllowed)
41                     .setMessage("Use of ASCII quote marks (' \") is discouraged. Use primes for units (′ ″) and curly quotes for text (‘ ’ “ ” …)"));
42             }
43         }
44         if (DELIMITERS.matcher(path).matches()) {
45             if (!VALID_DELIMITERS.contains(value)) {
46                 result.add(new CheckStatus().setCause(this)
47                     .setMainType(CheckStatus.errorType)
48                     .setSubtype(Subtype.invalidDelimiter)
49                     .setMessage("Invalid delimiter. See https://sites.google.com/site/cldr/translation/characters for a list of valid delimiters."));
50             }
51         }
52 
53         return this;
54     }
55 
56 }
57