1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #if !UCONFIG_NO_FORMATTING
5 #ifndef __NUMBERRANGEFORMATTER_H__
6 #define __NUMBERRANGEFORMATTER_H__
9 #include "unicode/appendable.h"
10 #include "unicode/fieldpos.h"
11 #include "unicode/formattedvalue.h"
12 #include "unicode/fpositer.h"
13 #include "unicode/numberformatter.h"
15 #ifndef U_HIDE_DRAFT_API
19 * \brief C++ API: Library for localized formatting of number, currency, and unit ranges.
21 * The main entrypoint to the formatting of ranges of numbers, including currencies and other units of measurement.
26 * NumberRangeFormatter::with()
27 * .identityFallback(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE)
28 * .numberFormatterFirst(NumberFormatter::with().adoptUnit(MeasureUnit::createMeter()))
29 * .numberFormatterSecond(NumberFormatter::with().adoptUnit(MeasureUnit::createKilometer()))
31 * .formatRange(750, 1.2, status)
33 * // => "750 m - 1.2 km"
36 * Like NumberFormatter, NumberRangeFormatter instances (i.e., LocalizedNumberRangeFormatter
37 * and UnlocalizedNumberRangeFormatter) are immutable and thread-safe. This API is based on the
38 * <em>fluent</em> design pattern popularized by libraries such as Google's Guava.
45 * Defines how to merge fields that are identical across the range sign.
49 typedef enum UNumberRangeCollapse
{
51 * Use locale data and heuristics to determine how much of the string to collapse. Could end up collapsing none,
52 * some, or all repeated pieces in a locale-sensitive way.
54 * The heuristics used for this option are subject to change over time.
58 UNUM_RANGE_COLLAPSE_AUTO
,
61 * Do not collapse any part of the number. Example: "3.2 thousand kilograms – 5.3 thousand kilograms"
65 UNUM_RANGE_COLLAPSE_NONE
,
68 * Collapse the unit part of the number, but not the notation, if present. Example: "3.2 thousand – 5.3 thousand
73 UNUM_RANGE_COLLAPSE_UNIT
,
76 * Collapse any field that is equal across the range sign. May introduce ambiguity on the magnitude of the
77 * number. Example: "3.2 – 5.3 thousand kilograms"
81 UNUM_RANGE_COLLAPSE_ALL
82 } UNumberRangeCollapse
;
85 * Defines the behavior when the two numbers in the range are identical after rounding. To programmatically detect
86 * when the identity fallback is used, compare the lower and upper BigDecimals via FormattedNumber.
89 * @see NumberRangeFormatter
91 typedef enum UNumberRangeIdentityFallback
{
93 * Show the number as a single value rather than a range. Example: "$5"
97 UNUM_IDENTITY_FALLBACK_SINGLE_VALUE
,
100 * Show the number using a locale-sensitive approximation pattern. If the numbers were the same before rounding,
101 * show the single value. Example: "~$5" or "$5"
105 UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE
,
108 * Show the number using a locale-sensitive approximation pattern. Use the range pattern always, even if the
109 * inputs are the same. Example: "~$5"
113 UNUM_IDENTITY_FALLBACK_APPROXIMATELY
,
116 * Show the number as the range of two equal values. Use the range pattern always, even if the inputs are the
117 * same. Example (with RangeCollapse.NONE): "$5 – $5"
121 UNUM_IDENTITY_FALLBACK_RANGE
122 } UNumberRangeIdentityFallback
;
125 * Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted in the range
126 * were equal or not, and whether or not the identity fallback was applied.
129 * @see NumberRangeFormatter
131 typedef enum UNumberRangeIdentityResult
{
133 * Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.
136 * @see NumberRangeFormatter
138 UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING
,
141 * Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied.
144 * @see NumberRangeFormatter
146 UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING
,
149 * Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied.
152 * @see NumberRangeFormatter
154 UNUM_IDENTITY_RESULT_NOT_EQUAL
,
156 #ifndef U_HIDE_INTERNAL_API
158 * The number of entries in this enum.
161 UNUM_IDENTITY_RESULT_COUNT
164 } UNumberRangeIdentityResult
;
166 #if U_SHOW_CPLUSPLUS_API
169 namespace number
{ // icu::number
171 // Forward declarations:
172 class UnlocalizedNumberRangeFormatter
;
173 class LocalizedNumberRangeFormatter
;
174 class FormattedNumberRange
;
178 // Forward declarations:
179 struct RangeMacroProps
;
180 class DecimalQuantity
;
181 class UFormattedNumberRangeData
;
182 class NumberRangeFormatterImpl
;
188 * Export an explicit template instantiation. See datefmt.h
189 * (When building DLLs for Windows this is required.)
191 #if U_PLATFORM == U_PF_WINDOWS && !defined(U_IN_DOXYGEN)
192 } // namespace icu::number
195 template struct U_I18N_API
std::atomic
< U_NAMESPACE_QUALIFIER
number::impl::NumberRangeFormatterImpl
*>;
198 namespace number
{ // icu::number
202 // Other helper classes would go here, but there are none.
204 namespace impl
{ // icu::number::impl
206 // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
208 struct U_I18N_API RangeMacroProps
: public UMemory
{
210 UnlocalizedNumberFormatter formatter1
; // = NumberFormatter::with();
213 UnlocalizedNumberFormatter formatter2
; // = NumberFormatter::with();
216 bool singleFormatter
= true;
219 UNumberRangeCollapse collapse
= UNUM_RANGE_COLLAPSE_AUTO
;
222 UNumberRangeIdentityFallback identityFallback
= UNUM_IDENTITY_FALLBACK_APPROXIMATELY
;
227 // NOTE: Uses default copy and move constructors.
230 * Check all members for errors.
233 bool copyErrorTo(UErrorCode
&status
) const {
234 return formatter1
.copyErrorTo(status
) || formatter2
.copyErrorTo(status
);
241 * An abstract base class for specifying settings related to number formatting. This class is implemented by
242 * {@link UnlocalizedNumberRangeFormatter} and {@link LocalizedNumberRangeFormatter}. This class is not intended for
243 * public subclassing.
245 template<typename Derived
>
246 class U_I18N_API NumberRangeFormatterSettings
{
249 * Sets the NumberFormatter instance to use for the numbers in the range. The same formatter is applied to both
250 * sides of the range.
252 * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
253 * NumberRangeFormatter will be used.
256 * The formatter to use for both numbers in the range.
257 * @return The fluent chain.
260 Derived
numberFormatterBoth(const UnlocalizedNumberFormatter
&formatter
) const &;
263 * Overload of numberFormatterBoth() for use on an rvalue reference.
266 * The formatter to use for both numbers in the range.
267 * @return The fluent chain.
268 * @see #numberFormatterBoth
271 Derived
numberFormatterBoth(const UnlocalizedNumberFormatter
&formatter
) &&;
274 * Overload of numberFormatterBoth() for use on an rvalue reference.
277 * The formatter to use for both numbers in the range.
278 * @return The fluent chain.
279 * @see #numberFormatterBoth
282 Derived
numberFormatterBoth(UnlocalizedNumberFormatter
&&formatter
) const &;
285 * Overload of numberFormatterBoth() for use on an rvalue reference.
288 * The formatter to use for both numbers in the range.
289 * @return The fluent chain.
290 * @see #numberFormatterBoth
293 Derived
numberFormatterBoth(UnlocalizedNumberFormatter
&&formatter
) &&;
296 * Sets the NumberFormatter instance to use for the first number in the range.
298 * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
299 * NumberRangeFormatter will be used.
301 * @param formatterFirst
302 * The formatter to use for the first number in the range.
303 * @return The fluent chain.
306 Derived
numberFormatterFirst(const UnlocalizedNumberFormatter
&formatterFirst
) const &;
309 * Overload of numberFormatterFirst() for use on an rvalue reference.
311 * @param formatterFirst
312 * The formatter to use for the first number in the range.
313 * @return The fluent chain.
314 * @see #numberFormatterFirst
317 Derived
numberFormatterFirst(const UnlocalizedNumberFormatter
&formatterFirst
) &&;
320 * Overload of numberFormatterFirst() for use on an rvalue reference.
322 * @param formatterFirst
323 * The formatter to use for the first number in the range.
324 * @return The fluent chain.
325 * @see #numberFormatterFirst
328 Derived
numberFormatterFirst(UnlocalizedNumberFormatter
&&formatterFirst
) const &;
331 * Overload of numberFormatterFirst() for use on an rvalue reference.
333 * @param formatterFirst
334 * The formatter to use for the first number in the range.
335 * @return The fluent chain.
336 * @see #numberFormatterFirst
339 Derived
numberFormatterFirst(UnlocalizedNumberFormatter
&&formatterFirst
) &&;
342 * Sets the NumberFormatter instance to use for the second number in the range.
344 * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
345 * NumberRangeFormatter will be used.
347 * @param formatterSecond
348 * The formatter to use for the second number in the range.
349 * @return The fluent chain.
352 Derived
numberFormatterSecond(const UnlocalizedNumberFormatter
&formatterSecond
) const &;
355 * Overload of numberFormatterSecond() for use on an rvalue reference.
357 * @param formatterSecond
358 * The formatter to use for the second number in the range.
359 * @return The fluent chain.
360 * @see #numberFormatterSecond
363 Derived
numberFormatterSecond(const UnlocalizedNumberFormatter
&formatterSecond
) &&;
366 * Overload of numberFormatterSecond() for use on an rvalue reference.
368 * @param formatterSecond
369 * The formatter to use for the second number in the range.
370 * @return The fluent chain.
371 * @see #numberFormatterSecond
374 Derived
numberFormatterSecond(UnlocalizedNumberFormatter
&&formatterSecond
) const &;
377 * Overload of numberFormatterSecond() for use on an rvalue reference.
379 * @param formatterSecond
380 * The formatter to use for the second number in the range.
381 * @return The fluent chain.
382 * @see #numberFormatterSecond
385 Derived
numberFormatterSecond(UnlocalizedNumberFormatter
&&formatterSecond
) &&;
388 * Sets the aggressiveness of "collapsing" fields across the range separator. Possible values:
391 * <li>ALL: "3-5K miles"</li>
392 * <li>UNIT: "3K - 5K miles"</li>
393 * <li>NONE: "3K miles - 5K miles"</li>
394 * <li>AUTO: usually UNIT or NONE, depending on the locale and formatter settings</li>
397 * The default value is AUTO.
400 * The collapsing strategy to use for this range.
401 * @return The fluent chain.
404 Derived
collapse(UNumberRangeCollapse collapse
) const &;
407 * Overload of collapse() for use on an rvalue reference.
410 * The collapsing strategy to use for this range.
411 * @return The fluent chain.
415 Derived
collapse(UNumberRangeCollapse collapse
) &&;
418 * Sets the behavior when the two sides of the range are the same. This could happen if the same two numbers are
419 * passed to the formatRange function, or if different numbers are passed to the function but they become the same
420 * after rounding rules are applied. Possible values:
423 * <li>SINGLE_VALUE: "5 miles"</li>
424 * <li>APPROXIMATELY_OR_SINGLE_VALUE: "~5 miles" or "5 miles", depending on whether the number was the same before
425 * rounding was applied</li>
426 * <li>APPROXIMATELY: "~5 miles"</li>
427 * <li>RANGE: "5-5 miles" (with collapse=UNIT)</li>
430 * The default value is APPROXIMATELY.
432 * @param identityFallback
433 * The strategy to use when formatting two numbers that end up being the same.
434 * @return The fluent chain.
437 Derived
identityFallback(UNumberRangeIdentityFallback identityFallback
) const &;
440 * Overload of identityFallback() for use on an rvalue reference.
442 * @param identityFallback
443 * The strategy to use when formatting two numbers that end up being the same.
444 * @return The fluent chain.
445 * @see #identityFallback
448 Derived
identityFallback(UNumberRangeIdentityFallback identityFallback
) &&;
451 * Returns the current (Un)LocalizedNumberRangeFormatter as a LocalPointer
452 * wrapping a heap-allocated copy of the current object.
454 * This is equivalent to new-ing the move constructor with a value object
457 * @return A wrapped (Un)LocalizedNumberRangeFormatter pointer, or a wrapped
458 * nullptr on failure.
461 LocalPointer
<Derived
> clone() const &;
464 * Overload of clone for use on an rvalue reference.
466 * @return A wrapped (Un)LocalizedNumberRangeFormatter pointer, or a wrapped
467 * nullptr on failure.
470 LocalPointer
<Derived
> clone() &&;
473 * Sets the UErrorCode if an error occurred in the fluent chain.
474 * Preserves older error codes in the outErrorCode.
475 * @return TRUE if U_FAILURE(outErrorCode)
478 UBool
copyErrorTo(UErrorCode
&outErrorCode
) const {
479 if (U_FAILURE(outErrorCode
)) {
480 // Do not overwrite the older error code
483 fMacros
.copyErrorTo(outErrorCode
);
484 return U_FAILURE(outErrorCode
);
487 // NOTE: Uses default copy and move constructors.
490 impl::RangeMacroProps fMacros
;
492 // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
493 NumberRangeFormatterSettings() = default;
495 friend class LocalizedNumberRangeFormatter
;
496 friend class UnlocalizedNumberRangeFormatter
;
500 * A NumberRangeFormatter that does not yet have a locale. In order to format, a locale must be specified.
502 * Instances of this class are immutable and thread-safe.
504 * @see NumberRangeFormatter
507 class U_I18N_API UnlocalizedNumberRangeFormatter
508 : public NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>, public UMemory
{
512 * Associate the given locale with the number range formatter. The locale is used for picking the
513 * appropriate symbols, formats, and other data for number display.
516 * The locale to use when loading data for number formatting.
517 * @return The fluent chain.
520 LocalizedNumberRangeFormatter
locale(const icu::Locale
&locale
) const &;
523 * Overload of locale() for use on an rvalue reference.
526 * The locale to use when loading data for number formatting.
527 * @return The fluent chain.
531 LocalizedNumberRangeFormatter
locale(const icu::Locale
&locale
) &&;
534 * Default constructor: puts the formatter into a valid but undefined state.
538 UnlocalizedNumberRangeFormatter() = default;
541 * Returns a copy of this UnlocalizedNumberRangeFormatter.
544 UnlocalizedNumberRangeFormatter(const UnlocalizedNumberRangeFormatter
&other
);
548 * The source UnlocalizedNumberRangeFormatter will be left in a valid but undefined state.
551 UnlocalizedNumberRangeFormatter(UnlocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
554 * Copy assignment operator.
557 UnlocalizedNumberRangeFormatter
& operator=(const UnlocalizedNumberRangeFormatter
& other
);
560 * Move assignment operator:
561 * The source UnlocalizedNumberRangeFormatter will be left in a valid but undefined state.
564 UnlocalizedNumberRangeFormatter
& operator=(UnlocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
567 explicit UnlocalizedNumberRangeFormatter(
568 const NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>& other
);
570 explicit UnlocalizedNumberRangeFormatter(
571 NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>&& src
) U_NOEXCEPT
;
573 // To give the fluent setters access to this class's constructor:
574 friend class NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>;
576 // To give NumberRangeFormatter::with() access to this class's constructor:
577 friend class NumberRangeFormatter
;
581 * A NumberRangeFormatter that has a locale associated with it; this means .formatRange() methods are available.
583 * Instances of this class are immutable and thread-safe.
585 * @see NumberFormatter
588 class U_I18N_API LocalizedNumberRangeFormatter
589 : public NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>, public UMemory
{
592 * Format the given Formattables to a string using the settings specified in the NumberRangeFormatter fluent setting
596 * The first number in the range, usually to the left in LTR locales.
598 * The second number in the range, usually to the right in LTR locales.
600 * Set if an error occurs while formatting.
601 * @return A FormattedNumberRange object; call .toString() to get the string.
604 FormattedNumberRange
formatFormattableRange(
605 const Formattable
& first
, const Formattable
& second
, UErrorCode
& status
) const;
608 * Default constructor: puts the formatter into a valid but undefined state.
612 LocalizedNumberRangeFormatter() = default;
615 * Returns a copy of this LocalizedNumberRangeFormatter.
618 LocalizedNumberRangeFormatter(const LocalizedNumberRangeFormatter
&other
);
622 * The source LocalizedNumberRangeFormatter will be left in a valid but undefined state.
625 LocalizedNumberRangeFormatter(LocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
628 * Copy assignment operator.
631 LocalizedNumberRangeFormatter
& operator=(const LocalizedNumberRangeFormatter
& other
);
634 * Move assignment operator:
635 * The source LocalizedNumberRangeFormatter will be left in a valid but undefined state.
638 LocalizedNumberRangeFormatter
& operator=(LocalizedNumberRangeFormatter
&& src
) U_NOEXCEPT
;
640 #ifndef U_HIDE_INTERNAL_API
644 * The results object. This method will mutate it to save the results.
645 * @param equalBeforeRounding
646 * Whether the number was equal before copying it into a DecimalQuantity.
647 * Used for determining the identity fallback behavior.
649 * Set if an error occurs while formatting.
652 void formatImpl(impl::UFormattedNumberRangeData
& results
, bool equalBeforeRounding
,
653 UErrorCode
& status
) const;
658 * Destruct this LocalizedNumberRangeFormatter, cleaning up any memory it might own.
661 ~LocalizedNumberRangeFormatter();
664 std::atomic
<impl::NumberRangeFormatterImpl
*> fAtomicFormatter
= {};
666 const impl::NumberRangeFormatterImpl
* getFormatter(UErrorCode
& stauts
) const;
668 explicit LocalizedNumberRangeFormatter(
669 const NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>& other
);
671 explicit LocalizedNumberRangeFormatter(
672 NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>&& src
) U_NOEXCEPT
;
674 LocalizedNumberRangeFormatter(const impl::RangeMacroProps
¯os
, const Locale
&locale
);
676 LocalizedNumberRangeFormatter(impl::RangeMacroProps
&¯os
, const Locale
&locale
);
680 // To give the fluent setters access to this class's constructor:
681 friend class NumberRangeFormatterSettings
<UnlocalizedNumberRangeFormatter
>;
682 friend class NumberRangeFormatterSettings
<LocalizedNumberRangeFormatter
>;
684 // To give UnlocalizedNumberRangeFormatter::locale() access to this class's constructor:
685 friend class UnlocalizedNumberRangeFormatter
;
689 * The result of a number range formatting operation. This class allows the result to be exported in several data types,
690 * including a UnicodeString and a FieldPositionIterator.
692 * Instances of this class are immutable and thread-safe.
696 class U_I18N_API FormattedNumberRange
: public UMemory
, public FormattedValue
{
698 // Copybrief: this method is older than the parent method
700 * @copybrief FormattedValue::toString()
702 * For more information, see FormattedValue::toString()
706 UnicodeString
toString(UErrorCode
& status
) const U_OVERRIDE
;
708 // Copydoc: this method is new in ICU 64
709 /** @copydoc FormattedValue::toTempString() */
710 UnicodeString
toTempString(UErrorCode
& status
) const U_OVERRIDE
;
712 // Copybrief: this method is older than the parent method
714 * @copybrief FormattedValue::appendTo()
716 * For more information, see FormattedValue::appendTo()
720 Appendable
&appendTo(Appendable
&appendable
, UErrorCode
& status
) const U_OVERRIDE
;
722 // Copydoc: this method is new in ICU 64
723 /** @copydoc FormattedValue::nextPosition() */
724 UBool
nextPosition(ConstrainedFieldPosition
& cfpos
, UErrorCode
& status
) const U_OVERRIDE
;
727 * Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given
728 * <em>field</em> in the output string. This allows you to determine the locations of, for example,
729 * the integer part, fraction part, or symbols.
731 * If both sides of the range have the same field, the field will occur twice, once before the
732 * range separator and once after the range separator, if applicable.
734 * If a field occurs just once, calling this method will find that occurrence and return it. If a
735 * field occurs multiple times, this method may be called repeatedly with the following pattern:
738 * FieldPosition fpos(UNUM_INTEGER_FIELD);
739 * while (formattedNumberRange.nextFieldPosition(fpos, status)) {
740 * // do something with fpos.
744 * This method is useful if you know which field to query. If you want all available field position
745 * information, use #getAllFieldPositions().
747 * @param fieldPosition
748 * Input+output variable. See {@link FormattedNumber#nextFieldPosition}.
750 * Set if an error occurs while populating the FieldPosition.
751 * @return TRUE if a new occurrence of the field was found; FALSE otherwise.
753 * @see UNumberFormatFields
755 UBool
nextFieldPosition(FieldPosition
& fieldPosition
, UErrorCode
& status
) const;
758 * Export the formatted number range to a FieldPositionIterator. This allows you to determine which characters in
759 * the output string correspond to which <em>fields</em>, such as the integer part, fraction part, and sign.
761 * If information on only one field is needed, use #nextFieldPosition() instead.
764 * The FieldPositionIterator to populate with all of the fields present in the formatted number.
766 * Set if an error occurs while populating the FieldPositionIterator.
768 * @see UNumberFormatFields
770 void getAllFieldPositions(FieldPositionIterator
&iterator
, UErrorCode
&status
) const;
773 * Export the first formatted number as a decimal number. This endpoint
774 * is useful for obtaining the exact number being printed after scaling
775 * and rounding have been applied by the number range formatting pipeline.
777 * The syntax of the unformatted number is a "numeric string"
778 * as defined in the Decimal Arithmetic Specification, available at
779 * http://speleotrove.com/decimal
781 * @return A decimal representation of the first formatted number.
783 * @see NumberRangeFormatter
784 * @see #getSecondDecimal
786 UnicodeString
getFirstDecimal(UErrorCode
& status
) const;
789 * Export the second formatted number as a decimal number. This endpoint
790 * is useful for obtaining the exact number being printed after scaling
791 * and rounding have been applied by the number range formatting pipeline.
793 * The syntax of the unformatted number is a "numeric string"
794 * as defined in the Decimal Arithmetic Specification, available at
795 * http://speleotrove.com/decimal
797 * @return A decimal representation of the second formatted number.
799 * @see NumberRangeFormatter
800 * @see #getFirstDecimal
802 UnicodeString
getSecondDecimal(UErrorCode
& status
) const;
805 * Returns whether the pair of numbers was successfully formatted as a range or whether an identity fallback was
806 * used. For example, if the first and second number were the same either before or after rounding occurred, an
807 * identity fallback was used.
809 * @return An indication the resulting identity situation in the formatted number range.
811 * @see UNumberRangeIdentityFallback
813 UNumberRangeIdentityResult
getIdentityResult(UErrorCode
& status
) const;
816 * Copying not supported; use move constructor instead.
818 FormattedNumberRange(const FormattedNumberRange
&) = delete;
821 * Copying not supported; use move assignment instead.
823 FormattedNumberRange
& operator=(const FormattedNumberRange
&) = delete;
827 * Leaves the source FormattedNumberRange in an undefined state.
830 FormattedNumberRange(FormattedNumberRange
&& src
) U_NOEXCEPT
;
834 * Leaves the source FormattedNumberRange in an undefined state.
837 FormattedNumberRange
& operator=(FormattedNumberRange
&& src
) U_NOEXCEPT
;
840 * Destruct an instance of FormattedNumberRange, cleaning up any memory it might own.
843 ~FormattedNumberRange();
846 // Can't use LocalPointer because UFormattedNumberRangeData is forward-declared
847 const impl::UFormattedNumberRangeData
*fData
;
849 // Error code for the terminal methods
850 UErrorCode fErrorCode
;
853 * Internal constructor from data type. Adopts the data pointer.
856 explicit FormattedNumberRange(impl::UFormattedNumberRangeData
*results
)
857 : fData(results
), fErrorCode(U_ZERO_ERROR
) {}
859 explicit FormattedNumberRange(UErrorCode errorCode
)
860 : fData(nullptr), fErrorCode(errorCode
) {}
862 void getAllFieldPositionsImpl(FieldPositionIteratorHandler
& fpih
, UErrorCode
& status
) const;
864 // To give LocalizedNumberRangeFormatter format methods access to this class's constructor:
865 friend class LocalizedNumberRangeFormatter
;
869 * See the main description in numberrangeformatter.h for documentation and examples.
873 class U_I18N_API NumberRangeFormatter final
{
876 * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is not currently
877 * known at the call site.
879 * @return An {@link UnlocalizedNumberRangeFormatter}, to be used for chaining.
882 static UnlocalizedNumberRangeFormatter
with();
885 * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call
889 * The locale from which to load formats and symbols for number range formatting.
890 * @return A {@link LocalizedNumberRangeFormatter}, to be used for chaining.
893 static LocalizedNumberRangeFormatter
withLocale(const Locale
&locale
);
896 * Use factory methods instead of the constructor to create a NumberFormatter.
898 NumberRangeFormatter() = delete;
901 } // namespace number
903 #endif // U_SHOW_CPLUSPLUS_API
905 #endif // U_HIDE_DRAFT_API
907 #endif // __NUMBERRANGEFORMATTER_H__
909 #endif /* #if !UCONFIG_NO_FORMATTING */