1/* 2********************************************************************** 3* Copyright (c) 2004-2014 International Business Machines 4* Corporation and others. All Rights Reserved. 5********************************************************************** 6* Author: Alan Liu 7* Created: April 20, 2004 8* Since: ICU 3.0 9********************************************************************** 10*/ 11#include "unicode/utypes.h" 12 13#if !UCONFIG_NO_FORMATTING 14 15#include "currfmt.h" 16#include "unicode/numfmt.h" 17#include "unicode/curramt.h" 18 19U_NAMESPACE_BEGIN 20 21CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) : 22 MeasureFormat(locale, UMEASFMT_WIDTH_WIDE, ec), fmt(NULL) 23{ 24 fmt = NumberFormat::createCurrencyInstance(locale, ec); 25} 26 27CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) : 28 MeasureFormat(other), fmt(NULL) 29{ 30 fmt = (NumberFormat*) other.fmt->clone(); 31} 32 33CurrencyFormat::~CurrencyFormat() { 34 delete fmt; 35} 36 37Format* CurrencyFormat::clone() const { 38 return new CurrencyFormat(*this); 39} 40 41UnicodeString& CurrencyFormat::format(const Formattable& obj, 42 UnicodeString& appendTo, 43 FieldPosition& pos, 44 UErrorCode& ec) const 45{ 46 return fmt->format(obj, appendTo, pos, ec); 47} 48 49void CurrencyFormat::parseObject(const UnicodeString& source, 50 Formattable& result, 51 ParsePosition& pos) const 52{ 53 CurrencyAmount* currAmt = fmt->parseCurrency(source, pos); 54 if (currAmt != NULL) { 55 result.adoptObject(currAmt); 56 } 57} 58 59UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat) 60 61U_NAMESPACE_END 62 63#endif /* #if !UCONFIG_NO_FORMATTING */ 64