TitlecaseTransliterator::TitlecaseTransliterator() :
CaseMapTransliterator(UNICODE_STRING("Any-Title", 9), nullptr)
{ // Need to look back 2 characters in the case of "can't"
setMaximumContextLength(2);
}
/** * Implements {@link Transliterator#handleTransliterate}.
*/ void TitlecaseTransliterator::handleTransliterate(
Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const
{ // TODO reimplement, see ustrcase.c // using a real word break iterator // instead of just looking for a transition between cased and uncased characters // call CaseMapTransliterator::handleTransliterate() for lowercasing? (set fMap) // needs to take isIncremental into account because case mappings are context-sensitive // also detect when lowercasing function did not finish because of context
// Our mode; we are either converting letter toTitle or // toLower.
UBool doTitle = true;
// Determine if there is a preceding context of cased case-ignorable*, // in which case we want to start in toLower mode. If the // prior context is anything else (including empty) then start // in toTitle mode.
UChar32 c;
int32_t start; for (start = offsets.start - 1; start >= offsets.contextStart; start -= U16_LENGTH(c)) {
c = text.char32At(start);
type=ucase_getTypeOrIgnorable(c); if(type>0) { // cased
doTitle=false; break;
} elseif(type==0) { // uncased but not ignorable break;
} // else (type<0) case-ignorable: continue
}
// Convert things after a cased character toLower; things // after an uncased, non-case-ignorable character toTitle. Case-ignorable // characters are copied directly and do not change the mode.
UCaseContext csc;
uprv_memset(&csc, 0, sizeof(csc));
csc.p = &text;
csc.start = offsets.contextStart;
csc.limit = offsets.contextLimit;
if(csc.b1 && isIncremental) { // fMap() tried to look beyond the context limit // wait for more input
offsets.start=csc.cpStart; return;
}
if(result>=0) { // replace the current code point with its full case mapping result // see UCASE_MAX_STRING_LENGTH if(result<=UCASE_MAX_STRING_LENGTH) { // string s[result]
tmp.setTo(false, s, result);
delta=result-U16_LENGTH(c);
} else { // single code point
tmp.setTo(result);
delta=tmp.length()-U16_LENGTH(c);
}
text.handleReplaceBetween(csc.cpStart, textPos, tmp); if(delta!=0) {
textPos+=delta;
csc.limit=offsets.contextLimit+=delta;
offsets.limit+=delta;
}
}
}
}
offsets.start=textPos;
}
U_NAMESPACE_END
#endif/* #if !UCONFIG_NO_TRANSLITERATION */
Messung V0.5
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.