本文整理汇总了C++中Formattable::getArray方法的典型用法代码示例。如果您正苦于以下问题:C++ Formattable::getArray方法的具体用法?C++ Formattable::getArray怎么用?C++ Formattable::getArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formattable
的用法示例。
在下文中一共展示了Formattable::getArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
U_DRAFT UFormattable * U_EXPORT2
ufmt_getArrayItemByIndex(UFormattable* fmt, int32_t n, UErrorCode *status) {
Formattable *obj = Formattable::fromUFormattable(fmt);
int32_t count;
(void)obj->getArray(count, *status);
if(U_FAILURE(*status)) {
return NULL;
} else if(n<0 || n>=count) {
setError(*status, U_INDEX_OUTOFBOUNDS_ERROR);
return NULL;
} else {
return (*obj)[n].toUFormattable(); // returns non-const Formattable
}
}
示例2: switch
void
FormattableStreamer::streamOut(ostream& stream, const Formattable& obj)
{
static DateFormat *defDateFormat = 0;
UnicodeString buffer;
switch(obj.getType()) {
case Formattable::kDate :
// Creates a DateFormat instance for formatting the
// Date instance.
if (defDateFormat == 0) {
defDateFormat = DateFormat::createInstance();
}
defDateFormat->format(obj.getDate(), buffer);
stream << buffer;
break;
case Formattable::kDouble :
// Output the double as is.
stream << obj.getDouble() << 'D';
break;
case Formattable::kLong :
// Output the double as is.
stream << obj.getLong() << 'L';
break;
case Formattable::kString:
// Output the double as is. Please see UnicodeString console
// I/O routine for more details.
stream << '"' << obj.getString(buffer) << '"';
break;
case Formattable::kArray:
int32_t i, count;
const Formattable* array;
array = obj.getArray(count);
stream << '[';
// Recursively calling the console I/O routine for each element in the array.
for (i=0; i<count; ++i) {
FormattableStreamer::streamOut(stream, array[i]);
stream << ( (i==(count-1)) ? "" : ", " );
}
stream << ']';
break;
default:
// Not a recognizable Formattable object.
stream << "INVALID_Formattable";
}
stream.flush();
}
示例3: testParse
void TestMessageFormat::testParse()
{
UErrorCode err = U_ZERO_ERROR;
int32_t count;
UnicodeString msgFormatString = "{0} =sep= {1}";
MessageFormat msg( msgFormatString, err);
UnicodeString source = "abc =sep= def";
UnicodeString tmp1, tmp2;
Formattable* fmt_arr = msg.parse( source, count, err );
if (U_FAILURE(err) || (!fmt_arr)) {
errln("*** MSG parse (ustring, count, err) error.");
}else{
logln("MSG parse -- count: %d", count);
if (count != 2) {
errln("*** MSG parse (ustring, count, err) count err.");
}else{
if ((fmt_arr[0].getType() == Formattable::kString)
&& (fmt_arr[1].getType() == Formattable::kString)
&& (fmt_arr[0].getString(tmp1) == "abc")
&& (fmt_arr[1].getString(tmp2) == "def")) {
logln("MSG parse (ustring, count, err) tested.");
}else{
errln("*** MSG parse (ustring, count, err) result err.");
}
}
}
delete[] fmt_arr;
ParsePosition pp(0);
fmt_arr = msg.parse( source, pp, count );
if ((pp == 0) || (!fmt_arr)) {
errln("*** MSG parse (ustring, parsepos., count) error.");
}else{
logln("MSG parse -- count: %d", count);
if (count != 2) {
errln("*** MSG parse (ustring, parsepos., count) count err.");
}else{
if ((fmt_arr[0].getType() == Formattable::kString)
&& (fmt_arr[1].getType() == Formattable::kString)
&& (fmt_arr[0].getString(tmp1) == "abc")
&& (fmt_arr[1].getString(tmp2) == "def")) {
logln("MSG parse (ustring, parsepos., count) tested.");
}else{
errln("*** MSG parse (ustring, parsepos., count) result err.");
}
}
}
delete[] fmt_arr;
pp = 0;
Formattable fmta;
msg.parseObject( source, fmta, pp );
if (pp == 0) {
errln("*** MSG parse (ustring, Formattable, parsepos ) error.");
}else{
logln("MSG parse -- count: %d", count);
fmta.getArray(count);
if (count != 2) {
errln("*** MSG parse (ustring, Formattable, parsepos ) count err.");
}else{
if ((fmta[0].getType() == Formattable::kString)
&& (fmta[1].getType() == Formattable::kString)
&& (fmta[0].getString(tmp1) == "abc")
&& (fmta[1].getString(tmp2) == "def")) {
logln("MSG parse (ustring, Formattable, parsepos ) tested.");
}else{
errln("*** MSG parse (ustring, Formattable, parsepos ) result err.");
}
}
}
}