1 /*
2 **********************************************************************
3 * Copyright (c) 2004-2006, 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
18 U_NAMESPACE_BEGIN
19
CurrencyFormat(const Locale & locale,UErrorCode & ec)20 CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
21 fmt(NULL) {
22 fmt = NumberFormat::createCurrencyInstance(locale, ec);
23 }
24
CurrencyFormat(const CurrencyFormat & other)25 CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
26 MeasureFormat(other), fmt(NULL) {
27 fmt = (NumberFormat*) other.fmt->clone();
28 }
29
~CurrencyFormat()30 CurrencyFormat::~CurrencyFormat() {
31 delete fmt;
32 }
33
operator ==(const Format & other) const34 UBool CurrencyFormat::operator==(const Format& other) const {
35 if (this == &other) {
36 return TRUE;
37 }
38 if (other.getDynamicClassID() != CurrencyFormat::getStaticClassID()) {
39 return FALSE;
40 }
41 const CurrencyFormat* c = (const CurrencyFormat*) &other;
42 return *fmt == *c->fmt;
43 }
44
clone() const45 Format* CurrencyFormat::clone() const {
46 return new CurrencyFormat(*this);
47 }
48
format(const Formattable & obj,UnicodeString & appendTo,FieldPosition & pos,UErrorCode & ec) const49 UnicodeString& CurrencyFormat::format(const Formattable& obj,
50 UnicodeString& appendTo,
51 FieldPosition& pos,
52 UErrorCode& ec) const {
53 return fmt->format(obj, appendTo, pos, ec);
54 }
55
parseObject(const UnicodeString & source,Formattable & result,ParsePosition & pos) const56 void CurrencyFormat::parseObject(const UnicodeString& source,
57 Formattable& result,
58 ParsePosition& pos) const {
59 fmt->parseCurrency(source, result, pos);
60 }
61
62 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
63
64 U_NAMESPACE_END
65
66 #endif /* #if !UCONFIG_NO_FORMATTING */
67