11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
31cb0ef41Sopenharmony_ci/*
41cb0ef41Sopenharmony_ci********************************************************************************
51cb0ef41Sopenharmony_ci*   Copyright (C) 1997-2013, International Business Machines
61cb0ef41Sopenharmony_ci*   Corporation and others.  All Rights Reserved.
71cb0ef41Sopenharmony_ci********************************************************************************
81cb0ef41Sopenharmony_ci*
91cb0ef41Sopenharmony_ci* File CHOICFMT.H
101cb0ef41Sopenharmony_ci*
111cb0ef41Sopenharmony_ci* Modification History:
121cb0ef41Sopenharmony_ci*
131cb0ef41Sopenharmony_ci*   Date        Name        Description
141cb0ef41Sopenharmony_ci*   02/19/97    aliu        Converted from java.
151cb0ef41Sopenharmony_ci*   03/20/97    helena      Finished first cut of implementation and got rid
161cb0ef41Sopenharmony_ci*                           of nextDouble/previousDouble and replaced with
171cb0ef41Sopenharmony_ci*                           boolean array.
181cb0ef41Sopenharmony_ci*   4/10/97     aliu        Clean up.  Modified to work on AIX.
191cb0ef41Sopenharmony_ci*   8/6/97      nos         Removed overloaded constructor, member var 'buffer'.
201cb0ef41Sopenharmony_ci*   07/22/98    stephen     Removed operator!= (implemented in Format)
211cb0ef41Sopenharmony_ci********************************************************************************
221cb0ef41Sopenharmony_ci*/
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci#ifndef CHOICFMT_H
251cb0ef41Sopenharmony_ci#define CHOICFMT_H
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci#include "unicode/utypes.h"
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci/**
321cb0ef41Sopenharmony_ci * \file
331cb0ef41Sopenharmony_ci * \brief C++ API: Choice Format.
341cb0ef41Sopenharmony_ci */
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci#if !UCONFIG_NO_FORMATTING
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci#include "unicode/fieldpos.h"
391cb0ef41Sopenharmony_ci#include "unicode/format.h"
401cb0ef41Sopenharmony_ci#include "unicode/messagepattern.h"
411cb0ef41Sopenharmony_ci#include "unicode/numfmt.h"
421cb0ef41Sopenharmony_ci#include "unicode/unistr.h"
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci#ifndef U_HIDE_DEPRECATED_API
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciclass MessageFormat;
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci/**
511cb0ef41Sopenharmony_ci * ChoiceFormat converts between ranges of numeric values and strings for those ranges.
521cb0ef41Sopenharmony_ci * The strings must conform to the MessageFormat pattern syntax.
531cb0ef41Sopenharmony_ci *
541cb0ef41Sopenharmony_ci * <p><em><code>ChoiceFormat</code> is probably not what you need.
551cb0ef41Sopenharmony_ci * Please use <code>MessageFormat</code>
561cb0ef41Sopenharmony_ci * with <code>plural</code> arguments for proper plural selection,
571cb0ef41Sopenharmony_ci * and <code>select</code> arguments for simple selection among a fixed set of choices!</em></p>
581cb0ef41Sopenharmony_ci *
591cb0ef41Sopenharmony_ci * <p>A <code>ChoiceFormat</code> splits
601cb0ef41Sopenharmony_ci * the real number line \htmlonly<code>-&#x221E;</code> to
611cb0ef41Sopenharmony_ci * <code>+&#x221E;</code>\endhtmlonly into two
621cb0ef41Sopenharmony_ci * or more contiguous ranges. Each range is mapped to a
631cb0ef41Sopenharmony_ci * string.</p>
641cb0ef41Sopenharmony_ci *
651cb0ef41Sopenharmony_ci * <p><code>ChoiceFormat</code> was originally intended
661cb0ef41Sopenharmony_ci * for displaying grammatically correct
671cb0ef41Sopenharmony_ci * plurals such as &quot;There is one file.&quot; vs. &quot;There are 2 files.&quot;
681cb0ef41Sopenharmony_ci * <em>However,</em> plural rules for many languages
691cb0ef41Sopenharmony_ci * are too complex for the capabilities of ChoiceFormat,
701cb0ef41Sopenharmony_ci * and its requirement of specifying the precise rules for each message
711cb0ef41Sopenharmony_ci * is unmanageable for translators.</p>
721cb0ef41Sopenharmony_ci *
731cb0ef41Sopenharmony_ci * <p>There are two methods of defining a <code>ChoiceFormat</code>; both
741cb0ef41Sopenharmony_ci * are equivalent.  The first is by using a string pattern. This is the
751cb0ef41Sopenharmony_ci * preferred method in most cases.  The second method is through direct
761cb0ef41Sopenharmony_ci * specification of the arrays that logically make up the
771cb0ef41Sopenharmony_ci * <code>ChoiceFormat</code>.</p>
781cb0ef41Sopenharmony_ci *
791cb0ef41Sopenharmony_ci * <p>Note: Typically, choice formatting is done (if done at all) via <code>MessageFormat</code>
801cb0ef41Sopenharmony_ci * with a <code>choice</code> argument type,
811cb0ef41Sopenharmony_ci * rather than using a stand-alone <code>ChoiceFormat</code>.</p>
821cb0ef41Sopenharmony_ci *
831cb0ef41Sopenharmony_ci * <h5>Patterns and Their Interpretation</h5>
841cb0ef41Sopenharmony_ci *
851cb0ef41Sopenharmony_ci * <p>The pattern string defines the range boundaries and the strings for each number range.
861cb0ef41Sopenharmony_ci * Syntax:
871cb0ef41Sopenharmony_ci * <pre>
881cb0ef41Sopenharmony_ci * choiceStyle = number separator message ('|' number separator message)*
891cb0ef41Sopenharmony_ci * number = normal_number | ['-'] \htmlonly&#x221E;\endhtmlonly (U+221E, infinity)
901cb0ef41Sopenharmony_ci * normal_number = double value (unlocalized ASCII string)
911cb0ef41Sopenharmony_ci * separator = less_than | less_than_or_equal
921cb0ef41Sopenharmony_ci * less_than = '<'
931cb0ef41Sopenharmony_ci * less_than_or_equal = '#' | \htmlonly&#x2264;\endhtmlonly (U+2264)
941cb0ef41Sopenharmony_ci * message: see {@link MessageFormat}
951cb0ef41Sopenharmony_ci * </pre>
961cb0ef41Sopenharmony_ci * Pattern_White_Space between syntax elements is ignored, except
971cb0ef41Sopenharmony_ci * around each range's sub-message.</p>
981cb0ef41Sopenharmony_ci *
991cb0ef41Sopenharmony_ci * <p>Each numeric sub-range extends from the current range's number
1001cb0ef41Sopenharmony_ci * to the next range's number.
1011cb0ef41Sopenharmony_ci * The number itself is included in its range if a <code>less_than_or_equal</code> sign is used,
1021cb0ef41Sopenharmony_ci * and excluded from its range (and instead included in the previous range)
1031cb0ef41Sopenharmony_ci * if a <code>less_than</code> sign is used.</p>
1041cb0ef41Sopenharmony_ci *
1051cb0ef41Sopenharmony_ci * <p>When a <code>ChoiceFormat</code> is constructed from
1061cb0ef41Sopenharmony_ci * arrays of numbers, closure flags and strings,
1071cb0ef41Sopenharmony_ci * they are interpreted just like
1081cb0ef41Sopenharmony_ci * the sequence of <code>(number separator string)</code> in an equivalent pattern string.
1091cb0ef41Sopenharmony_ci * <code>closure[i]==true</code> corresponds to a <code>less_than</code> separator sign.
1101cb0ef41Sopenharmony_ci * The equivalent pattern string will be constructed automatically.</p>
1111cb0ef41Sopenharmony_ci *
1121cb0ef41Sopenharmony_ci * <p>During formatting, a number is mapped to the first range
1131cb0ef41Sopenharmony_ci * where the number is not greater than the range's upper limit.
1141cb0ef41Sopenharmony_ci * That range's message string is returned. A NaN maps to the very first range.</p>
1151cb0ef41Sopenharmony_ci *
1161cb0ef41Sopenharmony_ci * <p>During parsing, a range is selected for the longest match of
1171cb0ef41Sopenharmony_ci * any range's message. That range's number is returned, ignoring the separator/closure.
1181cb0ef41Sopenharmony_ci * Only a simple string match is performed, without parsing of arguments that
1191cb0ef41Sopenharmony_ci * might be specified in the message strings.</p>
1201cb0ef41Sopenharmony_ci *
1211cb0ef41Sopenharmony_ci * <p>Note that the first range's number is ignored in formatting
1221cb0ef41Sopenharmony_ci * but may be returned from parsing.</p>
1231cb0ef41Sopenharmony_ci *
1241cb0ef41Sopenharmony_ci * <h5>Examples</h5>
1251cb0ef41Sopenharmony_ci *
1261cb0ef41Sopenharmony_ci * <p>Here is an example of two arrays that map the number
1271cb0ef41Sopenharmony_ci * <code>1..7</code> to the English day of the week abbreviations
1281cb0ef41Sopenharmony_ci * <code>Sun..Sat</code>. No closures array is given; this is the same as
1291cb0ef41Sopenharmony_ci * specifying all closures to be <code>false</code>.</p>
1301cb0ef41Sopenharmony_ci *
1311cb0ef41Sopenharmony_ci * <pre>    {1,2,3,4,5,6,7},
1321cb0ef41Sopenharmony_ci *     {&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thur&quot;,&quot;Fri&quot;,&quot;Sat&quot;}</pre>
1331cb0ef41Sopenharmony_ci *
1341cb0ef41Sopenharmony_ci * <p>Here is an example that maps the ranges [-Inf, 1), [1, 1], and (1,
1351cb0ef41Sopenharmony_ci * +Inf] to three strings. That is, the number line is split into three
1361cb0ef41Sopenharmony_ci * ranges: x &lt; 1.0, x = 1.0, and x &gt; 1.0.
1371cb0ef41Sopenharmony_ci * (The round parentheses in the notation above indicate an exclusive boundary,
1381cb0ef41Sopenharmony_ci * like the turned bracket in European notation: [-Inf, 1) == [-Inf, 1[  )</p>
1391cb0ef41Sopenharmony_ci *
1401cb0ef41Sopenharmony_ci * <pre>    {0, 1, 1},
1411cb0ef41Sopenharmony_ci *     {false, false, true},
1421cb0ef41Sopenharmony_ci *     {&quot;no files&quot;, &quot;one file&quot;, &quot;many files&quot;}</pre>
1431cb0ef41Sopenharmony_ci *
1441cb0ef41Sopenharmony_ci * <p>Here is an example that shows formatting and parsing: </p>
1451cb0ef41Sopenharmony_ci *
1461cb0ef41Sopenharmony_ci * \code
1471cb0ef41Sopenharmony_ci *   #include <unicode/choicfmt.h>
1481cb0ef41Sopenharmony_ci *   #include <unicode/unistr.h>
1491cb0ef41Sopenharmony_ci *   #include <iostream.h>
1501cb0ef41Sopenharmony_ci *
1511cb0ef41Sopenharmony_ci *   int main(int argc, char *argv[]) {
1521cb0ef41Sopenharmony_ci *       double limits[] = {1,2,3,4,5,6,7};
1531cb0ef41Sopenharmony_ci *       UnicodeString monthNames[] = {
1541cb0ef41Sopenharmony_ci *           "Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
1551cb0ef41Sopenharmony_ci *       ChoiceFormat fmt(limits, monthNames, 7);
1561cb0ef41Sopenharmony_ci *       UnicodeString str;
1571cb0ef41Sopenharmony_ci *       char buf[256];
1581cb0ef41Sopenharmony_ci *       for (double x = 1.0; x <= 8.0; x += 1.0) {
1591cb0ef41Sopenharmony_ci *           fmt.format(x, str);
1601cb0ef41Sopenharmony_ci *           str.extract(0, str.length(), buf, 256, "");
1611cb0ef41Sopenharmony_ci *           str.truncate(0);
1621cb0ef41Sopenharmony_ci *           cout << x << " -> "
1631cb0ef41Sopenharmony_ci *                << buf << endl;
1641cb0ef41Sopenharmony_ci *       }
1651cb0ef41Sopenharmony_ci *       cout << endl;
1661cb0ef41Sopenharmony_ci *       return 0;
1671cb0ef41Sopenharmony_ci *   }
1681cb0ef41Sopenharmony_ci * \endcode
1691cb0ef41Sopenharmony_ci *
1701cb0ef41Sopenharmony_ci * <p><em>User subclasses are not supported.</em> While clients may write
1711cb0ef41Sopenharmony_ci * subclasses, such code will not necessarily work and will not be
1721cb0ef41Sopenharmony_ci * guaranteed to work stably from release to release.
1731cb0ef41Sopenharmony_ci *
1741cb0ef41Sopenharmony_ci * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
1751cb0ef41Sopenharmony_ci */
1761cb0ef41Sopenharmony_ciclass U_I18N_API ChoiceFormat: public NumberFormat {
1771cb0ef41Sopenharmony_cipublic:
1781cb0ef41Sopenharmony_ci    /**
1791cb0ef41Sopenharmony_ci     * Constructs a new ChoiceFormat from the pattern string.
1801cb0ef41Sopenharmony_ci     *
1811cb0ef41Sopenharmony_ci     * @param pattern   Pattern used to construct object.
1821cb0ef41Sopenharmony_ci     * @param status    Output param to receive success code.  If the
1831cb0ef41Sopenharmony_ci     *                  pattern cannot be parsed, set to failure code.
1841cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
1851cb0ef41Sopenharmony_ci     */
1861cb0ef41Sopenharmony_ci    ChoiceFormat(const UnicodeString& pattern,
1871cb0ef41Sopenharmony_ci                 UErrorCode& status);
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci    /**
1911cb0ef41Sopenharmony_ci     * Constructs a new ChoiceFormat with the given limits and message strings.
1921cb0ef41Sopenharmony_ci     * All closure flags default to <code>false</code>,
1931cb0ef41Sopenharmony_ci     * equivalent to <code>less_than_or_equal</code> separators.
1941cb0ef41Sopenharmony_ci     *
1951cb0ef41Sopenharmony_ci     * Copies the limits and formats instead of adopting them.
1961cb0ef41Sopenharmony_ci     *
1971cb0ef41Sopenharmony_ci     * @param limits    Array of limit values.
1981cb0ef41Sopenharmony_ci     * @param formats   Array of formats.
1991cb0ef41Sopenharmony_ci     * @param count     Size of 'limits' and 'formats' arrays.
2001cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2011cb0ef41Sopenharmony_ci     */
2021cb0ef41Sopenharmony_ci    ChoiceFormat(const double* limits,
2031cb0ef41Sopenharmony_ci                 const UnicodeString* formats,
2041cb0ef41Sopenharmony_ci                 int32_t count );
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ci    /**
2071cb0ef41Sopenharmony_ci     * Constructs a new ChoiceFormat with the given limits, closure flags and message strings.
2081cb0ef41Sopenharmony_ci     *
2091cb0ef41Sopenharmony_ci     * Copies the limits and formats instead of adopting them.
2101cb0ef41Sopenharmony_ci     *
2111cb0ef41Sopenharmony_ci     * @param limits Array of limit values
2121cb0ef41Sopenharmony_ci     * @param closures Array of booleans specifying whether each
2131cb0ef41Sopenharmony_ci     * element of 'limits' is open or closed.  If false, then the
2141cb0ef41Sopenharmony_ci     * corresponding limit number is a member of its range.
2151cb0ef41Sopenharmony_ci     * If true, then the limit number belongs to the previous range it.
2161cb0ef41Sopenharmony_ci     * @param formats Array of formats
2171cb0ef41Sopenharmony_ci     * @param count Size of 'limits', 'closures', and 'formats' arrays
2181cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2191cb0ef41Sopenharmony_ci     */
2201cb0ef41Sopenharmony_ci    ChoiceFormat(const double* limits,
2211cb0ef41Sopenharmony_ci                 const UBool* closures,
2221cb0ef41Sopenharmony_ci                 const UnicodeString* formats,
2231cb0ef41Sopenharmony_ci                 int32_t count);
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci    /**
2261cb0ef41Sopenharmony_ci     * Copy constructor.
2271cb0ef41Sopenharmony_ci     *
2281cb0ef41Sopenharmony_ci     * @param that   ChoiceFormat object to be copied from
2291cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2301cb0ef41Sopenharmony_ci     */
2311cb0ef41Sopenharmony_ci    ChoiceFormat(const ChoiceFormat& that);
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_ci    /**
2341cb0ef41Sopenharmony_ci     * Assignment operator.
2351cb0ef41Sopenharmony_ci     *
2361cb0ef41Sopenharmony_ci     * @param that   ChoiceFormat object to be copied
2371cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2381cb0ef41Sopenharmony_ci     */
2391cb0ef41Sopenharmony_ci    const ChoiceFormat& operator=(const ChoiceFormat& that);
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci    /**
2421cb0ef41Sopenharmony_ci     * Destructor.
2431cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2441cb0ef41Sopenharmony_ci     */
2451cb0ef41Sopenharmony_ci    virtual ~ChoiceFormat();
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ci    /**
2481cb0ef41Sopenharmony_ci     * Clones this Format object. The caller owns the
2491cb0ef41Sopenharmony_ci     * result and must delete it when done.
2501cb0ef41Sopenharmony_ci     *
2511cb0ef41Sopenharmony_ci     * @return a copy of this object
2521cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2531cb0ef41Sopenharmony_ci     */
2541cb0ef41Sopenharmony_ci    virtual ChoiceFormat* clone() const override;
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_ci    /**
2571cb0ef41Sopenharmony_ci     * Returns true if the given Format objects are semantically equal.
2581cb0ef41Sopenharmony_ci     * Objects of different subclasses are considered unequal.
2591cb0ef41Sopenharmony_ci     *
2601cb0ef41Sopenharmony_ci     * @param other    ChoiceFormat object to be compared
2611cb0ef41Sopenharmony_ci     * @return         true if other is the same as this.
2621cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2631cb0ef41Sopenharmony_ci     */
2641cb0ef41Sopenharmony_ci    virtual bool operator==(const Format& other) const override;
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci    /**
2671cb0ef41Sopenharmony_ci     * Sets the pattern.
2681cb0ef41Sopenharmony_ci     * @param pattern   The pattern to be applied.
2691cb0ef41Sopenharmony_ci     * @param status    Output param set to success/failure code on
2701cb0ef41Sopenharmony_ci     *                  exit. If the pattern is invalid, this will be
2711cb0ef41Sopenharmony_ci     *                  set to a failure result.
2721cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2731cb0ef41Sopenharmony_ci     */
2741cb0ef41Sopenharmony_ci    virtual void applyPattern(const UnicodeString& pattern,
2751cb0ef41Sopenharmony_ci                              UErrorCode& status);
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci    /**
2781cb0ef41Sopenharmony_ci     * Sets the pattern.
2791cb0ef41Sopenharmony_ci     * @param pattern    The pattern to be applied.
2801cb0ef41Sopenharmony_ci     * @param parseError Struct to receive information on position
2811cb0ef41Sopenharmony_ci     *                   of error if an error is encountered
2821cb0ef41Sopenharmony_ci     * @param status     Output param set to success/failure code on
2831cb0ef41Sopenharmony_ci     *                   exit. If the pattern is invalid, this will be
2841cb0ef41Sopenharmony_ci     *                   set to a failure result.
2851cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2861cb0ef41Sopenharmony_ci     */
2871cb0ef41Sopenharmony_ci    virtual void applyPattern(const UnicodeString& pattern,
2881cb0ef41Sopenharmony_ci                             UParseError& parseError,
2891cb0ef41Sopenharmony_ci                             UErrorCode& status);
2901cb0ef41Sopenharmony_ci    /**
2911cb0ef41Sopenharmony_ci     * Gets the pattern.
2921cb0ef41Sopenharmony_ci     *
2931cb0ef41Sopenharmony_ci     * @param pattern    Output param which will receive the pattern
2941cb0ef41Sopenharmony_ci     *                   Previous contents are deleted.
2951cb0ef41Sopenharmony_ci     * @return    A reference to 'pattern'
2961cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
2971cb0ef41Sopenharmony_ci     */
2981cb0ef41Sopenharmony_ci    virtual UnicodeString& toPattern(UnicodeString &pattern) const;
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci    /**
3011cb0ef41Sopenharmony_ci     * Sets the choices to be used in formatting.
3021cb0ef41Sopenharmony_ci     * For details see the constructor with the same parameter list.
3031cb0ef41Sopenharmony_ci     *
3041cb0ef41Sopenharmony_ci     * @param limitsToCopy      Contains the top value that you want
3051cb0ef41Sopenharmony_ci     *                          parsed with that format,and should be in
3061cb0ef41Sopenharmony_ci     *                          ascending sorted order. When formatting X,
3071cb0ef41Sopenharmony_ci     *                          the choice will be the i, where limit[i]
3081cb0ef41Sopenharmony_ci     *                          &lt;= X &lt; limit[i+1].
3091cb0ef41Sopenharmony_ci     * @param formatsToCopy     The format strings you want to use for each limit.
3101cb0ef41Sopenharmony_ci     * @param count             The size of the above arrays.
3111cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
3121cb0ef41Sopenharmony_ci     */
3131cb0ef41Sopenharmony_ci    virtual void setChoices(const double* limitsToCopy,
3141cb0ef41Sopenharmony_ci                            const UnicodeString* formatsToCopy,
3151cb0ef41Sopenharmony_ci                            int32_t count );
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci    /**
3181cb0ef41Sopenharmony_ci     * Sets the choices to be used in formatting.
3191cb0ef41Sopenharmony_ci     * For details see the constructor with the same parameter list.
3201cb0ef41Sopenharmony_ci     *
3211cb0ef41Sopenharmony_ci     * @param limits Array of limits
3221cb0ef41Sopenharmony_ci     * @param closures Array of limit booleans
3231cb0ef41Sopenharmony_ci     * @param formats Array of format string
3241cb0ef41Sopenharmony_ci     * @param count The size of the above arrays
3251cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
3261cb0ef41Sopenharmony_ci     */
3271cb0ef41Sopenharmony_ci    virtual void setChoices(const double* limits,
3281cb0ef41Sopenharmony_ci                            const UBool* closures,
3291cb0ef41Sopenharmony_ci                            const UnicodeString* formats,
3301cb0ef41Sopenharmony_ci                            int32_t count);
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci    /**
3331cb0ef41Sopenharmony_ci     * Returns nullptr and 0.
3341cb0ef41Sopenharmony_ci     * Before ICU 4.8, this used to return the choice limits array.
3351cb0ef41Sopenharmony_ci     *
3361cb0ef41Sopenharmony_ci     * @param count Will be set to 0.
3371cb0ef41Sopenharmony_ci     * @return nullptr
3381cb0ef41Sopenharmony_ci     * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
3391cb0ef41Sopenharmony_ci     */
3401cb0ef41Sopenharmony_ci    virtual const double* getLimits(int32_t& count) const;
3411cb0ef41Sopenharmony_ci
3421cb0ef41Sopenharmony_ci    /**
3431cb0ef41Sopenharmony_ci     * Returns nullptr and 0.
3441cb0ef41Sopenharmony_ci     * Before ICU 4.8, this used to return the limit booleans array.
3451cb0ef41Sopenharmony_ci     *
3461cb0ef41Sopenharmony_ci     * @param count Will be set to 0.
3471cb0ef41Sopenharmony_ci     * @return nullptr
3481cb0ef41Sopenharmony_ci     * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
3491cb0ef41Sopenharmony_ci     */
3501cb0ef41Sopenharmony_ci    virtual const UBool* getClosures(int32_t& count) const;
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci    /**
3531cb0ef41Sopenharmony_ci     * Returns nullptr and 0.
3541cb0ef41Sopenharmony_ci     * Before ICU 4.8, this used to return the array of choice strings.
3551cb0ef41Sopenharmony_ci     *
3561cb0ef41Sopenharmony_ci     * @param count Will be set to 0.
3571cb0ef41Sopenharmony_ci     * @return nullptr
3581cb0ef41Sopenharmony_ci     * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
3591cb0ef41Sopenharmony_ci     */
3601cb0ef41Sopenharmony_ci    virtual const UnicodeString* getFormats(int32_t& count) const;
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci
3631cb0ef41Sopenharmony_ci    using NumberFormat::format;
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ci    /**
3661cb0ef41Sopenharmony_ci     * Formats a double number using this object's choices.
3671cb0ef41Sopenharmony_ci     *
3681cb0ef41Sopenharmony_ci     * @param number    The value to be formatted.
3691cb0ef41Sopenharmony_ci     * @param appendTo  Output parameter to receive result.
3701cb0ef41Sopenharmony_ci     *                  Result is appended to existing contents.
3711cb0ef41Sopenharmony_ci     * @param pos       On input: an alignment field, if desired.
3721cb0ef41Sopenharmony_ci     *                  On output: the offsets of the alignment field.
3731cb0ef41Sopenharmony_ci     * @return          Reference to 'appendTo' parameter.
3741cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
3751cb0ef41Sopenharmony_ci     */
3761cb0ef41Sopenharmony_ci    virtual UnicodeString& format(double number,
3771cb0ef41Sopenharmony_ci                                  UnicodeString& appendTo,
3781cb0ef41Sopenharmony_ci                                  FieldPosition& pos) const override;
3791cb0ef41Sopenharmony_ci    /**
3801cb0ef41Sopenharmony_ci     * Formats an int32_t number using this object's choices.
3811cb0ef41Sopenharmony_ci     *
3821cb0ef41Sopenharmony_ci     * @param number    The value to be formatted.
3831cb0ef41Sopenharmony_ci     * @param appendTo  Output parameter to receive result.
3841cb0ef41Sopenharmony_ci     *                  Result is appended to existing contents.
3851cb0ef41Sopenharmony_ci     * @param pos       On input: an alignment field, if desired.
3861cb0ef41Sopenharmony_ci     *                  On output: the offsets of the alignment field.
3871cb0ef41Sopenharmony_ci     * @return          Reference to 'appendTo' parameter.
3881cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
3891cb0ef41Sopenharmony_ci     */
3901cb0ef41Sopenharmony_ci    virtual UnicodeString& format(int32_t number,
3911cb0ef41Sopenharmony_ci                                  UnicodeString& appendTo,
3921cb0ef41Sopenharmony_ci                                  FieldPosition& pos) const override;
3931cb0ef41Sopenharmony_ci
3941cb0ef41Sopenharmony_ci    /**
3951cb0ef41Sopenharmony_ci     * Formats an int64_t number using this object's choices.
3961cb0ef41Sopenharmony_ci     *
3971cb0ef41Sopenharmony_ci     * @param number    The value to be formatted.
3981cb0ef41Sopenharmony_ci     * @param appendTo  Output parameter to receive result.
3991cb0ef41Sopenharmony_ci     *                  Result is appended to existing contents.
4001cb0ef41Sopenharmony_ci     * @param pos       On input: an alignment field, if desired.
4011cb0ef41Sopenharmony_ci     *                  On output: the offsets of the alignment field.
4021cb0ef41Sopenharmony_ci     * @return          Reference to 'appendTo' parameter.
4031cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
4041cb0ef41Sopenharmony_ci     */
4051cb0ef41Sopenharmony_ci    virtual UnicodeString& format(int64_t number,
4061cb0ef41Sopenharmony_ci                                  UnicodeString& appendTo,
4071cb0ef41Sopenharmony_ci                                  FieldPosition& pos) const override;
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ci    /**
4101cb0ef41Sopenharmony_ci     * Formats an array of objects using this object's choices.
4111cb0ef41Sopenharmony_ci     *
4121cb0ef41Sopenharmony_ci     * @param objs      The array of objects to be formatted.
4131cb0ef41Sopenharmony_ci     * @param cnt       The size of objs.
4141cb0ef41Sopenharmony_ci     * @param appendTo  Output parameter to receive result.
4151cb0ef41Sopenharmony_ci     *                  Result is appended to existing contents.
4161cb0ef41Sopenharmony_ci     * @param pos       On input: an alignment field, if desired.
4171cb0ef41Sopenharmony_ci     *                  On output: the offsets of the alignment field.
4181cb0ef41Sopenharmony_ci     * @param success   Output param set to success/failure code on
4191cb0ef41Sopenharmony_ci     *                  exit.
4201cb0ef41Sopenharmony_ci     * @return          Reference to 'appendTo' parameter.
4211cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
4221cb0ef41Sopenharmony_ci     */
4231cb0ef41Sopenharmony_ci    virtual UnicodeString& format(const Formattable* objs,
4241cb0ef41Sopenharmony_ci                                  int32_t cnt,
4251cb0ef41Sopenharmony_ci                                  UnicodeString& appendTo,
4261cb0ef41Sopenharmony_ci                                  FieldPosition& pos,
4271cb0ef41Sopenharmony_ci                                  UErrorCode& success) const;
4281cb0ef41Sopenharmony_ci
4291cb0ef41Sopenharmony_ci   using NumberFormat::parse;
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci   /**
4321cb0ef41Sopenharmony_ci    * Looks for the longest match of any message string on the input text and,
4331cb0ef41Sopenharmony_ci    * if there is a match, sets the result object to the corresponding range's number.
4341cb0ef41Sopenharmony_ci    *
4351cb0ef41Sopenharmony_ci    * If no string matches, then the parsePosition is unchanged.
4361cb0ef41Sopenharmony_ci    *
4371cb0ef41Sopenharmony_ci    * @param text           The text to be parsed.
4381cb0ef41Sopenharmony_ci    * @param result         Formattable to be set to the parse result.
4391cb0ef41Sopenharmony_ci    *                       If parse fails, return contents are undefined.
4401cb0ef41Sopenharmony_ci    * @param parsePosition  The position to start parsing at on input.
4411cb0ef41Sopenharmony_ci    *                       On output, moved to after the last successfully
4421cb0ef41Sopenharmony_ci    *                       parse character. On parse failure, does not change.
4431cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
4441cb0ef41Sopenharmony_ci    */
4451cb0ef41Sopenharmony_ci    virtual void parse(const UnicodeString& text,
4461cb0ef41Sopenharmony_ci                       Formattable& result,
4471cb0ef41Sopenharmony_ci                       ParsePosition& parsePosition) const override;
4481cb0ef41Sopenharmony_ci
4491cb0ef41Sopenharmony_ci    /**
4501cb0ef41Sopenharmony_ci     * Returns a unique class ID POLYMORPHICALLY. Part of ICU's "poor man's RTTI".
4511cb0ef41Sopenharmony_ci     *
4521cb0ef41Sopenharmony_ci     * @return          The class ID for this object. All objects of a
4531cb0ef41Sopenharmony_ci     *                  given class have the same class ID.  Objects of
4541cb0ef41Sopenharmony_ci     *                  other classes have different class IDs.
4551cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
4561cb0ef41Sopenharmony_ci     */
4571cb0ef41Sopenharmony_ci    virtual UClassID getDynamicClassID(void) const override;
4581cb0ef41Sopenharmony_ci
4591cb0ef41Sopenharmony_ci    /**
4601cb0ef41Sopenharmony_ci     * Returns the class ID for this class.  This is useful only for
4611cb0ef41Sopenharmony_ci     * comparing to a return value from getDynamicClassID().  For example:
4621cb0ef41Sopenharmony_ci     * <pre>
4631cb0ef41Sopenharmony_ci     * .       Base* polymorphic_pointer = createPolymorphicObject();
4641cb0ef41Sopenharmony_ci     * .       if (polymorphic_pointer->getDynamicClassID() ==
4651cb0ef41Sopenharmony_ci     * .           Derived::getStaticClassID()) ...
4661cb0ef41Sopenharmony_ci     * </pre>
4671cb0ef41Sopenharmony_ci     * @return          The class ID for all objects of this class.
4681cb0ef41Sopenharmony_ci     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
4691cb0ef41Sopenharmony_ci     */
4701cb0ef41Sopenharmony_ci    static UClassID U_EXPORT2 getStaticClassID(void);
4711cb0ef41Sopenharmony_ci
4721cb0ef41Sopenharmony_ciprivate:
4731cb0ef41Sopenharmony_ci    /**
4741cb0ef41Sopenharmony_ci     * Converts a double value to a string.
4751cb0ef41Sopenharmony_ci     * @param value the double number to be converted.
4761cb0ef41Sopenharmony_ci     * @param string the result string.
4771cb0ef41Sopenharmony_ci     * @return the converted string.
4781cb0ef41Sopenharmony_ci     */
4791cb0ef41Sopenharmony_ci    static UnicodeString& dtos(double value, UnicodeString& string);
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ci    ChoiceFormat() = delete; // default constructor not implemented
4821cb0ef41Sopenharmony_ci
4831cb0ef41Sopenharmony_ci    /**
4841cb0ef41Sopenharmony_ci     * Construct a new ChoiceFormat with the limits and the corresponding formats
4851cb0ef41Sopenharmony_ci     * based on the pattern.
4861cb0ef41Sopenharmony_ci     *
4871cb0ef41Sopenharmony_ci     * @param newPattern   Pattern used to construct object.
4881cb0ef41Sopenharmony_ci     * @param parseError   Struct to receive information on position
4891cb0ef41Sopenharmony_ci     *                     of error if an error is encountered.
4901cb0ef41Sopenharmony_ci     * @param status       Output param to receive success code.  If the
4911cb0ef41Sopenharmony_ci     *                     pattern cannot be parsed, set to failure code.
4921cb0ef41Sopenharmony_ci     */
4931cb0ef41Sopenharmony_ci    ChoiceFormat(const UnicodeString& newPattern,
4941cb0ef41Sopenharmony_ci                 UParseError& parseError,
4951cb0ef41Sopenharmony_ci                 UErrorCode& status);
4961cb0ef41Sopenharmony_ci
4971cb0ef41Sopenharmony_ci    friend class MessageFormat;
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_ci    virtual void setChoices(const double* limits,
5001cb0ef41Sopenharmony_ci                            const UBool* closures,
5011cb0ef41Sopenharmony_ci                            const UnicodeString* formats,
5021cb0ef41Sopenharmony_ci                            int32_t count,
5031cb0ef41Sopenharmony_ci                            UErrorCode &errorCode);
5041cb0ef41Sopenharmony_ci
5051cb0ef41Sopenharmony_ci    /**
5061cb0ef41Sopenharmony_ci     * Finds the ChoiceFormat sub-message for the given number.
5071cb0ef41Sopenharmony_ci     * @param pattern A MessagePattern.
5081cb0ef41Sopenharmony_ci     * @param partIndex the index of the first ChoiceFormat argument style part.
5091cb0ef41Sopenharmony_ci     * @param number a number to be mapped to one of the ChoiceFormat argument's intervals
5101cb0ef41Sopenharmony_ci     * @return the sub-message start part index.
5111cb0ef41Sopenharmony_ci     */
5121cb0ef41Sopenharmony_ci    static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
5131cb0ef41Sopenharmony_ci
5141cb0ef41Sopenharmony_ci    static double parseArgument(
5151cb0ef41Sopenharmony_ci            const MessagePattern &pattern, int32_t partIndex,
5161cb0ef41Sopenharmony_ci            const UnicodeString &source, ParsePosition &pos);
5171cb0ef41Sopenharmony_ci
5181cb0ef41Sopenharmony_ci    /**
5191cb0ef41Sopenharmony_ci     * Matches the pattern string from the end of the partIndex to
5201cb0ef41Sopenharmony_ci     * the beginning of the limitPartIndex,
5211cb0ef41Sopenharmony_ci     * including all syntax except SKIP_SYNTAX,
5221cb0ef41Sopenharmony_ci     * against the source string starting at sourceOffset.
5231cb0ef41Sopenharmony_ci     * If they match, returns the length of the source string match.
5241cb0ef41Sopenharmony_ci     * Otherwise returns -1.
5251cb0ef41Sopenharmony_ci     */
5261cb0ef41Sopenharmony_ci    static int32_t matchStringUntilLimitPart(
5271cb0ef41Sopenharmony_ci            const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
5281cb0ef41Sopenharmony_ci            const UnicodeString &source, int32_t sourceOffset);
5291cb0ef41Sopenharmony_ci
5301cb0ef41Sopenharmony_ci    /**
5311cb0ef41Sopenharmony_ci     * Some of the ChoiceFormat constructors do not have a UErrorCode parameter.
5321cb0ef41Sopenharmony_ci     * We need _some_ way to provide one for the MessagePattern constructor.
5331cb0ef41Sopenharmony_ci     * Alternatively, the MessagePattern could be a pointer field, but that is
5341cb0ef41Sopenharmony_ci     * not nice either.
5351cb0ef41Sopenharmony_ci     */
5361cb0ef41Sopenharmony_ci    UErrorCode constructorErrorCode;
5371cb0ef41Sopenharmony_ci
5381cb0ef41Sopenharmony_ci    /**
5391cb0ef41Sopenharmony_ci     * The MessagePattern which contains the parsed structure of the pattern string.
5401cb0ef41Sopenharmony_ci     *
5411cb0ef41Sopenharmony_ci     * Starting with ICU 4.8, the MessagePattern contains a sequence of
5421cb0ef41Sopenharmony_ci     * numeric/selector/message parts corresponding to the parsed pattern.
5431cb0ef41Sopenharmony_ci     * For details see the MessagePattern class API docs.
5441cb0ef41Sopenharmony_ci     */
5451cb0ef41Sopenharmony_ci    MessagePattern msgPattern;
5461cb0ef41Sopenharmony_ci
5471cb0ef41Sopenharmony_ci    /**
5481cb0ef41Sopenharmony_ci     * Docs & fields from before ICU 4.8, before MessagePattern was used.
5491cb0ef41Sopenharmony_ci     * Commented out, and left only for explanation of semantics.
5501cb0ef41Sopenharmony_ci     * --------
5511cb0ef41Sopenharmony_ci     * Each ChoiceFormat divides the range -Inf..+Inf into fCount
5521cb0ef41Sopenharmony_ci     * intervals.  The intervals are:
5531cb0ef41Sopenharmony_ci     *
5541cb0ef41Sopenharmony_ci     *         0: fChoiceLimits[0]..fChoiceLimits[1]
5551cb0ef41Sopenharmony_ci     *         1: fChoiceLimits[1]..fChoiceLimits[2]
5561cb0ef41Sopenharmony_ci     *        ...
5571cb0ef41Sopenharmony_ci     *  fCount-2: fChoiceLimits[fCount-2]..fChoiceLimits[fCount-1]
5581cb0ef41Sopenharmony_ci     *  fCount-1: fChoiceLimits[fCount-1]..+Inf
5591cb0ef41Sopenharmony_ci     *
5601cb0ef41Sopenharmony_ci     * Interval 0 is special; during formatting (mapping numbers to
5611cb0ef41Sopenharmony_ci     * strings), it also contains all numbers less than
5621cb0ef41Sopenharmony_ci     * fChoiceLimits[0], as well as NaN values.
5631cb0ef41Sopenharmony_ci     *
5641cb0ef41Sopenharmony_ci     * Interval i maps to and from string fChoiceFormats[i].  When
5651cb0ef41Sopenharmony_ci     * parsing (mapping strings to numbers), then intervals map to
5661cb0ef41Sopenharmony_ci     * their lower limit, that is, interval i maps to fChoiceLimit[i].
5671cb0ef41Sopenharmony_ci     *
5681cb0ef41Sopenharmony_ci     * The intervals may be closed, half open, or open.  This affects
5691cb0ef41Sopenharmony_ci     * formatting but does not affect parsing.  Interval i is affected
5701cb0ef41Sopenharmony_ci     * by fClosures[i] and fClosures[i+1].  If fClosures[i]
5711cb0ef41Sopenharmony_ci     * is false, then the value fChoiceLimits[i] is in interval i.
5721cb0ef41Sopenharmony_ci     * That is, intervals i and i are:
5731cb0ef41Sopenharmony_ci     *
5741cb0ef41Sopenharmony_ci     *  i-1:                 ... x < fChoiceLimits[i]
5751cb0ef41Sopenharmony_ci     *    i: fChoiceLimits[i] <= x ...
5761cb0ef41Sopenharmony_ci     *
5771cb0ef41Sopenharmony_ci     * If fClosures[i] is true, then the value fChoiceLimits[i] is
5781cb0ef41Sopenharmony_ci     * in interval i-1.  That is, intervals i-1 and i are:
5791cb0ef41Sopenharmony_ci     *
5801cb0ef41Sopenharmony_ci     *  i-1:                ... x <= fChoiceLimits[i]
5811cb0ef41Sopenharmony_ci     *    i: fChoiceLimits[i] < x ...
5821cb0ef41Sopenharmony_ci     *
5831cb0ef41Sopenharmony_ci     * Because of the nature of interval 0, fClosures[0] has no
5841cb0ef41Sopenharmony_ci     * effect.
5851cb0ef41Sopenharmony_ci     */
5861cb0ef41Sopenharmony_ci    // double*         fChoiceLimits;
5871cb0ef41Sopenharmony_ci    // UBool*          fClosures;
5881cb0ef41Sopenharmony_ci    // UnicodeString*  fChoiceFormats;
5891cb0ef41Sopenharmony_ci    // int32_t         fCount;
5901cb0ef41Sopenharmony_ci};
5911cb0ef41Sopenharmony_ci
5921cb0ef41Sopenharmony_ci
5931cb0ef41Sopenharmony_ciU_NAMESPACE_END
5941cb0ef41Sopenharmony_ci
5951cb0ef41Sopenharmony_ci#endif  // U_HIDE_DEPRECATED_API
5961cb0ef41Sopenharmony_ci#endif /* #if !UCONFIG_NO_FORMATTING */
5971cb0ef41Sopenharmony_ci
5981cb0ef41Sopenharmony_ci#endif /* U_SHOW_CPLUSPLUS_API */
5991cb0ef41Sopenharmony_ci
6001cb0ef41Sopenharmony_ci#endif // CHOICFMT_H
6011cb0ef41Sopenharmony_ci//eof
602