]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /* |
2 | ********************************************************************** | |
4388f060 | 3 | * Copyright (c) 2004-2012 International Business Machines |
374ca955 A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | * Author: Alan Liu | |
7 | * Created: April 20, 2004 | |
8 | * Since: ICU 3.0 | |
9 | ********************************************************************** | |
10 | */ | |
729e4ab9 A |
11 | #include <typeinfo> // for 'typeid' to work |
12 | ||
374ca955 A |
13 | #include "unicode/utypes.h" |
14 | ||
15 | #if !UCONFIG_NO_FORMATTING | |
16 | ||
17 | #include "currfmt.h" | |
18 | #include "unicode/numfmt.h" | |
4388f060 | 19 | #include "unicode/curramt.h" |
374ca955 A |
20 | |
21 | U_NAMESPACE_BEGIN | |
22 | ||
23 | CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) : | |
46f4442e A |
24 | fmt(NULL) |
25 | { | |
374ca955 A |
26 | fmt = NumberFormat::createCurrencyInstance(locale, ec); |
27 | } | |
28 | ||
29 | CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) : | |
46f4442e A |
30 | MeasureFormat(other), fmt(NULL) |
31 | { | |
374ca955 A |
32 | fmt = (NumberFormat*) other.fmt->clone(); |
33 | } | |
34 | ||
35 | CurrencyFormat::~CurrencyFormat() { | |
36 | delete fmt; | |
37 | } | |
38 | ||
39 | UBool CurrencyFormat::operator==(const Format& other) const { | |
40 | if (this == &other) { | |
41 | return TRUE; | |
42 | } | |
729e4ab9 | 43 | if (typeid(*this) != typeid(other)) { |
374ca955 A |
44 | return FALSE; |
45 | } | |
46 | const CurrencyFormat* c = (const CurrencyFormat*) &other; | |
47 | return *fmt == *c->fmt; | |
48 | } | |
49 | ||
50 | Format* CurrencyFormat::clone() const { | |
51 | return new CurrencyFormat(*this); | |
52 | } | |
53 | ||
54 | UnicodeString& CurrencyFormat::format(const Formattable& obj, | |
55 | UnicodeString& appendTo, | |
56 | FieldPosition& pos, | |
46f4442e A |
57 | UErrorCode& ec) const |
58 | { | |
374ca955 A |
59 | return fmt->format(obj, appendTo, pos, ec); |
60 | } | |
61 | ||
374ca955 A |
62 | void CurrencyFormat::parseObject(const UnicodeString& source, |
63 | Formattable& result, | |
46f4442e A |
64 | ParsePosition& pos) const |
65 | { | |
4388f060 A |
66 | CurrencyAmount* currAmt = fmt->parseCurrency(source, pos); |
67 | if (currAmt != NULL) { | |
68 | result.adoptObject(currAmt); | |
69 | } | |
374ca955 A |
70 | } |
71 | ||
374ca955 A |
72 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat) |
73 | ||
74 | U_NAMESPACE_END | |
75 | ||
76 | #endif /* #if !UCONFIG_NO_FORMATTING */ |