/* structure containing specification of a collator. Initialized * from a short string. Also used to construct a short string from a * collator instance
*/ struct CollatorSpec { inline CollatorSpec();
CollatorSpec::CollatorSpec() :
locale(),
variableTopValue(0),
variableTopString(),
variableTopSet(false)
{ // set collation options to default for(int32_t i = 0; i < UCOL_ATTRIBUTE_COUNT; i++) {
options[i] = UCOL_DEFAULT;
}
}
/* structure for converting between character attribute * representation and real collation attribute value.
*/ struct AttributeConversion { char letter;
UColAttributeValue value;
};
/* function prototype for functions used to parse a short string */
U_CDECL_BEGIN typedefconstchar* U_CALLCONV
ActionFunction(CollatorSpec *spec, uint32_t value1, constchar* string,
UErrorCode *status);
U_CDECL_END
U_CDECL_BEGIN staticconstchar* U_CALLCONV
_processLocaleElement(CollatorSpec *spec, uint32_t value, constchar* string,
UErrorCode *status)
{ do { if(value == UCOL_SIT_LANGUAGE || value == UCOL_SIT_KEYWORD || value == UCOL_SIT_PROVIDER) {
spec->locElements[value].append(uprv_tolower(*string), *status);
} else {
spec->locElements[value].append(*string, *status);
}
} while(*(++string) != '_' && *string && U_SUCCESS(*status)); // don't skip the underscore at the end return string;
}
U_CDECL_END
staticvoid
ucol_sit_calculateWholeLocale(CollatorSpec *s, UErrorCode &status) { // put the locale together, unless we have a done // locale if(s->locale.isEmpty()) { // first the language
s->locale.append(s->locElements[UCOL_SIT_LANGUAGE], status); // then the script, if present if(!s->locElements[UCOL_SIT_SCRIPT].isEmpty()) {
s->locale.append("_", status);
s->locale.append(s->locElements[UCOL_SIT_SCRIPT], status);
} // then the region, if present if(!s->locElements[UCOL_SIT_REGION].isEmpty()) {
s->locale.append("_", status);
s->locale.append(s->locElements[UCOL_SIT_REGION], status);
} elseif(!s->locElements[UCOL_SIT_VARIANT].isEmpty()) { // if there is a variant, we need an underscore
s->locale.append("_", status);
} // add variant, if there if(!s->locElements[UCOL_SIT_VARIANT].isEmpty()) {
s->locale.append("_", status);
s->locale.append(s->locElements[UCOL_SIT_VARIANT], status);
}
// if there is a collation keyword, add that too if(!s->locElements[UCOL_SIT_KEYWORD].isEmpty()) {
s->locale.append(collationKeyword, status);
s->locale.append(s->locElements[UCOL_SIT_KEYWORD], status);
}
// if there is a provider keyword, add that too if(!s->locElements[UCOL_SIT_PROVIDER].isEmpty()) {
s->locale.append(providerKeyword, status);
s->locale.append(s->locElements[UCOL_SIT_PROVIDER], status);
}
}
}
// first we want to pick stuff out of short string. // we'll end up with an UCA version, locale and a bunch of // settings
// analyse the string in order to get everything we need.
CollatorSpec s;
ucol_sit_readSpecs(&s, definition, parseError, status);
ucol_sit_calculateWholeLocale(&s, *status);
UResourceBundle *b = ures_open(U_ICUDATA_COLL, buffer.data(), status); /* we try to find stuff from keyword */
UResourceBundle *collations = ures_getByKey(b, "collations", nullptr, status);
UResourceBundle *collElem = nullptr; // if there is a keyword, we pick it up and try to get elements
CharString keyBuffer = ulocimp_getKeywordValue(buffer.data(), "collation", *status); if(keyBuffer.isEmpty()) { // no keyword // we try to find the default setting, which will give us the keyword value
UResourceBundle *defaultColl = ures_getByKeyWithFallback(collations, "default", nullptr, status); if(U_SUCCESS(*status)) {
int32_t defaultKeyLen = 0; const char16_t *defaultKey = ures_getString(defaultColl, &defaultKeyLen, status);
keyBuffer.appendInvariantChars(defaultKey, defaultKeyLen, *status);
} else {
*status = U_INTERNAL_PROGRAM_ERROR; return;
}
ures_close(defaultColl);
}
collElem = ures_getByKeyWithFallback(collations, keyBuffer.data(), collElem, status);
ures_close(collElem);
ures_close(collations);
ures_close(b);
}
// first we want to pick stuff out of short string. // we'll end up with an UCA version, locale and a bunch of // settings
// analyse the string in order to get everything we need. constchar *string = definition;
CollatorSpec s;
string = ucol_sit_readSpecs(&s, definition, parseError, status);
ucol_sit_calculateWholeLocale(&s, *status);
/** * Get a set containing the contractions defined by the collator. The set includes * both the UCA contractions and the contractions defined by the collator * @param coll collator * @param conts the set to hold the result * @param status to hold the error code * @return the size of the contraction set
*/
U_CAPI int32_t U_EXPORT2
ucol_getContractions( const UCollator *coll,
USet *contractions,
UErrorCode *status)
{
ucol_getContractionsAndExpansions(coll, contractions, nullptr, false, status); return uset_getItemCount(contractions);
}
/** * Get a set containing the expansions defined by the collator. The set includes * both the UCA expansions and the expansions defined by the tailoring * @param coll collator * @param conts the set to hold the result * @param addPrefixes add the prefix contextual elements to contractions * @param status to hold the error code * * @draft ICU 3.4
*/
U_CAPI void U_EXPORT2
ucol_getContractionsAndExpansions( const UCollator *coll,
USet *contractions,
USet *expansions,
UBool addPrefixes,
UErrorCode *status)
{ if(U_FAILURE(*status)) { return;
} if(coll == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR; return;
} const icu::RuleBasedCollator *rbc = icu::RuleBasedCollator::rbcFromUCollator(coll); if(rbc == nullptr) {
*status = U_UNSUPPORTED_ERROR; return;
}
rbc->internalGetContractionsAndExpansions(
icu::UnicodeSet::fromUSet(contractions),
icu::UnicodeSet::fromUSet(expansions),
addPrefixes, *status);
} #endif
Messung V0.5
¤ Dauer der Verarbeitung: 0.15 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.