本文整理汇总了C++中MessageFormat::applyPattern方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageFormat::applyPattern方法的具体用法?C++ MessageFormat::applyPattern怎么用?C++ MessageFormat::applyPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageFormat
的用法示例。
在下文中一共展示了MessageFormat::applyPattern方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formatErrorMessage
void formatErrorMessage(UErrorCode &realStatus, const UnicodeString& pattern, const Locale& theLocale,
UErrorCode inStatus0, /* statusString 1 */ const Locale &inCountry2, double currency3, // these numbers are the message arguments.
UnicodeString &result)
{
if(U_FAILURE(realStatus))
return; // you messed up
UnicodeString errString1(u_errorName(inStatus0));
UnicodeString countryName2;
inCountry2.getDisplayCountry(theLocale,countryName2);
Formattable myArgs[] = {
Formattable((int32_t)inStatus0), // inStatus0 {0}
Formattable(errString1), // statusString1 {1}
Formattable(countryName2), // inCountry2 {2}
Formattable(currency3)// currency3 {3,number,currency}
};
MessageFormat *fmt = new MessageFormat("MessageFormat's API is broken!!!!!!!!!!!",realStatus);
fmt->setLocale(theLocale);
fmt->applyPattern(pattern, realStatus);
if (U_FAILURE(realStatus)) {
delete fmt;
return;
}
FieldPosition ignore = 0;
fmt->format(myArgs,4,result,ignore,realStatus);
delete fmt;
}
示例2: pp
void MessageFormatRegressionTest::Test4116444()
{
UnicodeString patterns [] = {
(UnicodeString)"",
(UnicodeString)"one",
(UnicodeString) "{0,date,short}"
};
UErrorCode status = U_ZERO_ERROR;
MessageFormat *mf = new MessageFormat("", status);
failure(status, "new MessageFormat");
for (int i = 0; i < 3; i++) {
UnicodeString pattern = patterns[i];
mf->applyPattern(pattern, status);
failure(status, "mf->applyPattern", TRUE);
//try {
int32_t count = 0;
ParsePosition pp(0);
Formattable *array = mf->parse(UnicodeString(""), pp, count);
logln("pattern: \"" + pattern + "\"");
log(" parsedObjects: ");
if (array != NULL) {
log("{");
for (int j = 0; j < count; j++) {
//if (array[j] != null)
UnicodeString dummy;
err("\"" + array[j].getString(dummy) + "\"");
//else
// log("null");
if (j < count- 1)
log(",");
}
log("}") ;
delete[] array;
} else {
log("null");
}
logln("");
/*} catch (Exception e) {
errln("pattern: \"" + pattern + "\"");
errln(" Exception: " + e.getMessage());
}*/
}
delete mf;
}
示例3: forParsing
void MessageFormatRegressionTest::Test4118594()
{
UErrorCode status = U_ZERO_ERROR;
const UBool possibleDataError = TRUE;
MessageFormat *mf = new MessageFormat("{0}, {0}, {0}", status);
failure(status, "new MessageFormat");
UnicodeString forParsing("x, y, z");
//Object[] objs = mf.parse(forParsing, new ParsePosition(0));
int32_t count = 0;
ParsePosition pp(0);
Formattable *objs = mf->parse(forParsing, pp, count);
UnicodeString pat;
logln("pattern: \"" + mf->toPattern(pat) + "\"");
logln("text for parsing: \"" + forParsing + "\"");
UnicodeString str;
if (objs[0].getString(str) != "z")
errln("argument0: \"" + objs[0].getString(str) + "\"");
mf->applyPattern("{0,number,#.##}, {0,number,#.#}", status);
failure(status, "mf->applyPattern", possibleDataError);
//Object[] oldobjs = {new Double(3.1415)};
Formattable oldobjs [] = {Formattable(3.1415)};
UnicodeString result;
FieldPosition pos(FieldPosition::DONT_CARE);
result = mf->format( oldobjs, 1, result, pos, status );
failure(status, "mf->format", possibleDataError);
pat.remove();
logln("pattern: \"" + mf->toPattern(pat) + "\"");
logln("text for parsing: \"" + result + "\"");
// result now equals "3.14, 3.1"
if (result != "3.14, 3.1")
dataerrln("result = " + result + " - " + u_errorName(status));
//Object[] newobjs = mf.parse(result, new ParsePosition(0));
int32_t count1 = 0;
pp.setIndex(0);
Formattable *newobjs = mf->parse(result, pp, count1);
// newobjs now equals {new Double(3.1)}
if (newobjs == NULL) {
dataerrln("Error calling MessageFormat::parse");
} else {
if (newobjs[0].getDouble() != 3.1)
errln( UnicodeString("newobjs[0] = ") + newobjs[0].getDouble());
}
delete [] objs;
delete [] newobjs;
delete mf;
}
示例4: originalPattern
void MessageFormatRegressionTest::Test4114743()
{
UnicodeString originalPattern("initial pattern");
UErrorCode status = U_ZERO_ERROR;
MessageFormat *mf = new MessageFormat(originalPattern, status);
failure(status, "new MessageFormat");
//try {
UnicodeString illegalPattern("ab { '}' de");
mf->applyPattern(illegalPattern, status);
if( ! U_FAILURE(status))
errln("illegal pattern: \"" + illegalPattern + "\"");
/*} catch (IllegalArgumentException foo) {
if (!originalPattern.equals(mf.toPattern()))
errln("pattern after: \"" + mf.toPattern() + "\"");
}*/
delete mf;
}
示例5: pattern
void MessageFormatRegressionTest::Test4118592()
{
UErrorCode status = U_ZERO_ERROR;
MessageFormat *mf = new MessageFormat("", status);
failure(status, "new messageFormat");
UnicodeString pattern("{0,choice,1#YES|2#NO}");
UnicodeString prefix("");
Formattable *objs = 0;
for (int i = 0; i < 5; i++) {
UnicodeString formatted;
formatted = prefix + "YES";
mf->applyPattern(prefix + pattern, status);
failure(status, "mf->applyPattern");
prefix += "x";
//Object[] objs = mf.parse(formatted, new ParsePosition(0));
int32_t count = 0;
ParsePosition pp(0);
objs = mf->parse(formatted, pp, count);
UnicodeString pat;
logln(UnicodeString("") + i + ". pattern :\"" + mf->toPattern(pat) + "\"");
log(" \"" + formatted + "\" parsed as ");
if (objs == NULL)
logln(" null");
else {
UnicodeString temp;
if(objs[0].getType() == Formattable::kString)
logln((UnicodeString)" " + objs[0].getString(temp));
else
logln((UnicodeString)" " + (objs[0].getType() == Formattable::kLong ? objs[0].getLong() : objs[0].getDouble()));
delete[] objs;
}
}
delete mf;
}
示例6: pos
void MessageFormatRegressionTest::Test4074764() {
UnicodeString pattern [] = {
"Message without param",
"Message with param:{0}",
"Longer Message with param {0}"
};
//difference between the two param strings are that
//in the first one, the param position is within the
//length of the string without param while it is not so
//in the other case.
UErrorCode status = U_ZERO_ERROR;
MessageFormat *messageFormatter = new MessageFormat("", status);
failure(status, "couldn't create MessageFormat");
//try {
//Apply pattern with param and print the result
messageFormatter->applyPattern(pattern[1], status);
failure(status, "messageFormat->applyPattern");
//Object[] params = {new UnicodeString("BUG"), new Date()};
Formattable params [] = {
Formattable(UnicodeString("BUG")),
Formattable(0, Formattable::kIsDate)
};
UnicodeString tempBuffer;
FieldPosition pos(FieldPosition::DONT_CARE);
tempBuffer = messageFormatter->format(params, 2, tempBuffer, pos, status);
if( tempBuffer != "Message with param:BUG" || failure(status, "messageFormat->format"))
errln("MessageFormat with one param test failed.");
logln("Formatted with one extra param : " + tempBuffer);
//Apply pattern without param and print the result
messageFormatter->applyPattern(pattern[0], status);
failure(status, "messageFormatter->applyPattern");
// {sfb} how much does this apply in C++?
// do we want to verify that the Formattable* array is not NULL,
// or is that the user's responsibility?
// additionally, what should be the item count?
// for bug testing purposes, assume that something was set to
// NULL by mistake, and that the length should be non-zero
//tempBuffer = messageFormatter->format(NULL, 1, tempBuffer, FieldPosition(FieldPosition::DONT_CARE), status);
tempBuffer.remove();
tempBuffer = messageFormatter->format(NULL, 0, tempBuffer, pos, status);
if( tempBuffer != "Message without param" || failure(status, "messageFormat->format"))
errln("MessageFormat with no param test failed.");
logln("Formatted with no params : " + tempBuffer);
tempBuffer.remove();
tempBuffer = messageFormatter->format(params, 2, tempBuffer, pos, status);
if (tempBuffer != "Message without param" || failure(status, "messageFormat->format"))
errln("Formatted with arguments > subsitution failed. result = " + tempBuffer);
logln("Formatted with extra params : " + tempBuffer);
//This statement gives an exception while formatting...
//If we use pattern[1] for the message with param,
//we get an NullPointerException in MessageFormat.java(617)
//If we use pattern[2] for the message with param,
//we get an StringArrayIndexOutOfBoundsException in MessageFormat.java(614)
//Both are due to maxOffset not being reset to -1
//in applyPattern() when the pattern does not
//contain any param.
/*} catch (Exception foo) {
errln("Exception when formatting with no params.");
}*/
delete messageFormatter;
}