2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2004-04-21 18:05:06 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 2004-2014 International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2004-04-21 18:05:06 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Author: Alan Liu
|
|
|
|
* Created: April 20, 2004
|
|
|
|
* Since: ICU 3.0
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "currfmt.h"
|
|
|
|
#include "unicode/numfmt.h"
|
2012-02-19 06:45:47 +00:00
|
|
|
#include "unicode/curramt.h"
|
2004-04-21 18:05:06 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
|
2014-02-04 00:29:17 +00:00
|
|
|
MeasureFormat(locale, UMEASFMT_WIDTH_WIDE, ec), fmt(NULL)
|
2008-02-23 19:15:18 +00:00
|
|
|
{
|
2004-04-21 18:05:06 +00:00
|
|
|
fmt = NumberFormat::createCurrencyInstance(locale, ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
|
2008-02-23 19:15:18 +00:00
|
|
|
MeasureFormat(other), fmt(NULL)
|
|
|
|
{
|
2004-04-21 18:05:06 +00:00
|
|
|
fmt = (NumberFormat*) other.fmt->clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrencyFormat::~CurrencyFormat() {
|
2008-02-23 19:15:18 +00:00
|
|
|
delete fmt;
|
2004-04-21 18:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Format* CurrencyFormat::clone() const {
|
|
|
|
return new CurrencyFormat(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString& CurrencyFormat::format(const Formattable& obj,
|
|
|
|
UnicodeString& appendTo,
|
|
|
|
FieldPosition& pos,
|
2008-02-23 19:15:18 +00:00
|
|
|
UErrorCode& ec) const
|
|
|
|
{
|
|
|
|
return fmt->format(obj, appendTo, pos, ec);
|
2004-04-21 18:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CurrencyFormat::parseObject(const UnicodeString& source,
|
|
|
|
Formattable& result,
|
2008-02-23 19:15:18 +00:00
|
|
|
ParsePosition& pos) const
|
|
|
|
{
|
2012-02-19 06:45:47 +00:00
|
|
|
CurrencyAmount* currAmt = fmt->parseCurrency(source, pos);
|
|
|
|
if (currAmt != NULL) {
|
|
|
|
result.adoptObject(currAmt);
|
|
|
|
}
|
2004-04-21 18:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|