mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 14:05:32 +00:00
ICU-25 Redeclarations of format/parse needed in Format hierarchy
X-SVN-Rev: 93
This commit is contained in:
parent
2f959e256c
commit
48c94ab013
3 changed files with 166 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1997-1999 *
|
||||
* Copyright (C) 1999 Alan Liu and others. All rights reserved. *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
|
@ -305,6 +306,25 @@ public:
|
|||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Redeclared NumberFormat method.
|
||||
*/
|
||||
UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& result,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Redeclared NumberFormat method.
|
||||
*/
|
||||
UnicodeString& format(double number,
|
||||
UnicodeString& output) const;
|
||||
|
||||
/**
|
||||
* Redeclared NumberFormat method.
|
||||
*/
|
||||
UnicodeString& format(int32_t number,
|
||||
UnicodeString& output) const;
|
||||
|
||||
/**
|
||||
* Parse the given string using this object's choices. The method
|
||||
* does string comparisons to try to find an optimal match.
|
||||
|
@ -940,6 +960,27 @@ protected:
|
|||
static const int32_t kDoubleIntegerDigits;
|
||||
static const int32_t kDoubleFractionDigits;
|
||||
};
|
||||
|
||||
inline UnicodeString&
|
||||
DecimalFormat::format(const Formattable& obj,
|
||||
UnicodeString& result,
|
||||
UErrorCode& status) const {
|
||||
// Don't use Format:: - use immediate base class only,
|
||||
// in case immediate base modifies behavior later.
|
||||
return NumberFormat::format(obj, result, status);
|
||||
}
|
||||
|
||||
inline UnicodeString&
|
||||
DecimalFormat::format(double number,
|
||||
UnicodeString& output) const {
|
||||
return NumberFormat::format(number, output);
|
||||
}
|
||||
|
||||
inline UnicodeString&
|
||||
DecimalFormat::format(int32_t number,
|
||||
UnicodeString& output) const {
|
||||
return NumberFormat::format(number, output);
|
||||
}
|
||||
|
||||
#endif // _DECIMFMT
|
||||
//eof
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* COPYRIGHT:
|
||||
* (C) Copyright Taligent, Inc., 1997
|
||||
* (C) Copyright International Business Machines Corporation, 1997 - 1998
|
||||
* Copyright (C) 1999 Alan Liu and others. All rights reserved.
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved.
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
||||
|
@ -16,6 +17,9 @@
|
|||
|
||||
#include "datefmt.h"
|
||||
#include "smpdtfmt.h"
|
||||
#include "decimfmt.h"
|
||||
#include "choicfmt.h"
|
||||
#include "msgfmt.h"
|
||||
|
||||
|
||||
// This is an API test, not a unit test. It doesn't test very many cases, and doesn't
|
||||
|
@ -45,6 +49,13 @@ void IntlTestDateFormatAPI::runIndexedTest( int32_t index, bool_t exec, char* &n
|
|||
}
|
||||
break;
|
||||
|
||||
case 2: name = "TestNameHiding";
|
||||
if (exec) {
|
||||
logln("TestNameHiding---"); logln("");
|
||||
TestNameHiding();
|
||||
}
|
||||
break;
|
||||
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
@ -212,3 +223,111 @@ void IntlTestDateFormatAPI::testAPI(char *par)
|
|||
delete it;
|
||||
delete de;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hiding of parse() and format() APIs in the Format hierarchy.
|
||||
* We test the entire hierarchy, even though this test is located in
|
||||
* the DateFormat API test.
|
||||
*/
|
||||
void
|
||||
IntlTestDateFormatAPI::TestNameHiding() {
|
||||
|
||||
// N.B.: This test passes if it COMPILES, since it's a test of
|
||||
// compile-time name hiding.
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Formattable dateObj(0, Formattable::kIsDate);
|
||||
Formattable numObj(3.1415926535897932384626433832795);
|
||||
Formattable obj;
|
||||
UnicodeString str;
|
||||
FieldPosition fpos;
|
||||
ParsePosition ppos;
|
||||
|
||||
// DateFormat calling Format API
|
||||
{
|
||||
logln("DateFormat");
|
||||
DateFormat *dateFmt = DateFormat::createInstance();
|
||||
if (dateFmt) {
|
||||
dateFmt->format(dateObj, str, status);
|
||||
dateFmt->format(dateObj, str, fpos, status);
|
||||
delete dateFmt;
|
||||
} else {
|
||||
errln("FAIL: Can't create DateFormat");
|
||||
}
|
||||
}
|
||||
|
||||
// SimpleDateFormat calling Format & DateFormat API
|
||||
{
|
||||
logln("SimpleDateFormat");
|
||||
status = U_ZERO_ERROR;
|
||||
SimpleDateFormat sdf(status);
|
||||
// Format API
|
||||
sdf.format(dateObj, str, status);
|
||||
sdf.format(dateObj, str, fpos, status);
|
||||
// DateFormat API
|
||||
sdf.format((UDate)0, str, fpos);
|
||||
sdf.format((UDate)0, str);
|
||||
sdf.parse(str, status);
|
||||
sdf.parse(str, ppos);
|
||||
}
|
||||
|
||||
// NumberFormat calling Format API
|
||||
{
|
||||
logln("NumberFormat");
|
||||
status = U_ZERO_ERROR;
|
||||
NumberFormat *fmt = NumberFormat::createInstance(status);
|
||||
if (fmt) {
|
||||
fmt->format(numObj, str, status);
|
||||
fmt->format(numObj, str, fpos, status);
|
||||
delete fmt;
|
||||
} else {
|
||||
errln("FAIL: Can't create NumberFormat");
|
||||
}
|
||||
}
|
||||
|
||||
// DecimalFormat calling Format & NumberFormat API
|
||||
{
|
||||
logln("DecimalFormat");
|
||||
status = U_ZERO_ERROR;
|
||||
DecimalFormat fmt(status);
|
||||
// Format API
|
||||
fmt.format(numObj, str, status);
|
||||
fmt.format(numObj, str, fpos, status);
|
||||
// NumberFormat API
|
||||
fmt.format(2.71828, str);
|
||||
fmt.format(1234567, str);
|
||||
fmt.format(1.41421, str, fpos);
|
||||
fmt.format(9876543, str, fpos);
|
||||
fmt.parse(str, obj, ppos);
|
||||
fmt.parse(str, obj, status);
|
||||
}
|
||||
|
||||
// ChoiceFormat calling Format & NumberFormat API
|
||||
{
|
||||
logln("ChoiceFormat");
|
||||
status = U_ZERO_ERROR;
|
||||
ChoiceFormat fmt("0#foo|1#foos|2#foos", status);
|
||||
// Format API
|
||||
fmt.format(numObj, str, status);
|
||||
fmt.format(numObj, str, fpos, status);
|
||||
// NumberFormat API
|
||||
fmt.format(2.71828, str);
|
||||
fmt.format(1234567, str);
|
||||
fmt.format(1.41421, str, fpos);
|
||||
fmt.format(9876543, str, fpos);
|
||||
fmt.parse(str, obj, ppos);
|
||||
fmt.parse(str, obj, status);
|
||||
}
|
||||
|
||||
// MessageFormat calling Format API
|
||||
{
|
||||
logln("MessageFormat");
|
||||
status = U_ZERO_ERROR;
|
||||
MessageFormat fmt("", status);
|
||||
// Format API
|
||||
// We use dateObj, which MessageFormat should reject.
|
||||
// We're testing name hiding, not the format method.
|
||||
fmt.format(dateObj, str, status);
|
||||
fmt.format(dateObj, str, fpos, status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* COPYRIGHT:
|
||||
* (C) Copyright Taligent, Inc., 1997
|
||||
* (C) Copyright International Business Machines Corporation, 1997 - 1998
|
||||
* Copyright (C) 1999 Alan Liu and others. All rights reserved.
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved.
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
||||
|
@ -36,6 +37,11 @@ private:
|
|||
* Test that the equals method works correctly.
|
||||
*/
|
||||
void TestEquals();
|
||||
|
||||
/**
|
||||
* Test that no parse or format methods are hidden.
|
||||
*/
|
||||
void TestNameHiding();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue