+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
-* Copyright (C) 1997-2014, International Business Machines Corporation and others.
+* Copyright (C) 1997-2016, International Business Machines Corporation and others.
* All Rights Reserved.
********************************************************************************
*
class NumberFormatTest;
+#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
class SharedNumberFormat;
* formatting and parsing a number. Also provides methods for
* determining which locales have number formats, and what their names
* are.
+ * \headerfile unicode/numfmt.h "unicode/numfmt.h"
* <P>
* NumberFormat helps you to format and parse numbers for any locale.
* Your code can be completely independent of the locale conventions
* <P>
* To format a number for the current Locale, use one of the static
* factory methods:
- * <pre>
* \code
- * double myNumber = 7.0;
- * UnicodeString myString;
- * UErrorCode success = U_ZERO_ERROR;
- * NumberFormat* nf = NumberFormat::createInstance(success)
- * nf->format(myNumber, myString);
- * cout << " Example 1: " << myString << endl;
+ * #include <iostream>
+ * #include "unicode/numfmt.h"
+ * #include "unicode/unistr.h"
+ * #include "unicode/ustream.h"
+ * using namespace std;
+ *
+ * int main() {
+ * double myNumber = 7.0;
+ * UnicodeString myString;
+ * UErrorCode success = U_ZERO_ERROR;
+ * NumberFormat* nf = NumberFormat::createInstance(success);
+ * nf->format(myNumber, myString);
+ * cout << " Example 1: " << myString << endl;
+ * }
* \endcode
- * </pre>
* Note that there are additional factory methods within subclasses of
* NumberFormat.
* <P>
* the format and use it multiple times so that the system doesn't
* have to fetch the information about the local language and country
* conventions multiple times.
- * <pre>
* \code
* UnicodeString myString;
* UErrorCode success = U_ZERO_ERROR;
- * nf = NumberFormat::createInstance( success );
- * int32_t a[] = { 123, 3333, -1234567 };
- * const int32_t a_len = sizeof(a) / sizeof(a[0]);
- * myString.remove();
- * for (int32_t i = 0; i < a_len; i++) {
- * nf->format(a[i], myString);
- * myString += " ; ";
+ * NumberFormat *nf = NumberFormat::createInstance( success );
+ * for (int32_t number: {123, 3333, -1234567}) {
+ * nf->format(number, myString);
+ * myString += "; ";
* }
* cout << " Example 2: " << myString << endl;
* \endcode
- * </pre>
* To format a number for a different Locale, specify it in the
- * call to createInstance().
- * <pre>
+ * call to \c createInstance().
* \code
- * nf = NumberFormat::createInstance( Locale::FRENCH, success );
+ * nf = NumberFormat::createInstance(Locale::getFrench(), success);
* \endcode
- * </pre>
- * You can use a NumberFormat to parse also.
- * <pre>
+ * You can use a \c NumberFormat to parse also.
* \code
* UErrorCode success;
* Formattable result(-999); // initialized with error code
* nf->parse(myString, result, success);
* \endcode
- * </pre>
- * Use createInstance to get the normal number format for that country.
- * There are other static factory methods available. Use getCurrency
- * to get the currency number format for that country. Use getPercent
+ * Use \c createInstance() to get the normal number format for a \c Locale.
+ * There are other static factory methods available. Use \c createCurrencyInstance()
+ * to get the currency number format for that country. Use \c createPercentInstance()
* to get a format for displaying percentages. With this format, a
* fraction from 0.53 is displayed as 53%.
* <P>
- * Starting from ICU 4.2, you can use createInstance() by passing in a 'style'
- * as parameter to get the correct instance.
- * For example,
- * use createInstance(...kNumberStyle...) to get the normal number format,
- * createInstance(...kPercentStyle...) to get a format for displaying
- * percentage,
- * createInstance(...kScientificStyle...) to get a format for displaying
- * scientific number,
- * createInstance(...kCurrencyStyle...) to get the currency number format,
- * in which the currency is represented by its symbol, for example, "$3.00".
- * createInstance(...kIsoCurrencyStyle...) to get the currency number format,
- * in which the currency is represented by its ISO code, for example "USD3.00".
- * createInstance(...kPluralCurrencyStyle...) to get the currency number format,
+ * The type of number formatting can be specified by passing a 'style' parameter to \c createInstance().
+ * For example, use\n
+ * \c createInstance(locale, UNUM_DECIMAL, errorCode) to get the normal number format,\n
+ * \c createInstance(locale, UNUM_PERCENT, errorCode) to get a format for displaying percentage,\n
+ * \c createInstance(locale, UNUM_SCIENTIFIC, errorCode) to get a format for displaying scientific number,\n
+ * \c createInstance(locale, UNUM_CURRENCY, errorCode) to get the currency number format,
+ * in which the currency is represented by its symbol, for example, "$3.00".\n
+ * \c createInstance(locale, UNUM_CURRENCY_ISO, errorCode) to get the currency number format,
+ * in which the currency is represented by its ISO code, for example "USD3.00".\n
+ * \c createInstance(locale, UNUM_CURRENCY_PLURAL, errorCode) to get the currency number format,
* in which the currency is represented by its full name in plural format,
* for example, "3.00 US dollars" or "1.00 US dollar".
* <P>
* You can also control the display of numbers with such methods as
- * getMinimumFractionDigits. If you want even more control over the
+ * \c getMinimumFractionDigits(). If you want even more control over the
* format or parsing, or want to give your users more control, you can
- * try casting the NumberFormat you get from the factory methods to a
- * DecimalNumberFormat. This will work for the vast majority of
- * countries; just remember to put it in a try block in case you
+ * try dynamic_casting the \c NumberFormat you get from the factory methods to a
+ * \c DecimalFormat. This will work for the vast majority of
+ * countries; just remember to test for NULL in case you
* encounter an unusual one.
* <P>
* You can also use forms of the parse and format methods with
- * ParsePosition and FieldPosition to allow you to:
+ * \c ParsePosition and \c FieldPosition to allow you to:
* <ul type=round>
* <li>(a) progressively parse through pieces of a string.
* <li>(b) align the decimal point and other areas.
* For example, you can align numbers in two ways.
* <P>
* If you are using a monospaced font with spacing for alignment, you
- * can pass the FieldPosition in your format call, with field =
- * INTEGER_FIELD. On output, getEndIndex will be set to the offset
+ * can pass the \c FieldPosition in your format call, with field =
+ * \c UNUM_INTEGER_FIELD. On output, \c getEndIndex will be set to the offset
* between the last character of the integer and the decimal. Add
* (desiredSpaceCount - getEndIndex) spaces at the front of the
* string.
* NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
- * @stable 4.4
+ * @stable ICU 4.4
*/
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
- * @stable 4.4
+ * @stable ICU 4.4
*/
virtual UnicodeString& format(double number,
UnicodeString& appendTo,
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
- * @stable 4.4
+ * @stable ICU 4.4
*/
virtual UnicodeString& format(int32_t number,
UnicodeString& appendTo,
* Result is appended to existing contents.
* @param pos On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @internal
*/
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
- * @stable 4.4
+ * @stable ICU 4.4
*/
virtual UnicodeString& format(int64_t number,
UnicodeString& appendTo,
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
- * @stable 4.4
+ * @stable ICU 4.4
*/
- virtual UnicodeString& format(const StringPiece &number,
+ virtual UnicodeString& format(StringPiece number,
UnicodeString& appendTo,
FieldPositionIterator* posIter,
UErrorCode& status) const;
public:
/**
- * Format a decimal number.
+ * Format a decimal number.
* The number is a DigitList wrapper onto a floating point decimal number.
* The default implementation in NumberFormat converts the decimal number
* to a double and formats that. Subclasses of NumberFormat that want
UErrorCode& status) const;
/**
- * Format a decimal number.
+ * Format a decimal number.
* The number is a DigitList wrapper onto a floating point decimal number.
* The default implementation in NumberFormat converts the decimal number
* to a double and formats that. Subclasses of NumberFormat that want
/**
* Sets whether lenient parsing should be enabled (it is off by default).
*
- * @param enable <code>TRUE</code> if lenient parsing should be used,
- * <code>FALSE</code> otherwise.
+ * @param enable \c TRUE if lenient parsing should be used,
+ * \c FALSE otherwise.
* @stable ICU 4.8
*/
virtual void setLenient(UBool enable);
/**
* Returns whether lenient parsing is enabled (it is off by default).
*
- * @return <code>TRUE</code> if lenient parsing is enabled,
- * <code>FALSE</code> otherwise.
+ * @return \c TRUE if lenient parsing is enabled,
+ * \c FALSE otherwise.
* @see #setLenient
* @stable ICU 4.8
*/
virtual UBool isLenient(void) const;
/**
- * Returns the default number format for the current default
- * locale. The default format is one of the styles provided by
- * the other factory methods: getNumberInstance,
- * getCurrencyInstance or getPercentInstance. Exactly which one
- * is locale dependant.
+ * Create a default style NumberFormat for the current default locale.
+ * The default formatting style is locale dependent.
* @stable ICU 2.0
*/
static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
/**
- * Returns the default number format for the specified locale.
- * The default format is one of the styles provided by the other
- * factory methods: getNumberInstance, getCurrencyInstance or
- * getPercentInstance. Exactly which one is locale dependant.
+ * Create a default style NumberFormat for the specified locale.
+ * The default formatting style is locale dependent.
* @param inLocale the given locale.
* @stable ICU 2.0
*/
UErrorCode&);
/**
- * Creates the specified decimal format style of the desired locale.
+ * Create a specific style NumberFormat for the specified locale.
* @param desiredLocale the given locale.
* @param style the given style.
* @param errorCode Output param filled with success/failure status.
static const SharedNumberFormat* U_EXPORT2 createSharedInstance(
const Locale& inLocale, UNumberFormatStyle style, UErrorCode& status);
-#endif
+#endif /* U_HIDE_INTERNAL_API */
/**
* Returns a currency format for the current default locale.
* @param ec input-output error code
* @stable ICU 3.0
*/
- virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
+ virtual void setCurrency(const char16_t* theCurrency, UErrorCode& ec);
/**
* Gets the currency used to display currency
* the currency in use, or a pointer to the empty string.
* @stable ICU 2.6
*/
- const UChar* getCurrency() const;
-
- /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
+ const char16_t* getCurrency() const;
+
/**
* Set a particular UDisplayContext value in the formatter, such as
* UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
* @param value The UDisplayContext value to set.
* @param status Input/output status. If at entry this indicates a failure
* status, the function will do nothing; otherwise this will be
- * updated with any new status from the function.
- * @draft ICU 53
+ * updated with any new status from the function.
+ * @stable ICU 53
*/
virtual void setContext(UDisplayContext value, UErrorCode& status);
- /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
/**
* Get the formatter's UDisplayContext value for the specified UDisplayContextType,
* such as UDISPCTX_TYPE_CAPITALIZATION.
* @param type The UDisplayContextType whose value to return
* @param status Input/output status. If at entry this indicates a failure
* status, the function will do nothing; otherwise this will be
- * updated with any new status from the function.
+ * updated with any new status from the function.
* @return The UDisplayContextValue for the specified type.
- * @draft ICU 53
+ * @stable ICU 53
*/
virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
* have a capacity of at least 4
* @internal
*/
- virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
+ virtual void getEffectiveCurrency(char16_t* result, UErrorCode& ec) const;
#ifndef U_HIDE_INTERNAL_API
/**
int32_t fMinFractionDigits;
protected:
+ /** \internal */
static const int32_t gDefaultMaxIntegerDigits;
+ /** \internal */
static const int32_t gDefaultMinIntegerDigits;
-
+
private:
UBool fParseIntegerOnly;
UBool fLenient; // TRUE => lenient parse is enabled
// ISO currency code
- UChar fCurrency[4];
+ char16_t fCurrency[4];
UDisplayContext fCapitalizationContext;
}
U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */