1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/currfmt.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* 1.5 +********************************************************************** 1.6 +* Copyright (c) 2004-2012 International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +********************************************************************** 1.9 +* Author: Alan Liu 1.10 +* Created: April 20, 2004 1.11 +* Since: ICU 3.0 1.12 +********************************************************************** 1.13 +*/ 1.14 +#include "utypeinfo.h" // for 'typeid' to work 1.15 + 1.16 +#include "unicode/utypes.h" 1.17 + 1.18 +#if !UCONFIG_NO_FORMATTING 1.19 + 1.20 +#include "currfmt.h" 1.21 +#include "unicode/numfmt.h" 1.22 +#include "unicode/curramt.h" 1.23 + 1.24 +U_NAMESPACE_BEGIN 1.25 + 1.26 +CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) : 1.27 + fmt(NULL) 1.28 +{ 1.29 + fmt = NumberFormat::createCurrencyInstance(locale, ec); 1.30 +} 1.31 + 1.32 +CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) : 1.33 + MeasureFormat(other), fmt(NULL) 1.34 +{ 1.35 + fmt = (NumberFormat*) other.fmt->clone(); 1.36 +} 1.37 + 1.38 +CurrencyFormat::~CurrencyFormat() { 1.39 + delete fmt; 1.40 +} 1.41 + 1.42 +UBool CurrencyFormat::operator==(const Format& other) const { 1.43 + if (this == &other) { 1.44 + return TRUE; 1.45 + } 1.46 + if (typeid(*this) != typeid(other)) { 1.47 + return FALSE; 1.48 + } 1.49 + const CurrencyFormat* c = (const CurrencyFormat*) &other; 1.50 + return *fmt == *c->fmt; 1.51 +} 1.52 + 1.53 +Format* CurrencyFormat::clone() const { 1.54 + return new CurrencyFormat(*this); 1.55 +} 1.56 + 1.57 +UnicodeString& CurrencyFormat::format(const Formattable& obj, 1.58 + UnicodeString& appendTo, 1.59 + FieldPosition& pos, 1.60 + UErrorCode& ec) const 1.61 +{ 1.62 + return fmt->format(obj, appendTo, pos, ec); 1.63 +} 1.64 + 1.65 +void CurrencyFormat::parseObject(const UnicodeString& source, 1.66 + Formattable& result, 1.67 + ParsePosition& pos) const 1.68 +{ 1.69 + CurrencyAmount* currAmt = fmt->parseCurrency(source, pos); 1.70 + if (currAmt != NULL) { 1.71 + result.adoptObject(currAmt); 1.72 + } 1.73 +} 1.74 + 1.75 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat) 1.76 + 1.77 +U_NAMESPACE_END 1.78 + 1.79 +#endif /* #if !UCONFIG_NO_FORMATTING */