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