1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-11-22 20:25:35 +00:00
|
|
|
*******************************************************************************
|
2003-12-19 21:29:27 +00:00
|
|
|
* Copyright (C) 1997-2003, International Business Machines Corporation and *
|
1999-11-22 20:25:35 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File FMTABLE.CPP
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 03/25/97 clhuang Initial Implementation.
|
|
|
|
********************************************************************************
|
|
|
|
*/
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/fmtable.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// class Formattable
|
|
|
|
// *****************************************************************************
|
2001-03-06 19:44:45 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2003-08-31 20:53:46 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Formattable)
|
2002-06-29 00:04:16 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// default constructor.
|
|
|
|
// Creates a formattable object with a long value 0.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
Formattable::Formattable()
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kLong)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-10-31 22:47:25 +00:00
|
|
|
fValue.fInt64 = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a Date instance.
|
|
|
|
|
2000-08-15 18:25:20 +00:00
|
|
|
Formattable::Formattable(UDate date, ISDATE /*isDate*/)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kDate)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
fValue.fDate = date;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a double value.
|
|
|
|
|
|
|
|
Formattable::Formattable(double value)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kDouble)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
fValue.fDouble = value;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a long value.
|
|
|
|
|
|
|
|
Formattable::Formattable(int32_t value)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kLong)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
2003-10-31 22:47:25 +00:00
|
|
|
fValue.fInt64 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a long value.
|
|
|
|
|
|
|
|
Formattable::Formattable(int64_t value)
|
|
|
|
: UObject(), fType(kInt64)
|
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
2003-10-31 22:47:25 +00:00
|
|
|
fValue.fInt64 = value;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a char* string.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
Formattable::Formattable(const char* stringToCopy)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kString)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
fValue.fString = new UnicodeString(stringToCopy);
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a UnicodeString instance.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
Formattable::Formattable(const UnicodeString& stringToCopy)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kString)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
fValue.fString = new UnicodeString(stringToCopy);
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Creates a formattable object with a UnicodeString* value.
|
|
|
|
// (adopting symantics)
|
|
|
|
|
|
|
|
Formattable::Formattable(UnicodeString* stringToAdopt)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kString)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
fValue.fString = stringToAdopt;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
Formattable::Formattable(const Formattable* arrayToCopy, int32_t count)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fType(kArray)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
fValue.fArrayAndCount.fArray = createArrayCopy(arrayToCopy, count);
|
|
|
|
fValue.fArrayAndCount.fCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// copy constructor
|
|
|
|
|
|
|
|
Formattable::Formattable(const Formattable &source)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(source), fType(kLong)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
fBogus.setToBogus();
|
1999-08-16 21:50:52 +00:00
|
|
|
*this = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// assignment operator
|
|
|
|
|
|
|
|
Formattable&
|
|
|
|
Formattable::operator=(const Formattable& source)
|
|
|
|
{
|
|
|
|
if (this != &source)
|
|
|
|
{
|
|
|
|
// Disposes the current formattable value/setting.
|
|
|
|
dispose();
|
|
|
|
|
|
|
|
// Sets the correct data type for this value.
|
|
|
|
fType = source.fType;
|
|
|
|
switch (fType)
|
|
|
|
{
|
|
|
|
case kArray:
|
|
|
|
// Sets each element in the array one by one and records the array count.
|
|
|
|
fValue.fArrayAndCount.fCount = source.fValue.fArrayAndCount.fCount;
|
|
|
|
fValue.fArrayAndCount.fArray = createArrayCopy(source.fValue.fArrayAndCount.fArray,
|
|
|
|
source.fValue.fArrayAndCount.fCount);
|
|
|
|
break;
|
|
|
|
case kString:
|
|
|
|
// Sets the string value.
|
|
|
|
fValue.fString = new UnicodeString(*source.fValue.fString);
|
|
|
|
break;
|
|
|
|
case kDouble:
|
|
|
|
// Sets the double value.
|
|
|
|
fValue.fDouble = source.fValue.fDouble;
|
|
|
|
break;
|
|
|
|
case kLong:
|
2003-11-04 23:10:46 +00:00
|
|
|
case kInt64:
|
1999-08-16 21:50:52 +00:00
|
|
|
// Sets the long value.
|
2003-10-31 22:47:25 +00:00
|
|
|
fValue.fInt64 = source.fValue.fInt64;
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
case kDate:
|
|
|
|
// Sets the Date value.
|
|
|
|
fValue.fDate = source.fValue.fDate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
Formattable::operator==(const Formattable& that) const
|
|
|
|
{
|
|
|
|
// Checks class ID.
|
|
|
|
if (this == &that) return TRUE;
|
|
|
|
|
|
|
|
// Returns FALSE if the data types are different.
|
|
|
|
if (fType != that.fType) return FALSE;
|
|
|
|
|
|
|
|
// Compares the actual data values.
|
|
|
|
switch (fType) {
|
|
|
|
case kDate:
|
|
|
|
return fValue.fDate == that.fValue.fDate;
|
|
|
|
case kDouble:
|
|
|
|
return fValue.fDouble == that.fValue.fDouble;
|
|
|
|
case kLong:
|
2003-11-04 23:10:46 +00:00
|
|
|
case kInt64:
|
2003-10-31 22:47:25 +00:00
|
|
|
return fValue.fInt64 == that.fValue.fInt64;
|
1999-08-16 21:50:52 +00:00
|
|
|
case kString:
|
|
|
|
return *(fValue.fString) == *(that.fValue.fString);
|
|
|
|
case kArray:
|
|
|
|
if (fValue.fArrayAndCount.fCount != that.fValue.fArrayAndCount.fCount)
|
|
|
|
return FALSE;
|
|
|
|
// Checks each element for equality.
|
|
|
|
for (int32_t i=0; i<fValue.fArrayAndCount.fCount; ++i)
|
|
|
|
if (fValue.fArrayAndCount.fArray[i] != that.fValue.fArrayAndCount.fArray[i])
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
Formattable::~Formattable()
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
void Formattable::dispose()
|
|
|
|
{
|
|
|
|
// Deletes the data value if necessary.
|
|
|
|
switch (fType) {
|
|
|
|
case kString:
|
|
|
|
delete fValue.fString;
|
|
|
|
break;
|
|
|
|
case kArray:
|
|
|
|
delete[] fValue.fArrayAndCount.fArray;
|
|
|
|
break;
|
2001-03-06 19:44:45 +00:00
|
|
|
case kDate:
|
|
|
|
case kDouble:
|
|
|
|
case kLong:
|
2003-11-26 22:57:27 +00:00
|
|
|
case kInt64:
|
2001-03-06 19:44:45 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-05 21:59:41 +00:00
|
|
|
Formattable *
|
|
|
|
Formattable::clone() const {
|
|
|
|
return new Formattable(*this);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Gets the data type of this Formattable object.
|
|
|
|
Formattable::Type
|
|
|
|
Formattable::getType() const
|
|
|
|
{
|
|
|
|
return fType;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
// -------------------------------------
|
|
|
|
int32_t
|
|
|
|
Formattable::getLong(UErrorCode* status) const
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (fType) {
|
|
|
|
case Formattable::kLong:
|
|
|
|
return (int32_t)fValue.fInt64;
|
|
|
|
case Formattable::kInt64:
|
|
|
|
if (fValue.fInt64 > INT32_MAX) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return INT32_MAX;
|
|
|
|
} else if (fValue.fInt64 < INT32_MIN) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return INT32_MIN;
|
|
|
|
} else {
|
|
|
|
return (int32_t)fValue.fInt64;
|
|
|
|
}
|
|
|
|
case Formattable::kDouble:
|
|
|
|
if (fValue.fDouble > INT32_MAX) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return INT32_MAX;
|
|
|
|
} else if (fValue.fDouble < INT32_MIN) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return INT32_MIN;
|
|
|
|
} else {
|
|
|
|
return (int32_t)fValue.fDouble;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
int64_t
|
|
|
|
Formattable::getInt64(UErrorCode* status) const
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (fType) {
|
|
|
|
case Formattable::kLong:
|
|
|
|
case Formattable::kInt64:
|
|
|
|
return fValue.fInt64;
|
|
|
|
case Formattable::kDouble:
|
2003-11-05 01:49:45 +00:00
|
|
|
if (fValue.fDouble > U_INT64_MAX) {
|
2003-11-04 23:10:46 +00:00
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2003-11-05 01:49:45 +00:00
|
|
|
return U_INT64_MAX;
|
|
|
|
} else if (fValue.fDouble < U_INT64_MIN) {
|
2003-11-04 23:10:46 +00:00
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2003-11-05 01:49:45 +00:00
|
|
|
return U_INT64_MIN;
|
2003-11-04 23:10:46 +00:00
|
|
|
} else {
|
|
|
|
return (int64_t)fValue.fDouble;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
double
|
|
|
|
Formattable::getDouble(UErrorCode* status) const
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (fType) {
|
|
|
|
case Formattable::kLong:
|
|
|
|
case Formattable::kInt64: // loses precision
|
|
|
|
return (double)fValue.fInt64;
|
|
|
|
case Formattable::kDouble:
|
|
|
|
return fValue.fDouble;
|
|
|
|
default:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Sets the value to a double value d.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
|
|
|
Formattable::setDouble(double d)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kDouble;
|
|
|
|
fValue.fDouble = d;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Sets the value to a long value l.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
|
|
|
Formattable::setLong(int32_t l)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kLong;
|
2003-10-31 22:47:25 +00:00
|
|
|
fValue.fInt64 = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Sets the value to an int64 value ll.
|
|
|
|
|
|
|
|
void
|
|
|
|
Formattable::setInt64(int64_t ll)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kInt64;
|
|
|
|
fValue.fInt64 = ll;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Sets the value to a Date instance d.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
|
|
|
Formattable::setDate(UDate d)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kDate;
|
|
|
|
fValue.fDate = d;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Sets the value to a string value stringToCopy.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
|
|
|
Formattable::setString(const UnicodeString& stringToCopy)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kString;
|
|
|
|
fValue.fString = new UnicodeString(stringToCopy);
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Sets the value to an array of Formattable objects.
|
|
|
|
|
|
|
|
void
|
|
|
|
Formattable::setArray(const Formattable* array, int32_t count)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kArray;
|
|
|
|
fValue.fArrayAndCount.fArray = createArrayCopy(array, count);
|
|
|
|
fValue.fArrayAndCount.fCount = count;
|
2001-03-06 19:44:45 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Adopts the stringToAdopt value.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
|
|
|
Formattable::adoptString(UnicodeString* stringToAdopt)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kString;
|
|
|
|
fValue.fString = stringToAdopt;
|
|
|
|
}
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// Adopts the array value and its count.
|
2001-03-06 19:44:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
|
|
|
Formattable::adoptArray(Formattable* array, int32_t count)
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
fType = kArray;
|
|
|
|
fValue.fArrayAndCount.fArray = array;
|
|
|
|
fValue.fArrayAndCount.fCount = count;
|
2001-03-06 19:44:45 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
// -------------------------------------
|
|
|
|
UnicodeString&
|
|
|
|
Formattable::getString(UnicodeString& result, UErrorCode* status) const
|
|
|
|
{
|
|
|
|
if (status && U_SUCCESS(*status) && fType != kString) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
result.setToBogus();
|
|
|
|
} else {
|
|
|
|
result = *fValue.fString;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
const UnicodeString&
|
|
|
|
Formattable::getString(UErrorCode* status) const
|
|
|
|
{
|
|
|
|
if (status && U_SUCCESS(*status) && fType != kString) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return *getBogus();
|
|
|
|
}
|
|
|
|
return *fValue.fString;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
UnicodeString&
|
|
|
|
Formattable::getString(UErrorCode* status)
|
|
|
|
{
|
|
|
|
if (status && U_SUCCESS(*status) && fType != kString) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return *getBogus();
|
|
|
|
}
|
|
|
|
return *fValue.fString;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
const Formattable*
|
|
|
|
Formattable::getArray(int32_t& count, UErrorCode* status) const
|
|
|
|
{
|
|
|
|
if (status && U_SUCCESS(*status) && fType != kArray) {
|
|
|
|
count = 0;
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
count = fValue.fArrayAndCount.fCount;
|
|
|
|
return fValue.fArrayAndCount.fArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Gets the bogus string, ensures mondo bogosity.
|
|
|
|
|
|
|
|
UnicodeString*
|
2003-11-26 22:57:27 +00:00
|
|
|
Formattable::getBogus() const
|
2003-11-04 23:10:46 +00:00
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
return (UnicodeString*)&fBogus; /* cast away const :-( */
|
2003-11-04 23:10:46 +00:00
|
|
|
}
|
|
|
|
|
2000-07-24 17:32:41 +00:00
|
|
|
#if 0
|
1999-08-16 21:50:52 +00:00
|
|
|
//----------------------------------------------------
|
|
|
|
// console I/O
|
|
|
|
//----------------------------------------------------
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
2000-04-25 21:33:15 +00:00
|
|
|
#if U_IOSTREAM_SOURCE >= 199711
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
#elif U_IOSTREAM_SOURCE >= 198506
|
2000-04-20 17:16:45 +00:00
|
|
|
#include <iostream.h>
|
2000-04-25 21:33:15 +00:00
|
|
|
#endif
|
2000-04-20 17:16:45 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/datefmt.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "unistrm.h"
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
class FormattableStreamer /* not : public UObject because all methods are static */ {
|
1999-08-16 21:50:52 +00:00
|
|
|
public:
|
|
|
|
static void streamOut(ostream& stream, const Formattable& obj);
|
2002-06-27 01:19:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FormattableStreamer() {} // private - forbid instantiation
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This is for debugging purposes only. This will send a displayable
|
|
|
|
// form of the Formattable object to the output stream.
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-07-24 17:32:41 +00:00
|
|
|
#endif
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//eof
|