1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #ifndef __NUMBERRANGEFORMATTER_H__
5 #define __NUMBERRANGEFORMATTER_H__
7 #include "unicode/utypes.h"
9 #if U_SHOW_CPLUSPLUS_API
11 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/appendable.h"
15 #include "unicode/fieldpos.h"
16 #include "unicode/formattedvalue.h"
17 #include "unicode/fpositer.h"
18 #include "unicode/numberformatter.h"
22 * \brief C++ API: Library for localized formatting of number, currency, and unit ranges.
24 * The main entrypoint to the formatting of ranges of numbers, including currencies and other units of measurement.
29 * NumberRangeFormatter::with()
30 * .identityFallback(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE)
31 * .numberFormatterFirst(NumberFormatter::with().adoptUnit(MeasureUnit::createMeter()))
32 * .numberFormatterSecond(NumberFormatter::with().adoptUnit(MeasureUnit::createKilometer()))
34 * .formatRange(750, 1.2, status)
36 * // => "750 m - 1.2 km"
39 * Like NumberFormatter, NumberRangeFormatter instances (i.e., LocalizedNumberRangeFormatter
40 * and UnlocalizedNumberRangeFormatter) are immutable and thread-safe. This API is based on the
41 * <em>fluent</em> design pattern popularized by libraries such as Google's Guava.
48 * Defines how to merge fields that are identical across the range sign.
52 typedef enum UNumberRangeCollapse
{
54 * Use locale data and heuristics to determine how much of the string to collapse. Could end up collapsing none,
55 * some, or all repeated pieces in a locale-sensitive way.
57 * The heuristics used for this option are subject to change over time.
61 UNUM_RANGE_COLLAPSE_AUTO
,
64 * Do not collapse any part of the number. Example: "3.2 thousand kilograms – 5.3 thousand kilograms"
68 UNUM_RANGE_COLLAPSE_NONE
,
71 * Collapse the unit part of the number, but not the notation, if present. Example: "3.2 thousand – 5.3 thousand
76 UNUM_RANGE_COLLAPSE_UNIT
,
79 * Collapse any field that is equal across the range sign. May introduce ambiguity on the magnitude of the
80 * number. Example: "3.2 – 5.3 thousand kilograms"
84 UNUM_RANGE_COLLAPSE_ALL
85 } UNumberRangeCollapse
;
88 * Defines the behavior when the two numbers in the range are identical after rounding. To programmatically detect
89 * when the identity fallback is used, compare the lower and upper BigDecimals via FormattedNumber.
92 * @see NumberRangeFormatter
94 typedef enum UNumberRangeIdentityFallback
{
96 * Show the number as a single value rather than a range. Example: "$5"
100 UNUM_IDENTITY_FALLBACK_SINGLE_VALUE
,
103 * Show the number using a locale-sensitive approximation pattern. If the numbers were the same before rounding,
104 * show the single value. Example: "~$5" or "$5"
108 UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE
,
111 * Show the number using a locale-sensitive approximation pattern. Use the range pattern always, even if the
112 * inputs are the same. Example: "~$5"
116 UNUM_IDENTITY_FALLBACK_APPROXIMATELY
,
119 * Show the number as the range of two equal values. Use the range pattern always, even if the inputs are the
120 * same. Example (with RangeCollapse.NONE): "$5 – $5"
124 UNUM_IDENTITY_FALLBACK_RANGE
125 } UNumberRangeIdentityFallback
;
128 * Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted in the range
129 * were equal or not, and whether or not the identity fallback was applied.
132 * @see NumberRangeFormatter
134 typedef enum UNumberRangeIdentityResult
{
136 * Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.
139 * @see NumberRangeFormatter
141 UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING
,
144 * Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied.
147 * @see NumberRangeFormatter
149 UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING
,
152 * Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied.
155 * @see NumberRangeFormatter
157 UNUM_IDENTITY_RESULT_NOT_EQUAL
,
159 #ifndef U_HIDE_INTERNAL_API
161 * The number of entries in this enum.
164 UNUM_IDENTITY_RESULT_COUNT
167 } UNumberRangeIdentityResult
;
171 namespace number
{ // icu::number
173 // Forward declarations:
174 class UnlocalizedNumberRangeFormatter
;
175 class LocalizedNumberRangeFormatter
;
176 class FormattedNumberRange
;
180 // Forward declarations:
181 struct RangeMacroProps
;
182 class DecimalQuantity
;
183 class UFormattedNumberRangeData
;
184 class NumberRangeFormatterImpl
;
190 * Export an explicit template instantiation. See datefmt.h
191 * (When building DLLs for Windows this is required.)
193 #if U_PLATFORM == U_PF_WINDOWS && !defined(U_IN_DOXYGEN)
194 } // namespace icu::number
197 template struct U_I18N_API
std::atomic
< U_NAMESPACE_QUALIFIER
number::impl::NumberRangeFormatterImpl
*>;
200 namespace number
{ // icu::number
204 // Other helper classes would go here, but there are none.
206 namespace impl
{ // icu::number::impl
208 // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
210 struct U_I18N_API RangeMacroProps
: public UMemory
{
212 UnlocalizedNumberFormatter formatter1
; // = NumberFormatter::with();
215 UnlocalizedNumberFormatter formatter2
; // = NumberFormatter::with();
218 bool singleFormatter
= true;
221 UNumberRangeCollapse collapse
= UNUM_RANGE_COLLAPSE_AUTO
;
224 UNumberRangeIdentityFallback identityFallback
= UNUM_IDENTITY_FALLBACK_APPROXIMATELY
;
229 // NOTE: Uses default copy and move constructors.
232 * Check all members for errors.
235 bool copyErrorTo(UErrorCode
&status
) const {
236 return formatter1
.copyErrorTo(status
) || formatter2
.copyErrorTo(status
);
243 * An abstract base class for specifying settings related to number formatting. This class is implemented by
244 * {@link UnlocalizedNumberRangeFormatter} and {@link LocalizedNumberRangeFormatter}. This class is not intended for
245 * public subclassing.
247 template<typename Derived
>
248 class U_I18N_API NumberRangeFormatterSettings
{
251 * Sets the NumberFormatter instance to use for the numbers in the range. The same formatter is applied to both
252 * sides of the range.
254 * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
255 * NumberRangeFormatter will be used.
258 * The formatter to use for both numbers in the range.
259 * @return The fluent chain.
262 Derived
numberFormatterBoth(const UnlocalizedNumberFormatter
&formatter
) const &;
265 * Overload of numberFormatterBoth() for use on an rvalue reference.
268 * The formatter to use for both numbers in the range.
269 * @return The fluent chain.
270 * @see #numberFormatterBoth
273 Derived
numberFormatterBoth(const UnlocalizedNumberFormatter
&formatter
) &&;
276 * Overload of numberFormatterBoth() for use on an rvalue reference.
279 * The formatter to use for both numbers in the range.
280 * @return The fluent chain.
281 * @see #numberFormatterBoth
284 Derived
numberFormatterBoth(UnlocalizedNumberFormatter
&&formatter
) const &;
287 * Overload of numberFormatterBoth() for use on an rvalue reference.
290 * The formatter to use for both numbers in the range.
291 * @return The fluent chain.
292 * @see #numberFormatterBoth
295 Derived
numberFormatterBoth(UnlocalizedNumberFormatter
&&formatter
) &&;
298 * Sets the NumberFormatter instance to use for the first number in the range.
300 * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
301 * NumberRangeFormatter will be used.
303 * @param formatterFirst
304 * The formatter to use for the first number in the range.
305 * @return The fluent chain.
308 Derived
numberFormatterFirst(const UnlocalizedNumberFormatter
&formatterFirst
) const &;
311 * Overload of numberFormatterFirst() for use on an rvalue reference.
313 * @param formatterFirst
314 * The formatter to use for the first number in the range.
315 * @return The fluent chain.
316 * @see #numberFormatterFirst
319 Derived
numberFormatterFirst(const UnlocalizedNumberFormatter
&formatterFirst
) &&;
322 * Overload of numberFormatterFirst() for use on an rvalue reference.
324 * @param formatterFirst
325 * The formatter to use for the first number in the range.
326 * @return The fluent chain.
327 * @see #numberFormatterFirst
330 Derived
numberFormatterFirst(UnlocalizedNumberFormatter
&&formatterFirst
) const &;
333 * Overload of numberFormatterFirst() for use on an rvalue reference.
335 * @param formatterFirst
336 * The formatter to use for the first number in the range.
337 * @return The fluent chain.
338 * @see #numberFormatterFirst
341 Derived
numberFormatterFirst(UnlocalizedNumberFormatter
&&formatterFirst
) &&;
344 * Sets the NumberFormatter instance to use for the second number in the range.
346 * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
347 * NumberRangeFormatter will be used.
349 * @param formatterSecond
350 * The formatter to use for the second number in the range.
351 * @return The fluent chain.
354 Derived
numberFormatterSecond(const UnlocalizedNumberFormatter
&formatterSecond
) const &;
357 * Overload of numberFormatterSecond() for use on an rvalue reference.
359 * @param formatterSecond
360 * The formatter to use for the second number in the range.
361 * @return The fluent chain.
362 * @see #numberFormatterSecond
365 Derived
numberFormatterSecond(const UnlocalizedNumberFormatter
&formatterSecond
) &&;
368 * Overload of numberFormatterSecond() for use on an rvalue reference.
370 * @param formatterSecond
371 * The formatter to use for the second number in the range.
372 * @return The fluent chain.
373 * @see #numberFormatterSecond
376 Derived
numberFormatterSecond(UnlocalizedNumberFormatter
&&formatterSecond
) const &;
379 * Overload of numberFormatterSecond() for use on an rvalue reference.
381 * @param formatterSecond
382 * The formatter to use for the second number in the range.
383 * @return The fluent chain.
384 * @see #numberFormatterSecond
387 Derived
numberFormatterSecond(UnlocalizedNumberFormatter
&&formatterSecond
) &&;
390 * Sets the aggressiveness of "collapsing" fields across the range separator. Possible values:
393 * <li>ALL: "3-5K miles"</li>
394 * <li>UNIT: "3K - 5K miles"</li>
395 * <li>NONE: "3K miles - 5K miles"</li>
396 * <li>AUTO: usually UNIT or NONE, depending on the locale and formatter settings</li>
399 * The default value is AUTO.
402 * The collapsing strategy to use for this range.
403 * @return The fluent chain.
406 Derived
collapse(UNumberRangeCollapse collapse
) const &;
409 * Overload of collapse() for use on an rvalue reference.
412 * The collapsing strategy to use for this range.
413 * @return The fluent chain.
417 Derived
collapse(UNumberRangeCollapse collapse
) &&;
420 * Sets the behavior when the two sides of the range are the same. This could happen if the same two numbers are
421 * passed to the formatRange function, or if different numbers are passed to the function but they become the same
422 * after rounding rules are applied. Possible values:
425 * <li>SINGLE_VALUE: "5 miles"</li>
426 * <li>APPROXIMATELY_OR_SINGLE_VALUE: "~5 miles" or "5 miles", depending on whether the number was the same before
427 * rounding was applied</li>
428 * <li>APPROXIMATELY: "~5 miles"</li>
429 * <li>RANGE: "5-5 miles" (with collapse=UNIT)</li>
432 * The default value is APPROXIMATELY.
434 * @param identityFallback
435 * The strategy to use when formatting two numbers that end up being the same.
436 * @return The fluent chain.
439 Derived
identityFallback(UNumberRangeIdentityFallback identityFallback
) const &;
442 * Overload of identityFallback() for use on an rvalue reference.
444 * @param identityFallback
445 * The strategy to use when formatting two numbers that end up being the same.
446 * @return The fluent chain.
447 * @see #identityFallback
450 Derived
identityFallback(UNumberRangeIdentityFallback identityFallback
) &&;
452 #ifndef U_HIDE_DRAFT_API
454 * Returns the current (Un)LocalizedNumberRangeFormatter as a LocalPointer
455 * wrapping a heap-allocated copy of the current object.
457 * This is equivalent to new-ing the move constructor with a value object
460 * @return A wrapped (Un)LocalizedNumberRangeFormatter pointer, or a wrapped
461 * nullptr on failure.
464 LocalPointer
<Derived
> clone() const &;
467 * Overload of clone for use on an rvalue reference.
469 * @return A wrapped (Un)LocalizedNumberRangeFormatter pointer, or a wrapped
470 * nullptr on failure.
473 LocalPointer
<Derived
> clone() &&;
474 #endif /* U_HIDE_DRAFT_API */
477 * Sets the UErrorCode if an error occurred in the fluent chain.
478 * Preserves older error codes in the outErrorCode.
479 * @return TRUE if U_FAILURE(outErrorCode)
482 UBool
copyErrorTo(UErrorCode
&outErrorCode
) const {
483 if (U_FAILURE(outErrorCode
)) {
484 // Do not overwrite the older error code
487 fMacros
.copyErrorTo(outErrorCode
);
488 return U_FAILURE(outErrorCode
);
491 // NOTE: Uses default copy and move constructors.
494 impl::RangeMacroProps fMacros
;
496 // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
497 NumberRangeFormatterSettings() = default;
499 friend class LocalizedNumberRangeFormatter
;
500 friend class UnlocalizedNumberRangeFormatter
;
504 * A NumberRangeFormatter that does not yet have a locale. In order to format, a locale must be specified.
506 * Instances of this class are immutable and thread-safe.
508 * @see NumberRangeFormatter
511 class U_I18N_API UnlocalizedNumberRangeFormatter
512 : public NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>, public UMemory
{
516 * Associate the given locale with the number range formatter. The locale is used for picking the
517 * appropriate symbols, formats, and other data for number display.
520 * The locale to use when loading data for number formatting.
521 * @return The fluent chain.
524 LocalizedNumberRangeFormatter
locale(const icu::Locale
&locale
) const &;
527 * Overload of locale() for use on an rvalue reference.
530 * The locale to use when loading data for number formatting.
531 * @return The fluent chain.
535 LocalizedNumberRangeFormatter
locale(const icu::Locale
&locale
) &&;
538 * Default constructor: puts the formatter into a valid but undefined state.
542 UnlocalizedNumberRangeFormatter() = default;
545 * Returns a copy of this UnlocalizedNumberRangeFormatter.
548 UnlocalizedNumberRangeFormatter(const UnlocalizedNumberRangeFormatter
&other
);
552 * The source UnlocalizedNumberRangeFormatter will be left in a valid but undefined state.
555 UnlocalizedNumberRangeFormatter(UnlocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
558 * Copy assignment operator.
561 UnlocalizedNumberRangeFormatter
& operator=(const UnlocalizedNumberRangeFormatter
& other
);
564 * Move assignment operator:
565 * The source UnlocalizedNumberRangeFormatter will be left in a valid but undefined state.
568 UnlocalizedNumberRangeFormatter
& operator=(UnlocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
571 explicit UnlocalizedNumberRangeFormatter(
572 const NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>& other
);
574 explicit UnlocalizedNumberRangeFormatter(
575 NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>&& src
) U_NOEXCEPT
;
577 // To give the fluent setters access to this class's constructor:
578 friend class NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>;
580 // To give NumberRangeFormatter::with() access to this class's constructor:
581 friend class NumberRangeFormatter
;
585 * A NumberRangeFormatter that has a locale associated with it; this means .formatRange() methods are available.
587 * Instances of this class are immutable and thread-safe.
589 * @see NumberFormatter
592 class U_I18N_API LocalizedNumberRangeFormatter
593 : public NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>, public UMemory
{
596 * Format the given Formattables to a string using the settings specified in the NumberRangeFormatter fluent setting
600 * The first number in the range, usually to the left in LTR locales.
602 * The second number in the range, usually to the right in LTR locales.
604 * Set if an error occurs while formatting.
605 * @return A FormattedNumberRange object; call .toString() to get the string.
608 FormattedNumberRange
formatFormattableRange(
609 const Formattable
& first
, const Formattable
& second
, UErrorCode
& status
) const;
612 * Default constructor: puts the formatter into a valid but undefined state.
616 LocalizedNumberRangeFormatter() = default;
619 * Returns a copy of this LocalizedNumberRangeFormatter.
622 LocalizedNumberRangeFormatter(const LocalizedNumberRangeFormatter
&other
);
626 * The source LocalizedNumberRangeFormatter will be left in a valid but undefined state.
629 LocalizedNumberRangeFormatter(LocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
632 * Copy assignment operator.
635 LocalizedNumberRangeFormatter
& operator=(const LocalizedNumberRangeFormatter
& other
);
638 * Move assignment operator:
639 * The source LocalizedNumberRangeFormatter will be left in a valid but undefined state.
642 LocalizedNumberRangeFormatter
& operator=(LocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
644 #ifndef U_HIDE_INTERNAL_API
648 * The results object. This method will mutate it to save the results.
649 * @param equalBeforeRounding
650 * Whether the number was equal before copying it into a DecimalQuantity.
651 * Used for determining the identity fallback behavior.
653 * Set if an error occurs while formatting.
656 void formatImpl(impl::UFormattedNumberRangeData
& results
, bool equalBeforeRounding
,
657 UErrorCode
& status
) const;
659 #endif /* U_HIDE_INTERNAL_API */
662 * Destruct this LocalizedNumberRangeFormatter, cleaning up any memory it might own.
665 ~LocalizedNumberRangeFormatter();
668 std::atomic
<impl::NumberRangeFormatterImpl
*> fAtomicFormatter
= {};
670 const impl::NumberRangeFormatterImpl
* getFormatter(UErrorCode
& stauts
) const;
672 explicit LocalizedNumberRangeFormatter(
673 const NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>& other
);
675 explicit LocalizedNumberRangeFormatter(
676 NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>&& src
) U_NOEXCEPT
;
678 LocalizedNumberRangeFormatter(const impl::RangeMacroProps
¯os
, const Locale
&locale
);
680 LocalizedNumberRangeFormatter(impl::RangeMacroProps
&¯os
, const Locale
&locale
);
684 // To give the fluent setters access to this class's constructor:
685 friend class NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>;
686 friend class NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>;
688 // To give UnlocalizedNumberRangeFormatter::locale() access to this class's constructor:
689 friend class UnlocalizedNumberRangeFormatter
;
693 * The result of a number range formatting operation. This class allows the result to be exported in several data types,
694 * including a UnicodeString and a FieldPositionIterator.
696 * Instances of this class are immutable and thread-safe.
700 class U_I18N_API FormattedNumberRange
: public UMemory
, public FormattedValue
{
702 // Copybrief: this method is older than the parent method
704 * @copybrief FormattedValue::toString()
706 * For more information, see FormattedValue::toString()
710 UnicodeString
toString(UErrorCode
& status
) const U_OVERRIDE
;
712 // Copydoc: this method is new in ICU 64
713 /** @copydoc FormattedValue::toTempString() */
714 UnicodeString
toTempString(UErrorCode
& status
) const U_OVERRIDE
;
716 // Copybrief: this method is older than the parent method
718 * @copybrief FormattedValue::appendTo()
720 * For more information, see FormattedValue::appendTo()
724 Appendable
&appendTo(Appendable
&appendable
, UErrorCode
& status
) const U_OVERRIDE
;
726 // Copydoc: this method is new in ICU 64
727 /** @copydoc FormattedValue::nextPosition() */
728 UBool
nextPosition(ConstrainedFieldPosition
& cfpos
, UErrorCode
& status
) const U_OVERRIDE
;
730 #ifndef U_HIDE_DRAFT_API
732 * Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given
733 * <em>field</em> in the output string. This allows you to determine the locations of, for example,
734 * the integer part, fraction part, or symbols.
736 * If both sides of the range have the same field, the field will occur twice, once before the
737 * range separator and once after the range separator, if applicable.
739 * If a field occurs just once, calling this method will find that occurrence and return it. If a
740 * field occurs multiple times, this method may be called repeatedly with the following pattern:
743 * FieldPosition fpos(UNUM_INTEGER_FIELD);
744 * while (formattedNumberRange.nextFieldPosition(fpos, status)) {
745 * // do something with fpos.
749 * This method is useful if you know which field to query. If you want all available field position
750 * information, use #getAllFieldPositions().
752 * @param fieldPosition
753 * Input+output variable. See {@link FormattedNumber#nextFieldPosition}.
755 * Set if an error occurs while populating the FieldPosition.
756 * @return TRUE if a new occurrence of the field was found; FALSE otherwise.
758 * @see UNumberFormatFields
760 UBool
nextFieldPosition(FieldPosition
& fieldPosition
, UErrorCode
& status
) const;
763 * Export the formatted number range to a FieldPositionIterator. This allows you to determine which characters in
764 * the output string correspond to which <em>fields</em>, such as the integer part, fraction part, and sign.
766 * If information on only one field is needed, use #nextFieldPosition() instead.
769 * The FieldPositionIterator to populate with all of the fields present in the formatted number.
771 * Set if an error occurs while populating the FieldPositionIterator.
773 * @see UNumberFormatFields
775 void getAllFieldPositions(FieldPositionIterator
&iterator
, UErrorCode
&status
) const;
778 * Export the first formatted number as a decimal number. This endpoint
779 * is useful for obtaining the exact number being printed after scaling
780 * and rounding have been applied by the number range formatting pipeline.
782 * The syntax of the unformatted number is a "numeric string"
783 * as defined in the Decimal Arithmetic Specification, available at
784 * http://speleotrove.com/decimal
786 * @return A decimal representation of the first formatted number.
788 * @see NumberRangeFormatter
789 * @see #getSecondDecimal
791 UnicodeString
getFirstDecimal(UErrorCode
& status
) const;
794 * Export the second formatted number as a decimal number. This endpoint
795 * is useful for obtaining the exact number being printed after scaling
796 * and rounding have been applied by the number range formatting pipeline.
798 * The syntax of the unformatted number is a "numeric string"
799 * as defined in the Decimal Arithmetic Specification, available at
800 * http://speleotrove.com/decimal
802 * @return A decimal representation of the second formatted number.
804 * @see NumberRangeFormatter
805 * @see #getFirstDecimal
807 UnicodeString
getSecondDecimal(UErrorCode
& status
) const;
808 #endif // U_HIDE_DRAFT_API
811 * Returns whether the pair of numbers was successfully formatted as a range or whether an identity fallback was
812 * used. For example, if the first and second number were the same either before or after rounding occurred, an
813 * identity fallback was used.
815 * @return An indication the resulting identity situation in the formatted number range.
817 * @see UNumberRangeIdentityFallback
819 UNumberRangeIdentityResult
getIdentityResult(UErrorCode
& status
) const;
822 * Copying not supported; use move constructor instead.
824 FormattedNumberRange(const FormattedNumberRange
&) = delete;
827 * Copying not supported; use move assignment instead.
829 FormattedNumberRange
& operator=(const FormattedNumberRange
&) = delete;
833 * Leaves the source FormattedNumberRange in an undefined state.
836 FormattedNumberRange(FormattedNumberRange
&& src
) U_NOEXCEPT
;
840 * Leaves the source FormattedNumberRange in an undefined state.
843 FormattedNumberRange
& operator=(FormattedNumberRange
&& src
) U_NOEXCEPT
;
846 * Destruct an instance of FormattedNumberRange, cleaning up any memory it might own.
849 ~FormattedNumberRange();
852 // Can't use LocalPointer because UFormattedNumberRangeData is forward-declared
853 const impl::UFormattedNumberRangeData
*fData
;
855 // Error code for the terminal methods
856 UErrorCode fErrorCode
;
859 * Internal constructor from data type. Adopts the data pointer.
861 explicit FormattedNumberRange(impl::UFormattedNumberRangeData
*results
)
862 : fData(results
), fErrorCode(U_ZERO_ERROR
) {}
864 explicit FormattedNumberRange(UErrorCode errorCode
)
865 : fData(nullptr), fErrorCode(errorCode
) {}
867 void getAllFieldPositionsImpl(FieldPositionIteratorHandler
& fpih
, UErrorCode
& status
) const;
869 // To give LocalizedNumberRangeFormatter format methods access to this class's constructor:
870 friend class LocalizedNumberRangeFormatter
;
874 * See the main description in numberrangeformatter.h for documentation and examples.
878 class U_I18N_API NumberRangeFormatter final
{
881 * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is not currently
882 * known at the call site.
884 * @return An {@link UnlocalizedNumberRangeFormatter}, to be used for chaining.
887 static UnlocalizedNumberRangeFormatter
with();
890 * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call
894 * The locale from which to load formats and symbols for number range formatting.
895 * @return A {@link LocalizedNumberRangeFormatter}, to be used for chaining.
898 static LocalizedNumberRangeFormatter
withLocale(const Locale
&locale
);
901 * Use factory methods instead of the constructor to create a NumberFormatter.
903 NumberRangeFormatter() = delete;
906 } // namespace number
909 #endif /* #if !UCONFIG_NO_FORMATTING */
911 #endif /* U_SHOW_CPLUSPLUS_API */
913 #endif // __NUMBERRANGEFORMATTER_H__