LocaleBuilder& LocaleBuilder::setLanguageTag(StringPiece tag)
{
Locale l = Locale::forLanguageTag(tag, status_); if (U_FAILURE(status_)) { return *this; } // Because setLocale will reset status_ we need to return // first if we have error in forLanguageTag.
setLocale(l); return *this;
}
UErrorCode localErrorCode = U_ZERO_ERROR; auto attributes = extensions_->getKeywordValue<CharString>(kAttributeKey, localErrorCode); if (U_FAILURE(localErrorCode)) {
CharString new_attributes(value_str.data(), status_); // No attributes, set the attribute.
extensions_->setKeywordValue(kAttributeKey, new_attributes.data(), status_); return *this;
}
transform(attributes.data(),attributes.length()); constchar* start = attributes.data(); constchar* limit = attributes.data() + attributes.length();
CharString new_attributes; bool inserted = false; while (start < limit) { if (!inserted) { int cmp = uprv_strcmp(start, value_str.data()); if (cmp == 0) { return *this; } // Found it in attributes: Just return if (cmp > 0) { if (!new_attributes.isEmpty()) new_attributes.append('_', status_);
new_attributes.append(value_str.data(), status_);
inserted = true;
}
} if (!new_attributes.isEmpty()) {
new_attributes.append('_', status_);
}
new_attributes.append(start, status_);
start += uprv_strlen(start) + 1;
} if (!inserted) { if (!new_attributes.isEmpty()) {
new_attributes.append('_', status_);
}
new_attributes.append(value_str.data(), status_);
} // Not yet in the attributes, set the attribute.
extensions_->setKeywordValue(kAttributeKey, new_attributes.data(), status_); return *this;
}
LocaleBuilder& LocaleBuilder::removeUnicodeLocaleAttribute(
StringPiece value)
{
CharString value_str(value, status_); if (U_FAILURE(status_)) { return *this; }
transform(value_str.data(), value_str.length()); if (!ultag_isUnicodeLocaleAttribute(value_str.data(), value_str.length())) {
status_ = U_ILLEGAL_ARGUMENT_ERROR; return *this;
} if (extensions_ == nullptr) { return *this; }
UErrorCode localErrorCode = U_ZERO_ERROR; auto attributes = extensions_->getKeywordValue<CharString>(kAttributeKey, localErrorCode); // get failure, just return if (U_FAILURE(localErrorCode)) { return *this; } // Do not have any attributes, just return. if (attributes.isEmpty()) { return *this; }
char* p = attributes.data(); // Replace null terminiator in place for _ and - so later // we can use uprv_strcmp to compare. for (int32_t i = 0; i < attributes.length(); i++, p++) {
*p = (*p == '_' || *p == '-') ? '\0' : uprv_tolower(*p);
}
constchar* start = attributes.data(); constchar* limit = attributes.data() + attributes.length();
CharString new_attributes; bool found = false; while (start < limit) { if (uprv_strcmp(start, value_str.data()) == 0) {
found = true;
} else { if (!new_attributes.isEmpty()) {
new_attributes.append('_', status_);
}
new_attributes.append(start, status_);
}
start += uprv_strlen(start) + 1;
} // Found the value in attributes, set the attribute. if (found) {
extensions_->setKeywordValue(kAttributeKey, new_attributes.data(), status_);
} return *this;
}
void LocaleBuilder::copyExtensionsFrom(const Locale& src, UErrorCode& errorCode)
{ if (U_FAILURE(errorCode)) { return; }
LocalPointer<icu::StringEnumeration> keywords(src.createKeywords(errorCode)); if (U_FAILURE(errorCode) || keywords.isNull() || keywords->count(errorCode) == 0) { // Error, or no extensions to copy. return;
} if (extensions_ == nullptr) {
extensions_ = Locale::getRoot().clone(); if (extensions_ == nullptr) {
status_ = U_MEMORY_ALLOCATION_ERROR; return;
}
}
_copyExtensions(src, keywords.getAlias(), *extensions_, false, errorCode);
}
Locale LocaleBuilder::build(UErrorCode& errorCode)
{ if (U_FAILURE(errorCode)) { return makeBogusLocale();
} if (U_FAILURE(status_)) {
errorCode = status_; return makeBogusLocale();
}
CharString locale_str(language_, errorCode); if (uprv_strlen(script_) > 0) {
locale_str.append('-', errorCode).append(StringPiece(script_), errorCode);
} if (uprv_strlen(region_) > 0) {
locale_str.append('-', errorCode).append(StringPiece(region_), errorCode);
} if (variant_ != nullptr) {
locale_str.append('-', errorCode).append(StringPiece(variant_->data()), errorCode);
} if (U_FAILURE(errorCode)) { return makeBogusLocale();
}
Locale product(locale_str.data()); if (extensions_ != nullptr) {
_copyExtensions(*extensions_, nullptr, product, true, errorCode);
} if (U_FAILURE(errorCode)) { return makeBogusLocale();
} return product;
}
UBool LocaleBuilder::copyErrorTo(UErrorCode &outErrorCode) const { if (U_FAILURE(outErrorCode)) { // Do not overwrite the older error code returntrue;
}
outErrorCode = status_; return U_FAILURE(outErrorCode);
}
U_NAMESPACE_END
Messung V0.5 in Prozent
¤ 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.0.18Bemerkung:
(vorverarbeitet am 2026-05-07)
¤
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.