• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.test;
2 
3 import java.util.List;
4 
5 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
6 
7 import com.ibm.icu.lang.UCharacter;
8 
9 public class CheckCurrencies extends CheckCLDR {
10     // remember to add this class to the list in CheckCLDR.getCheckAll
11     // to run just this test, on just locales starting with 'nl', use CheckCLDR with -fnl.* -t.*Currencies.*
12 
13     // If you don't need any file initialization or postprocessing, you only need this one routine
14     @Override
handleCheck(String path, String fullPath, String value, Options options, List<CheckStatus> result)15     public CheckCLDR handleCheck(String path, String fullPath, String value, Options options,
16         List<CheckStatus> result) {
17         // it helps performance to have a quick reject of most paths
18         if (fullPath == null) return this; // skip paths that we don't have
19         if (path.indexOf("/currency") < 0 || path.indexOf("/symbol") < 0) return this;
20 
21         // parts.set(path); // normally you have to parse out a path to get the exact one, but in this case the quick
22         // reject suffices
23 
24         // we're simply going to test the length. might do something more complicated later
25         if (value != null && value.length() > 5) {
26             // The following test no longer applies, choice format is not used for INR
27             // if (path.indexOf("[@type=\"INR\"]") >= 0) { // skip INR, since it is typically a choice (could do more
28             // sophisticated check later)
29             // return this;
30             // }
31             if (!getCldrFileToCheck().getSourceLocaleID(path, null).equals(getCldrFileToCheck().getLocaleID())) { // skip
32                 // if
33                 // inherited
34                 // --
35                 // we
36                 // only
37                 // need
38                 // parent
39                 // instance
40                 return this;
41             }
42             // Don't include Cf format chars in length test
43             int adjustedLength = value.length();
44             for (int idx = 0; idx < value.length(); idx++) {
45                 if (UCharacter.getType(value.charAt(idx)) == UCharacter.FORMAT) {
46                     if (--adjustedLength <= 5) {
47                         return this;
48                     }
49                 }
50             }
51 
52             // the following is how you signal an error or warning (or add a demo....)
53             result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.warningType)
54                 .setSubtype(Subtype.currencySymbolTooWide) // typically warningType or errorType
55                 .setMessage("Currency symbol length > 5")); // the message; can be MessageFormat with arguments
56         }
57         return this;
58     }
59 }
60