private String TitleCaseFirst(ULocale locale, String value) { if (value.length() == 0) { return value; } breaker.setText(value); breaker.first(); int endOfFirstWord = breaker.next(); return UCharacter.toTitleCase(uLocale, value.substring(0, endOfFirstWord), breaker) + value.substring(endOfFirstWord); }
// If you don't need any file initialization or postprocessing, you only need this one routine public CheckCLDR handleCheck( String path, String fullPath, String value, Options options, List<CheckStatus> result) { // it helps performance to have a quick reject of most paths if (fullPath == null) return this; // skip paths that we don't have if (fullPath.indexOf("casing") < 0) return this; // pick up the casing attributes from the full path parts.set(fullPath); Case caseTest = Case.mixed; for (int i = 0; i < parts.size(); ++i) { String casingValue = parts.getAttributeValue(i, "casing"); if (casingValue == null) { continue; } caseTest = Case.forString(casingValue); if (caseTest == Case.verbatim) { return this; // we're done } } String newValue = value; switch (caseTest) { case lowercase_words: newValue = UCharacter.toLowerCase(uLocale, value); break; case titlecase_words: newValue = UCharacter.toTitleCase(uLocale, value, null); break; case titlecase_firstword: newValue = TitleCaseFirst(uLocale, value); break; default: break; } if (!newValue.equals(value)) { // the following is how you signal an error or warning (or add a demo....) result.add( new CheckStatus() .setCause(this) .setMainType(CheckStatus.errorType) .setSubtype(Subtype.incorrectCasing) // typically warningType or errorType .setMessage( "Casing incorrect: either should have casing=\"verbatim\" or be <{0}>", new Object[] {newValue})); // the message; can be MessageFormat with arguments } return this; }