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;
}
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.