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