本文整理汇总了C++中LocalPointer::select方法的典型用法代码示例。如果您正苦于以下问题:C++ LocalPointer::select方法的具体用法?C++ LocalPointer::select怎么用?C++ LocalPointer::select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalPointer
的用法示例。
在下文中一共展示了LocalPointer::select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkSelect
void PluralRulesTest::checkSelect(const LocalPointer<PluralRules> &rules, UErrorCode &status,
int32_t line, const char *keyword, ...) {
// The varargs parameters are a const char* strings, each being a decimal number.
// The formatting of the numbers as strings is significant, e.g.
// the difference between "2" and "2.0" can affect which rule matches (which keyword is selected).
// Note: rules parameter is a LocalPointer reference rather than a PluralRules * to avoid having
// to write getAlias() at every (numerous) call site.
if (U_FAILURE(status)) {
errln("file %s, line %d, ICU error status: %s.", __FILE__, line, u_errorName(status));
status = U_ZERO_ERROR;
return;
}
if (rules == NULL) {
errln("file %s, line %d: rules pointer is NULL", __FILE__, line);
return;
}
va_list ap;
va_start(ap, keyword);
for (;;) {
const char *num = va_arg(ap, const char *);
if (strcmp(num, END_MARK) == 0) {
break;
}
// DigitList is a convenient way to parse the decimal number string and get a double.
DigitList dl;
dl.set(StringPiece(num), status);
if (U_FAILURE(status)) {
errln("file %s, line %d, ICU error status: %s.", __FILE__, line, u_errorName(status));
status = U_ZERO_ERROR;
continue;
}
double numDbl = dl.getDouble();
const char *decimalPoint = strchr(num, '.');
int fractionDigitCount = decimalPoint == NULL ? 0 : (num + strlen(num) - 1) - decimalPoint;
int fractionDigits = fractionDigitCount == 0 ? 0 : atoi(decimalPoint + 1);
FixedDecimal ni(numDbl, fractionDigitCount, fractionDigits);
UnicodeString actualKeyword = rules->select(ni);
if (actualKeyword != UnicodeString(keyword)) {
errln("file %s, line %d, select(%s) returned incorrect keyword. Expected %s, got %s",
__FILE__, line, num, keyword, US(actualKeyword).cstr());
}
}
va_end(ap);
}