本文整理汇总了Java中com.ibm.icu.lang.UCharacter.toTitleCase方法的典型用法代码示例。如果您正苦于以下问题:Java UCharacter.toTitleCase方法的具体用法?Java UCharacter.toTitleCase怎么用?Java UCharacter.toTitleCase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.lang.UCharacter
的用法示例。
在下文中一共展示了UCharacter.toTitleCase方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjustForContext
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Adjust capitalization of formatted result for display context
*/
private String adjustForContext(String result) {
if (result != null && result.length() > 0 && UCharacter.isLowerCase(result.codePointAt(0))) {
DisplayContext capitalization = getContext(DisplayContext.Type.CAPITALIZATION);
if ( capitalization==DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
(capitalization == DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU && capitalizationForListOrMenu) ||
(capitalization == DisplayContext.CAPITALIZATION_FOR_STANDALONE && capitalizationForStandAlone) ) {
if (capitalizationBrkIter == null) {
// should only happen when deserializing, etc.
capitalizationBrkIter = BreakIterator.getSentenceInstance(locale);
}
return UCharacter.toTitleCase(locale, result, capitalizationBrkIter,
UCharacter.TITLECASE_NO_LOWERCASE | UCharacter.TITLECASE_NO_BREAK_ADJUSTMENT);
}
}
return result;
}
示例2: adjustForUsageAndContext
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
private String adjustForUsageAndContext(CapitalizationContextUsage usage, String name) {
if (name != null && name.length() > 0 && UCharacter.isLowerCase(name.codePointAt(0)) &&
(capitalization==DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
(capitalizationUsage != null && capitalizationUsage[usage.ordinal()]) )) {
// Note, won't have capitalizationUsage != null && capitalizationUsage[usage.ordinal()]
// unless capitalization is CAPITALIZATION_FOR_UI_LIST_OR_MENU or CAPITALIZATION_FOR_STANDALONE
synchronized (this) {
if (capitalizationBrkIter == null) {
// should only happen when deserializing, etc.
capitalizationBrkIter = BreakIterator.getSentenceInstance(locale);
}
return UCharacter.toTitleCase(locale, name, capitalizationBrkIter,
UCharacter.TITLECASE_NO_LOWERCASE | UCharacter.TITLECASE_NO_BREAK_ADJUSTMENT);
}
}
return name;
}
示例3: transform
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
public String transform(final String value) {
if (value == null) {
return null;
}
switch (mode) {
case UPPER_CASE:
return UCharacter.toUpperCase(value);
case LOWER_CASE:
return UCharacter.toLowerCase(value);
case CAPITALIZE_SENTENCES:
return UCharacter.toTitleCase(value, BreakIterator.getSentenceInstance());
case CAPITALIZE_WORDS:
return capitalizeWordsByDictionaries(value);
default:
throw new UnsupportedOperationException("Unsupported mode: " + mode);
}
}
示例4: capitalizeWordsByDictionaries
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
private String capitalizeWordsByDictionaries(final String value) {
final String preparedString = UCharacter.toTitleCase(value, BreakIterator.getWordInstance());
for (final DictionaryConnection allWordsDictionaryConnection : allWordsDictionaryConnections) {
final Iterator<String> lengthSortedValues = allWordsDictionaryConnection.getLengthSortedValues();
while (lengthSortedValues.hasNext()) {
final String candidate = lengthSortedValues.next();
if (candidate.equalsIgnoreCase(value)) {
return candidate;
}
}
}
return getAllWords(preparedString).stream().map(this::capitalizeWordByDictionaries)
.collect(Collectors.joining());
}
示例5: adjustForContext
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
private String adjustForContext(String originalFormattedString) {
if (breakIterator == null || originalFormattedString.length() == 0
|| !UCharacter.isLowerCase(UCharacter.codePointAt(originalFormattedString, 0))) {
return originalFormattedString;
}
synchronized (breakIterator) {
return UCharacter.toTitleCase(
locale,
originalFormattedString,
breakIterator,
UCharacter.TITLECASE_NO_LOWERCASE | UCharacter.TITLECASE_NO_BREAK_ADJUSTMENT);
}
}
示例6: addSourceTargetSet
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
@Override
public void addSourceTargetSet(UnicodeSet inputFilter, UnicodeSet sourceSet, UnicodeSet targetSet) {
synchronized (this) {
if (sourceTargetUtility == null) {
sourceTargetUtility = new SourceTargetUtility(new Transform<String,String>() {
@Override
public String transform(String source) {
return UCharacter.toTitleCase(locale, source, null);
}
});
}
}
sourceTargetUtility.addSourceTargetSet(this, inputFilter, sourceSet, targetSet);
}
示例7: format
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
@Override
public StringBuffer format(Calendar cal, StringBuffer toAppendTo,
FieldPosition fieldPosition) {
String relativeDayString = null;
DisplayContext capitalizationContext = getContext(DisplayContext.Type.CAPITALIZATION);
if (fDateStyle != DateFormat.NONE) {
// calculate the difference, in days, between 'cal' and now.
int dayDiff = dayDifference(cal);
// look up string
relativeDayString = getStringForDay(dayDiff);
}
if (fDateTimeFormat != null) {
if (relativeDayString != null && fDatePattern != null &&
(fTimePattern == null || fCombinedFormat == null || combinedFormatHasDateAtStart) ) {
// capitalize relativeDayString according to context for relative, set formatter no context
if ( relativeDayString.length() > 0 && UCharacter.isLowerCase(relativeDayString.codePointAt(0)) &&
(capitalizationContext == DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
(capitalizationContext == DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU && capitalizationOfRelativeUnitsForListOrMenu) ||
(capitalizationContext == DisplayContext.CAPITALIZATION_FOR_STANDALONE && capitalizationOfRelativeUnitsForStandAlone) )) {
if (capitalizationBrkIter == null) {
// should only happen when deserializing, etc.
capitalizationBrkIter = BreakIterator.getSentenceInstance(fLocale);
}
relativeDayString = UCharacter.toTitleCase(fLocale, relativeDayString, capitalizationBrkIter,
UCharacter.TITLECASE_NO_LOWERCASE | UCharacter.TITLECASE_NO_BREAK_ADJUSTMENT);
}
fDateTimeFormat.setContext(DisplayContext.CAPITALIZATION_NONE);
} else {
// set our context for the formatter
fDateTimeFormat.setContext(capitalizationContext);
}
}
if (fDateTimeFormat != null && (fDatePattern != null || fTimePattern != null)) {
// The new way
if (fDatePattern == null) {
// must have fTimePattern
fDateTimeFormat.applyPattern(fTimePattern);
fDateTimeFormat.format(cal, toAppendTo, fieldPosition);
} else if (fTimePattern == null) {
// must have fDatePattern
if (relativeDayString != null) {
toAppendTo.append(relativeDayString);
} else {
fDateTimeFormat.applyPattern(fDatePattern);
fDateTimeFormat.format(cal, toAppendTo, fieldPosition);
}
} else {
String datePattern = fDatePattern; // default;
if (relativeDayString != null) {
// Need to quote the relativeDayString to make it a legal date pattern
datePattern = "'" + relativeDayString.replace("'", "''") + "'";
}
StringBuffer combinedPattern = new StringBuffer("");
fCombinedFormat.format(new Object[] {fTimePattern, datePattern}, combinedPattern, new FieldPosition(0));
fDateTimeFormat.applyPattern(combinedPattern.toString());
fDateTimeFormat.format(cal, toAppendTo, fieldPosition);
}
} else if (fDateFormat != null) {
// A subset of the old way, for serialization compatibility
// (just do the date part)
if (relativeDayString != null) {
toAppendTo.append(relativeDayString);
} else {
fDateFormat.format(cal, toAppendTo, fieldPosition);
}
}
return toAppendTo;
}
示例8: toTitleCase
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Returns the title case equivalent for the specified code point if it
* exists. Otherwise, the specified code point is returned unchanged.
*
* @param codePoint
* the code point to convert.
* @return the title case equivalent of {@code codePoint} if it exists,
* otherwise {@code codePoint}.
*/
public static int toTitleCase(int codePoint) {
return UCharacter.toTitleCase(codePoint);
}
示例9: toTitleCase
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Answers the title case equivalent for the character, otherwise answers the
* character.
*
* @param codePoint
* the character
* @return the title case equivalent of the character
*/
public static int toTitleCase(int codePoint) {
return UCharacter.toTitleCase(codePoint);
}