]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/currfmt.cpp
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / currfmt.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
374ca955
A
3/*
4**********************************************************************
57a6839d 5* Copyright (c) 2004-2014 International Business Machines
374ca955
A
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"
4388f060 19#include "unicode/curramt.h"
374ca955
A
20
21U_NAMESPACE_BEGIN
22
23CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
57a6839d 24 MeasureFormat(locale, UMEASFMT_WIDTH_WIDE, ec), fmt(NULL)
46f4442e 25{
374ca955
A
26 fmt = NumberFormat::createCurrencyInstance(locale, ec);
27}
28
29CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
46f4442e
A
30 MeasureFormat(other), fmt(NULL)
31{
374ca955
A
32 fmt = (NumberFormat*) other.fmt->clone();
33}
34
35CurrencyFormat::~CurrencyFormat() {
36 delete fmt;
37}
38
374ca955
A
39Format* CurrencyFormat::clone() const {
40 return new CurrencyFormat(*this);
41}
42
43UnicodeString& CurrencyFormat::format(const Formattable& obj,
44 UnicodeString& appendTo,
45 FieldPosition& pos,
46f4442e
A
46 UErrorCode& ec) const
47{
374ca955
A
48 return fmt->format(obj, appendTo, pos, ec);
49}
50
374ca955
A
51void CurrencyFormat::parseObject(const UnicodeString& source,
52 Formattable& result,
46f4442e
A
53 ParsePosition& pos) const
54{
4388f060
A
55 CurrencyAmount* currAmt = fmt->parseCurrency(source, pos);
56 if (currAmt != NULL) {
57 result.adoptObject(currAmt);
58 }
374ca955
A
59}
60
374ca955
A
61UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
62
63U_NAMESPACE_END
64
65#endif /* #if !UCONFIG_NO_FORMATTING */