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 
19 U_NAMESPACE_BEGIN
20 
CurrencyFormat(const Locale & locale,UErrorCode & ec)21 CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
22     MeasureFormat(locale, UMEASFMT_WIDTH_WIDE, ec), fmt(NULL)
23 {
24     fmt = NumberFormat::createCurrencyInstance(locale, ec);
25 }
26 
CurrencyFormat(const CurrencyFormat & other)27 CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
28     MeasureFormat(other), fmt(NULL)
29 {
30     fmt = (NumberFormat*) other.fmt->clone();
31 }
32 
~CurrencyFormat()33 CurrencyFormat::~CurrencyFormat() {
34     delete fmt;
35 }
36 
clone() const37 Format* CurrencyFormat::clone() const {
38     return new CurrencyFormat(*this);
39 }
40 
format(const Formattable & obj,UnicodeString & appendTo,FieldPosition & pos,UErrorCode & ec) const41 UnicodeString& 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 
parseObject(const UnicodeString & source,Formattable & result,ParsePosition & pos) const49 void 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 
59 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
60 
61 U_NAMESPACE_END
62 
63 #endif /* #if !UCONFIG_NO_FORMATTING */
64