OLD | NEW |
1 /* | 1 /* |
2 ********************************************************************** | 2 ********************************************************************** |
3 * Copyright (c) 2004-2012, International Business Machines | 3 * Copyright (c) 2004-2014, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 ********************************************************************** | 5 ********************************************************************** |
6 * Author: Alan Liu | 6 * Author: Alan Liu |
7 * Created: April 26, 2004 | 7 * Created: April 26, 2004 |
8 * Since: ICU 3.0 | 8 * Since: ICU 3.0 |
9 ********************************************************************** | 9 ********************************************************************** |
10 */ | 10 */ |
11 #include "utypeinfo.h" // for 'typeid' to work | |
12 | |
13 #include "unicode/utypes.h" | 11 #include "unicode/utypes.h" |
14 | 12 |
15 #if !UCONFIG_NO_FORMATTING | 13 #if !UCONFIG_NO_FORMATTING |
16 | 14 |
17 #include "unicode/currunit.h" | 15 #include "unicode/currunit.h" |
18 #include "unicode/ustring.h" | 16 #include "unicode/ustring.h" |
19 | 17 |
20 U_NAMESPACE_BEGIN | 18 U_NAMESPACE_BEGIN |
21 | 19 |
22 CurrencyUnit::CurrencyUnit(const UChar* _isoCode, UErrorCode& ec) { | 20 CurrencyUnit::CurrencyUnit(const UChar* _isoCode, UErrorCode& ec) { |
23 *isoCode = 0; | 21 *isoCode = 0; |
24 if (U_SUCCESS(ec)) { | 22 if (U_SUCCESS(ec)) { |
25 if (_isoCode && u_strlen(_isoCode)==3) { | 23 if (_isoCode && u_strlen(_isoCode)==3) { |
26 u_strcpy(isoCode, _isoCode); | 24 u_strcpy(isoCode, _isoCode); |
| 25 char simpleIsoCode[4]; |
| 26 u_UCharsToChars(isoCode, simpleIsoCode, 4); |
| 27 initCurrency(simpleIsoCode); |
27 } else { | 28 } else { |
28 ec = U_ILLEGAL_ARGUMENT_ERROR; | 29 ec = U_ILLEGAL_ARGUMENT_ERROR; |
29 } | 30 } |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) : | 34 CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) : |
34 MeasureUnit(other) { | 35 MeasureUnit(other) { |
35 *this = other; | 36 u_strcpy(isoCode, other.isoCode); |
36 } | 37 } |
37 | 38 |
38 CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) { | 39 CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) { |
39 if (this != &other) { | 40 if (this == &other) { |
40 u_strcpy(isoCode, other.isoCode); | 41 return *this; |
41 } | 42 } |
| 43 MeasureUnit::operator=(other); |
| 44 u_strcpy(isoCode, other.isoCode); |
42 return *this; | 45 return *this; |
43 } | 46 } |
44 | 47 |
45 UObject* CurrencyUnit::clone() const { | 48 UObject* CurrencyUnit::clone() const { |
46 return new CurrencyUnit(*this); | 49 return new CurrencyUnit(*this); |
47 } | 50 } |
48 | 51 |
49 CurrencyUnit::~CurrencyUnit() { | 52 CurrencyUnit::~CurrencyUnit() { |
50 } | 53 } |
51 | 54 |
52 UBool CurrencyUnit::operator==(const UObject& other) const { | |
53 const CurrencyUnit& c = (const CurrencyUnit&) other; | |
54 return typeid(*this) == typeid(other) && | |
55 u_strcmp(isoCode, c.isoCode) == 0; | |
56 } | |
57 | |
58 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyUnit) | 55 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyUnit) |
59 | 56 |
60 U_NAMESPACE_END | 57 U_NAMESPACE_END |
61 | 58 |
62 #endif // !UCONFIG_NO_FORMATTING | 59 #endif // !UCONFIG_NO_FORMATTING |
OLD | NEW |