// © 2018 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html #ifndef __NUMBERRANGEFORMATTER_H__ #define __NUMBERRANGEFORMATTER_H__ #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API #if !UCONFIG_NO_FORMATTING #include <atomic> #include "unicode/appendable.h" #include "unicode/fieldpos.h" #include "unicode/formattedvalue.h" #include "unicode/fpositer.h" #include "unicode/numberformatter.h" #include "unicode/unumberrangeformatter.h" /** * \file * \brief C++ API: Library for localized formatting of number, currency, and unit ranges. * * The main entrypoint to the formatting of ranges of numbers, including currencies and other units of measurement. * <p> * Usage example: * <p> * <pre> * NumberRangeFormatter::with() * .identityFallback(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE) * .numberFormatterFirst(NumberFormatter::with().adoptUnit(MeasureUnit::createMeter())) * .numberFormatterSecond(NumberFormatter::with().adoptUnit(MeasureUnit::createKilometer())) * .locale("en-GB") * .formatFormattableRange(750, 1.2, status) * .toString(status); * // => "750 m - 1.2 km" * </pre> * <p> * Like NumberFormatter, NumberRangeFormatter instances (i.e., LocalizedNumberRangeFormatter * and UnlocalizedNumberRangeFormatter) are immutable and thread-safe. This API is based on the * <em>fluent</em> design pattern popularized by libraries such as Google's Guava. * * @author Shane Carr */ U_NAMESPACE_BEGIN // Forward declarations: class PluralRules; namespace number { // icu::number // Forward declarations: class UnlocalizedNumberRangeFormatter; class LocalizedNumberRangeFormatter; class FormattedNumberRange; namespace impl { // Forward declarations: struct RangeMacroProps; class DecimalQuantity; class UFormattedNumberRangeData; class NumberRangeFormatterImpl; struct UFormattedNumberRangeImpl; } // namespace impl #if 0 /** * \cond * Export an explicit template instantiation. See datefmt.h * (When building DLLs for Windows this is required.) */ #if U_PLATFORM == U_PF_WINDOWS && !defined(U_IN_DOXYGEN) && !defined(U_STATIC_IMPLEMENTATION) } // namespace icu::number U_NAMESPACE_END template struct U_I18N_API std::atomic< U_NAMESPACE_QUALIFIER number::impl::NumberRangeFormatterImpl*>; U_NAMESPACE_BEGIN namespace number { // icu::number #endif /** \endcond */ #endif // Other helper classes would go here, but there are none. namespace impl { // icu::number::impl // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field /** @internal */ struct U_I18N_API RangeMacroProps : public UMemory { … }; } // namespace impl /** * An abstract base class for specifying settings related to number formatting. This class is implemented by * {@link UnlocalizedNumberRangeFormatter} and {@link LocalizedNumberRangeFormatter}. This class is not intended for * public subclassing. */ template<typename Derived> class U_I18N_API NumberRangeFormatterSettings { … }; // Explicit instantiations in source/i18n/numrange_fluent.cpp. // (MSVC treats imports/exports of explicit instantiations differently.) #ifndef _MSC_VER extern template class NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>; extern template class NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>; #endif /** * A NumberRangeFormatter that does not yet have a locale. In order to format, a locale must be specified. * * Instances of this class are immutable and thread-safe. * * @see NumberRangeFormatter * @stable ICU 63 */ class U_I18N_API UnlocalizedNumberRangeFormatter : public NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>, public UMemory { … }; /** * A NumberRangeFormatter that has a locale associated with it; this means .formatRange() methods are available. * * Instances of this class are immutable and thread-safe. * * @see NumberFormatter * @stable ICU 63 */ class U_I18N_API LocalizedNumberRangeFormatter : public NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>, public UMemory { … }; /** * The result of a number range formatting operation. This class allows the result to be exported in several data types, * including a UnicodeString and a FieldPositionIterator. * * Instances of this class are immutable and thread-safe. * * @stable ICU 63 */ class U_I18N_API FormattedNumberRange : public UMemory, public FormattedValue { … }; // inline impl of @stable ICU 68 method template<typename StringClass> std::pair<StringClass, StringClass> FormattedNumberRange::getDecimalNumbers(UErrorCode& status) const { … } /** * See the main description in numberrangeformatter.h for documentation and examples. * * @stable ICU 63 */ class U_I18N_API NumberRangeFormatter final { … }; } // namespace number U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ #endif /* U_SHOW_CPLUSPLUS_API */ #endif // __NUMBERRANGEFORMATTER_H__