- UBool titlecase = FALSE;
- switch (capitalizationContext) {
- case UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE:
- titlecase = TRUE;
- break;
- case UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU:
- titlecase = fCapitalization[usage][0];
- break;
- case UDISPCTX_CAPITALIZATION_FOR_STANDALONE:
- titlecase = fCapitalization[usage][1];
- break;
- default:
- // titlecase = FALSE;
- break;
- }
- if (titlecase) {
- // TODO: Fix this titlecase hack when we figure out something better to do.
- // We don't want to titlecase the whole text, only something like the first word,
- // of the first segment long enough to have a complete cluster, whichever is
- // shorter. We could have keep a word break iterator around, but I am not sure
- // that will do the ight thing for the purposes here. For now we assume that in
- // languages for which titlecasing makes a difference, we can stop at non-letter
- // characters in 0x0000-0x00FF and only titlecase up to the first occurrence of
- // any of those, or to a small number of chars, whichever comes first.
- int32_t stopPos, stopPosLimit = 8, len = result.length();
- if ( stopPosLimit > len ) {
- stopPosLimit = len;
- }
- for ( stopPos = 0; stopPos < stopPosLimit; stopPos++ ) {
- UChar32 ch = result.char32At(stopPos);
- if ( (ch < 0x41) || (ch > 0x5A && ch < 0x61) || (ch > 0x7A && ch < 0xC0) ) {
- break;
- }
- if (ch >= 0x10000) {
- stopPos++;
- }
- }
- if ( stopPos > 0 && stopPos < len ) {
- UnicodeString firstWord(result, 0, stopPos);
- firstWord.toTitle(NULL, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
- result.replaceBetween(0, stopPos, firstWord);
- } else {
- // no stopPos, titlecase the whole text
- result.toTitle(NULL, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
- }
+ if ( result.length() > 0 && u_islower(result.char32At(0)) && capitalizationBrkIter!= NULL &&
+ ( capitalizationContext==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE || fCapitalization[usage] ) ) {
+ // note fCapitalization[usage] won't be set unless capitalizationContext is UI_LIST_OR_MENU or STANDALONE
+ result.toTitle(capitalizationBrkIter, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);