1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMBER_ASFORMAT_H__
8 #define __NUMBER_ASFORMAT_H__
10 #include "unicode/numberformatter.h"
11 #include "number_types.h"
12 #include "number_decimalquantity.h"
13 #include "number_scientific.h"
14 #include "number_patternstring.h"
15 #include "number_modifiers.h"
16 #include "number_multiplier.h"
17 #include "number_roundingutils.h"
18 #include "decNumber.h"
21 U_NAMESPACE_BEGIN
namespace number
{
25 * A wrapper around LocalizedNumberFormatter implementing the Format interface, enabling improved
26 * compatibility with other APIs.
29 * @see NumberFormatter
31 class U_I18N_API LocalizedNumberFormatterAsFormat
: public Format
{
33 LocalizedNumberFormatterAsFormat(const LocalizedNumberFormatter
& formatter
, const Locale
& locale
);
38 ~LocalizedNumberFormatterAsFormat() U_OVERRIDE
;
43 UBool
operator==(const Format
& other
) const U_OVERRIDE
;
46 * Creates a copy of this object.
48 Format
* clone() const U_OVERRIDE
;
51 * Formats a Number using the wrapped LocalizedNumberFormatter. The provided formattable must be a
54 UnicodeString
& format(const Formattable
& obj
, UnicodeString
& appendTo
, FieldPosition
& pos
,
55 UErrorCode
& status
) const U_OVERRIDE
;
58 * Formats a Number using the wrapped LocalizedNumberFormatter. The provided formattable must be a
61 UnicodeString
& format(const Formattable
& obj
, UnicodeString
& appendTo
, FieldPositionIterator
* posIter
,
62 UErrorCode
& status
) const U_OVERRIDE
;
65 * Not supported: sets an error index and returns.
67 void parseObject(const UnicodeString
& source
, Formattable
& result
,
68 ParsePosition
& parse_pos
) const U_OVERRIDE
;
71 * Gets the LocalizedNumberFormatter that this wrapper class uses to format numbers.
73 * For maximum efficiency, this function returns by const reference. You must copy the return value
74 * into a local variable if you want to use it beyond the lifetime of the current object:
77 * LocalizedNumberFormatter localFormatter = fmt->getNumberFormatter();
80 * You can however use the return value directly when chaining:
83 * FormattedNumber result = fmt->getNumberFormatter().formatDouble(514.23, status);
86 * @return The unwrapped LocalizedNumberFormatter.
88 const LocalizedNumberFormatter
& getNumberFormatter() const;
90 UClassID
getDynamicClassID() const U_OVERRIDE
;
91 static UClassID U_EXPORT2
getStaticClassID();
94 LocalizedNumberFormatter fFormatter
;
96 // Even though the locale is inside the LocalizedNumberFormatter, we have to keep it here, too, because
97 // LocalizedNumberFormatter doesn't have a getLocale() method, and ICU-TC didn't want to add one.
102 } // namespace number
105 #endif // __NUMBER_ASFORMAT_H__
107 #endif /* #if !UCONFIG_NO_FORMATTING */