本文整理汇总了C++中MessageFormat::toPattern方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageFormat::toPattern方法的具体用法?C++ MessageFormat::toPattern怎么用?C++ MessageFormat::toPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageFormat
的用法示例。
在下文中一共展示了MessageFormat::toPattern方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pp
void MessageFormatRegressionTest::Test4120552()
{
UErrorCode status = U_ZERO_ERROR;
MessageFormat *mf = new MessageFormat("pattern", status);
failure(status, "new MessageFormat");
UnicodeString texts[] = {
(UnicodeString)"pattern",
(UnicodeString)"pat",
(UnicodeString)"1234"
};
UnicodeString pat;
logln("pattern: \"" + mf->toPattern(pat) + "\"");
for (int i = 0; i < 3; i++) {
ParsePosition pp(0);
//Object[] objs = mf.parse(texts[i], pp);
int32_t count = 0;
Formattable *objs = mf->parse(texts[i], pp, count);
log(" text for parsing: \"" + texts[i] + "\"");
if (objs == NULL) {
logln(" (incorrectly formatted string)");
if (pp.getErrorIndex() == -1)
errln(UnicodeString("Incorrect error index: ") + pp.getErrorIndex());
} else {
logln(" (correctly formatted string)");
delete[] objs;
}
}
delete mf;
}
示例2: pos
// {sfb} doesn't apply in C++?
void MessageFormatRegressionTest::Test4114739()
{
UErrorCode status = U_ZERO_ERROR;
MessageFormat *mf = new MessageFormat("<{0}>", status);
failure(status, "new MessageFormat");
Formattable *objs1 = NULL;
//Formattable objs2 [] = {};
//Formattable *objs3 [] = {NULL};
//try {
UnicodeString pat;
UnicodeString res;
logln("pattern: \"" + mf->toPattern(pat) + "\"");
log("format(null) : ");
FieldPosition pos(FieldPosition::DONT_CARE);
logln("\"" + mf->format(objs1, 0, res, pos, status) + "\"");
failure(status, "mf->format");
/*log("format({}) : ");
logln("\"" + mf->format(objs2, 0, res, FieldPosition(FieldPosition::DONT_CARE), status) + "\"");
failure(status, "mf->format");
log("format({null}) :");
logln("\"" + mf->format(objs3, 0, res, FieldPosition(FieldPosition::DONT_CARE), status) + "\"");
failure(status, "mf->format");*/
/*} catch (Exception e) {
errln("Exception thrown for null argument tests.");
}*/
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: exp
void MessageFormatRegressionTest::Test4058973()
{
UErrorCode status = U_ZERO_ERROR;
MessageFormat *fmt = new MessageFormat("{0,choice,0#no files|1#one file|1< {0,number,integer} files}", status);
failure(status, "new MessageFormat");
UnicodeString pat;
pat = fmt->toPattern(pat);
UnicodeString exp("{0,choice,0#no files|1#one file|1< {0,number,integer} files}");
if (pat != exp) {
errln("MessageFormat.toPattern failed");
errln("Exp: " + exp);
errln("Got: " + pat);
}
delete fmt;
}
示例5: logln
void TestMessageFormat::testBug2()
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString result;
// {sfb} use double format in pattern, so result will match (not strictly necessary)
const UnicodeString pattern = "There {0,choice,0.0#are no files|1.0#is one file|1.0<are {0, number} files} on disk {1}. ";
logln("The input pattern : " + pattern);
MessageFormat *fmt = new MessageFormat(pattern, status);
if (U_FAILURE(status)) {
errln("MessageFormat pattern creation failed.");
return;
}
logln("The output pattern is : " + fmt->toPattern(result));
if (pattern != result) {
errln("MessageFormat::toPattern() failed.");
}
delete fmt;
}
示例6: originalPattern
void MessageFormatRegressionTest::Test4113018()
{
UnicodeString originalPattern("initial pattern");
UErrorCode status = U_ZERO_ERROR;
MessageFormat *mf = new MessageFormat(originalPattern, status);
failure(status, "new messageFormat");
UnicodeString illegalPattern("format: {0, xxxYYY}");
UnicodeString pat;
logln("pattern before: \"" + mf->toPattern(pat) + "\"");
logln("illegal pattern: \"" + illegalPattern + "\"");
//try {
mf->applyPattern(illegalPattern, status);
if( ! U_FAILURE(status))
errln("Should have thrown IllegalArgumentException for pattern : " + illegalPattern);
/*} catch (IllegalArgumentException e) {
if (!originalPattern.equals(mf.toPattern()))
errln("pattern after: \"" + mf.toPattern() + "\"");
}*/
delete mf;
}
示例7: 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;
}
示例8: fpos
void
TestChoiceFormat::TestComplexExample( void )
{
UErrorCode status = U_ZERO_ERROR;
const double filelimits[] = {-1, 0,1,2};
const UnicodeString filepart[] = {"are corrupted files", "are no files","is one file","are {2} files"};
ChoiceFormat* fileform = new ChoiceFormat( filelimits, filepart, 4);
if (!fileform) {
it_errln("*** test_complex_example fileform");
return;
}
Format* filenumform = NumberFormat::createInstance( status );
if (!filenumform) {
dataerrln((UnicodeString)"*** test_complex_example filenumform - " + u_errorName(status));
delete fileform;
return;
}
if (!chkstatus( status, "*** test_simple_example filenumform" )) {
delete fileform;
delete filenumform;
return;
}
//const Format* testFormats[] = { fileform, NULL, filenumform };
//pattform->setFormats( testFormats, 3 );
MessageFormat* pattform = new MessageFormat("There {0} on {1}", status );
if (!pattform) {
it_errln("*** test_complex_example pattform");
delete fileform;
delete filenumform;
return;
}
if (!chkstatus( status, "*** test_complex_example pattform" )) {
delete fileform;
delete filenumform;
delete pattform;
return;
}
pattform->setFormat( 0, *fileform );
pattform->setFormat( 2, *filenumform );
Formattable testArgs[] = {(int32_t)0, "Disk_A", (int32_t)0};
UnicodeString str;
UnicodeString res1, res2;
pattform->toPattern( res1 );
it_logln("MessageFormat toPattern: " + res1);
fileform->toPattern( res1 );
it_logln("ChoiceFormat toPattern: " + res1);
if (res1 == "-1#are corrupted files|0#are no files|1#is one file|2#are {2} files") {
it_logln("toPattern tested!");
}else{
it_errln("*** ChoiceFormat to Pattern result!");
}
FieldPosition fpos(FieldPosition::DONT_CARE);
UnicodeString checkstr[] = {
"There are corrupted files on Disk_A",
"There are no files on Disk_A",
"There is one file on Disk_A",
"There are 2 files on Disk_A",
"There are 3 files on Disk_A"
};
// if (status != U_ZERO_ERROR) return; // TODO: analyze why we have such a bad bail out here!
if (U_FAILURE(status)) {
delete fileform;
delete filenumform;
delete pattform;
return;
}
int32_t i;
int32_t start = -1;
for (i = start; i < 4; ++i) {
str = "";
status = U_ZERO_ERROR;
testArgs[0] = Formattable((int32_t)i);
testArgs[2] = testArgs[0];
res2 = pattform->format(testArgs, 3, str, fpos, status );
if (!chkstatus( status, "*** test_complex_example format" )) {
delete fileform;
delete filenumform;
delete pattform;
return;
}
it_logln(i + UnicodeString(" -> ") + res2);
if (res2 != checkstr[i - start]) {
it_errln("*** test_complex_example res string");
it_errln(UnicodeString("*** ") + i + UnicodeString(" -> '") + res2 + UnicodeString("' unlike '") + checkstr[i] + UnicodeString("' ! "));
}
}
//.........这里部分代码省略.........
示例9: PatternTest
void TestMessageFormat::PatternTest()
{
Formattable testArgs[] = {
Formattable(double(1)), Formattable(double(3456)),
Formattable("Disk"), Formattable(UDate((int32_t)1000000000L), Formattable::kIsDate)
};
UnicodeString testCases[] = {
"Quotes '', '{', 'a' {0} '{0}'",
"Quotes '', '{', 'a' {0,number} '{0}'",
"'{'1,number,'#',##} {1,number,'#',##}",
"There are {1} files on {2} at {3}.",
"On {2}, there are {1} files, with {0,number,currency}.",
"'{1,number,percent}', {1,number,percent},",
"'{1,date,full}', {1,date,full},",
"'{3,date,full}', {3,date,full},",
"'{1,number,#,##}' {1,number,#,##}",
};
UnicodeString testResultPatterns[] = {
"Quotes '', '{', a {0} '{'0}",
"Quotes '', '{', a {0,number} '{'0}",
"'{'1,number,#,##} {1,number,'#'#,##}",
"There are {1} files on {2} at {3}.",
"On {2}, there are {1} files, with {0,number,currency}.",
"'{'1,number,percent}, {1,number,percent},",
"'{'1,date,full}, {1,date,full},",
"'{'3,date,full}, {3,date,full},",
"'{'1,number,#,##} {1,number,#,##}"
};
UnicodeString testResultStrings[] = {
"Quotes ', {, a 1 {0}",
"Quotes ', {, a 1 {0}",
"{1,number,#,##} #34,56",
"There are 3,456 files on Disk at 1/12/70 5:46 AM.",
"On Disk, there are 3,456 files, with $1.00.",
"{1,number,percent}, 345,600%,",
"{1,date,full}, Wednesday, December 31, 1969,",
"{3,date,full}, Monday, January 12, 1970,",
"{1,number,#,##} 34,56"
};
for (int32_t i = 0; i < 9; ++i) {
//it_out << "\nPat in: " << testCases[i]);
MessageFormat *form = 0;
UErrorCode success = U_ZERO_ERROR;
UnicodeString buffer;
form = new MessageFormat(testCases[i], Locale::getUS(), success);
if (U_FAILURE(success)) {
errln("MessageFormat creation failed.#1");
logln(((UnicodeString)"MessageFormat for ") + testCases[i] + " creation failed.\n");
continue;
}
if (form->toPattern(buffer) != testResultPatterns[i]) {
errln(UnicodeString("TestMessageFormat::PatternTest failed test #2, i = ") + i);
//form->toPattern(buffer);
errln(((UnicodeString)" Orig: ") + testCases[i]);
errln(((UnicodeString)" Exp: ") + testResultPatterns[i]);
errln(((UnicodeString)" Got: ") + buffer);
}
//it_out << "Pat out: " << form->toPattern(buffer));
UnicodeString result;
int32_t count = 4;
FieldPosition fieldpos(0);
form->format(testArgs, count, result, fieldpos, success);
if (U_FAILURE(success)) {
errln("MessageFormat failed test #3");
logln("TestMessageFormat::PatternTest failed test #3");
continue;
}
if (result != testResultStrings[i]) {
errln("TestMessageFormat::PatternTest failed test #4");
logln("TestMessageFormat::PatternTest failed #4.");
logln(UnicodeString(" Result: ") + result );
logln(UnicodeString(" Expected: ") + testResultStrings[i] );
}
//it_out << "Result: " << result);
#if 0
/* TODO: Look at this test and see if this is still a valid test */
logln("---------------- test parse ----------------");
form->toPattern(buffer);
logln("MSG pattern for parse: " + buffer);
int32_t parseCount = 0;
Formattable* values = form->parse(result, parseCount, success);
if (U_FAILURE(success)) {
errln("MessageFormat failed test #5");
logln(UnicodeString("MessageFormat failed test #5 with error code ")+(int32_t)success);
} else if (parseCount != count) {
errln("MSG count not %d as expected. Got %d", count, parseCount);
}
UBool failed = FALSE;
for (int32_t j = 0; j < parseCount; ++j) {
if (values == 0 || testArgs[j] != values[j]) {
//.........这里部分代码省略.........