intl/icu/source/i18n/unicode/choicfmt.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/unicode/choicfmt.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,594 @@
     1.4 +/*
     1.5 +********************************************************************************
     1.6 +*   Copyright (C) 1997-2013, International Business Machines
     1.7 +*   Corporation and others.  All Rights Reserved.
     1.8 +********************************************************************************
     1.9 +*
    1.10 +* File CHOICFMT.H
    1.11 +*
    1.12 +* Modification History:
    1.13 +*
    1.14 +*   Date        Name        Description
    1.15 +*   02/19/97    aliu        Converted from java.
    1.16 +*   03/20/97    helena      Finished first cut of implementation and got rid
    1.17 +*                           of nextDouble/previousDouble and replaced with
    1.18 +*                           boolean array.
    1.19 +*   4/10/97     aliu        Clean up.  Modified to work on AIX.
    1.20 +*   8/6/97      nos         Removed overloaded constructor, member var 'buffer'.
    1.21 +*   07/22/98    stephen     Removed operator!= (implemented in Format)
    1.22 +********************************************************************************
    1.23 +*/
    1.24 +
    1.25 +#ifndef CHOICFMT_H
    1.26 +#define CHOICFMT_H
    1.27 +
    1.28 +#include "unicode/utypes.h"
    1.29 +
    1.30 +/**
    1.31 + * \file
    1.32 + * \brief C++ API: Choice Format.
    1.33 + */
    1.34 +
    1.35 +#if !UCONFIG_NO_FORMATTING
    1.36 +#ifndef U_HIDE_DEPRECATED_API
    1.37 +
    1.38 +#include "unicode/fieldpos.h"
    1.39 +#include "unicode/format.h"
    1.40 +#include "unicode/messagepattern.h"
    1.41 +#include "unicode/numfmt.h"
    1.42 +#include "unicode/unistr.h"
    1.43 +
    1.44 +U_NAMESPACE_BEGIN
    1.45 +
    1.46 +class MessageFormat;
    1.47 +
    1.48 +/**
    1.49 + * ChoiceFormat converts between ranges of numeric values and strings for those ranges.
    1.50 + * The strings must conform to the MessageFormat pattern syntax.
    1.51 + *
    1.52 + * <p><em><code>ChoiceFormat</code> is probably not what you need.
    1.53 + * Please use <code>MessageFormat</code>
    1.54 + * with <code>plural</code> arguments for proper plural selection,
    1.55 + * and <code>select</code> arguments for simple selection among a fixed set of choices!</em></p>
    1.56 + *
    1.57 + * <p>A <code>ChoiceFormat</code> splits
    1.58 + * the real number line \htmlonly<code>-&#x221E;</code> to
    1.59 + * <code>+&#x221E;</code>\endhtmlonly into two
    1.60 + * or more contiguous ranges. Each range is mapped to a
    1.61 + * string.</p>
    1.62 + *
    1.63 + * <p><code>ChoiceFormat</code> was originally intended
    1.64 + * for displaying grammatically correct
    1.65 + * plurals such as &quot;There is one file.&quot; vs. &quot;There are 2 files.&quot;
    1.66 + * <em>However,</em> plural rules for many languages
    1.67 + * are too complex for the capabilities of ChoiceFormat,
    1.68 + * and its requirement of specifying the precise rules for each message
    1.69 + * is unmanageable for translators.</p>
    1.70 + *
    1.71 + * <p>There are two methods of defining a <code>ChoiceFormat</code>; both
    1.72 + * are equivalent.  The first is by using a string pattern. This is the
    1.73 + * preferred method in most cases.  The second method is through direct
    1.74 + * specification of the arrays that logically make up the
    1.75 + * <code>ChoiceFormat</code>.</p>
    1.76 + *
    1.77 + * <p>Note: Typically, choice formatting is done (if done at all) via <code>MessageFormat</code>
    1.78 + * with a <code>choice</code> argument type,
    1.79 + * rather than using a stand-alone <code>ChoiceFormat</code>.</p>
    1.80 + *
    1.81 + * <h5>Patterns and Their Interpretation</h5>
    1.82 + *
    1.83 + * <p>The pattern string defines the range boundaries and the strings for each number range.
    1.84 + * Syntax:
    1.85 + * <pre>
    1.86 + * choiceStyle = number separator message ('|' number separator message)*
    1.87 + * number = normal_number | ['-'] \htmlonly&#x221E;\endhtmlonly (U+221E, infinity)
    1.88 + * normal_number = double value (unlocalized ASCII string)
    1.89 + * separator = less_than | less_than_or_equal
    1.90 + * less_than = '<'
    1.91 + * less_than_or_equal = '#' | \htmlonly&#x2264;\endhtmlonly (U+2264)
    1.92 + * message: see {@link MessageFormat}
    1.93 + * </pre>
    1.94 + * Pattern_White_Space between syntax elements is ignored, except
    1.95 + * around each range's sub-message.</p>
    1.96 + *
    1.97 + * <p>Each numeric sub-range extends from the current range's number
    1.98 + * to the next range's number.
    1.99 + * The number itself is included in its range if a <code>less_than_or_equal</code> sign is used,
   1.100 + * and excluded from its range (and instead included in the previous range)
   1.101 + * if a <code>less_than</code> sign is used.</p>
   1.102 + *
   1.103 + * <p>When a <code>ChoiceFormat</code> is constructed from
   1.104 + * arrays of numbers, closure flags and strings,
   1.105 + * they are interpreted just like
   1.106 + * the sequence of <code>(number separator string)</code> in an equivalent pattern string.
   1.107 + * <code>closure[i]==TRUE</code> corresponds to a <code>less_than</code> separator sign.
   1.108 + * The equivalent pattern string will be constructed automatically.</p>
   1.109 + *
   1.110 + * <p>During formatting, a number is mapped to the first range
   1.111 + * where the number is not greater than the range's upper limit.
   1.112 + * That range's message string is returned. A NaN maps to the very first range.</p>
   1.113 + *
   1.114 + * <p>During parsing, a range is selected for the longest match of
   1.115 + * any range's message. That range's number is returned, ignoring the separator/closure.
   1.116 + * Only a simple string match is performed, without parsing of arguments that
   1.117 + * might be specified in the message strings.</p>
   1.118 + *
   1.119 + * <p>Note that the first range's number is ignored in formatting
   1.120 + * but may be returned from parsing.</p>
   1.121 + *
   1.122 + * <h5>Examples</h5>
   1.123 + *
   1.124 + * <p>Here is an example of two arrays that map the number
   1.125 + * <code>1..7</code> to the English day of the week abbreviations
   1.126 + * <code>Sun..Sat</code>. No closures array is given; this is the same as
   1.127 + * specifying all closures to be <code>FALSE</code>.</p>
   1.128 + *
   1.129 + * <pre>    {1,2,3,4,5,6,7},
   1.130 + *     {&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thur&quot;,&quot;Fri&quot;,&quot;Sat&quot;}</pre>
   1.131 + *
   1.132 + * <p>Here is an example that maps the ranges [-Inf, 1), [1, 1], and (1,
   1.133 + * +Inf] to three strings. That is, the number line is split into three
   1.134 + * ranges: x &lt; 1.0, x = 1.0, and x &gt; 1.0.
   1.135 + * (The round parentheses in the notation above indicate an exclusive boundary,
   1.136 + * like the turned bracket in European notation: [-Inf, 1) == [-Inf, 1[  )</p>
   1.137 + *
   1.138 + * <pre>    {0, 1, 1},
   1.139 + *     {FALSE, FALSE, TRUE},
   1.140 + *     {&quot;no files&quot;, &quot;one file&quot;, &quot;many files&quot;}</pre>
   1.141 + *
   1.142 + * <p>Here is an example that shows formatting and parsing: </p>
   1.143 + *
   1.144 + * \code
   1.145 + *   #include <unicode/choicfmt.h>
   1.146 + *   #include <unicode/unistr.h>
   1.147 + *   #include <iostream.h>
   1.148 + *
   1.149 + *   int main(int argc, char *argv[]) {
   1.150 + *       double limits[] = {1,2,3,4,5,6,7};
   1.151 + *       UnicodeString monthNames[] = {
   1.152 + *           "Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
   1.153 + *       ChoiceFormat fmt(limits, monthNames, 7);
   1.154 + *       UnicodeString str;
   1.155 + *       char buf[256];
   1.156 + *       for (double x = 1.0; x <= 8.0; x += 1.0) {
   1.157 + *           fmt.format(x, str);
   1.158 + *           str.extract(0, str.length(), buf, 256, "");
   1.159 + *           str.truncate(0);
   1.160 + *           cout << x << " -> "
   1.161 + *                << buf << endl;
   1.162 + *       }
   1.163 + *       cout << endl;
   1.164 + *       return 0;
   1.165 + *   }
   1.166 + * \endcode
   1.167 + *
   1.168 + * <p><em>User subclasses are not supported.</em> While clients may write
   1.169 + * subclasses, such code will not necessarily work and will not be
   1.170 + * guaranteed to work stably from release to release.
   1.171 + *
   1.172 + * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.173 + */
   1.174 +class U_I18N_API ChoiceFormat: public NumberFormat {
   1.175 +public:
   1.176 +    /**
   1.177 +     * Constructs a new ChoiceFormat from the pattern string.
   1.178 +     *
   1.179 +     * @param pattern   Pattern used to construct object.
   1.180 +     * @param status    Output param to receive success code.  If the
   1.181 +     *                  pattern cannot be parsed, set to failure code.
   1.182 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.183 +     */
   1.184 +    ChoiceFormat(const UnicodeString& pattern,
   1.185 +                 UErrorCode& status);
   1.186 +
   1.187 +
   1.188 +    /**
   1.189 +     * Constructs a new ChoiceFormat with the given limits and message strings.
   1.190 +     * All closure flags default to <code>FALSE</code>,
   1.191 +     * equivalent to <code>less_than_or_equal</code> separators.
   1.192 +     *
   1.193 +     * Copies the limits and formats instead of adopting them.
   1.194 +     *
   1.195 +     * @param limits    Array of limit values.
   1.196 +     * @param formats   Array of formats.
   1.197 +     * @param count     Size of 'limits' and 'formats' arrays.
   1.198 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.199 +     */
   1.200 +    ChoiceFormat(const double* limits,
   1.201 +                 const UnicodeString* formats,
   1.202 +                 int32_t count );
   1.203 +
   1.204 +    /**
   1.205 +     * Constructs a new ChoiceFormat with the given limits, closure flags and message strings.
   1.206 +     *
   1.207 +     * Copies the limits and formats instead of adopting them.
   1.208 +     *
   1.209 +     * @param limits Array of limit values
   1.210 +     * @param closures Array of booleans specifying whether each
   1.211 +     * element of 'limits' is open or closed.  If FALSE, then the
   1.212 +     * corresponding limit number is a member of its range.
   1.213 +     * If TRUE, then the limit number belongs to the previous range it.
   1.214 +     * @param formats Array of formats
   1.215 +     * @param count Size of 'limits', 'closures', and 'formats' arrays
   1.216 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.217 +     */
   1.218 +    ChoiceFormat(const double* limits,
   1.219 +                 const UBool* closures,
   1.220 +                 const UnicodeString* formats,
   1.221 +                 int32_t count);
   1.222 +
   1.223 +    /**
   1.224 +     * Copy constructor.
   1.225 +     *
   1.226 +     * @param that   ChoiceFormat object to be copied from
   1.227 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.228 +     */
   1.229 +    ChoiceFormat(const ChoiceFormat& that);
   1.230 +
   1.231 +    /**
   1.232 +     * Assignment operator.
   1.233 +     *
   1.234 +     * @param that   ChoiceFormat object to be copied
   1.235 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.236 +     */
   1.237 +    const ChoiceFormat& operator=(const ChoiceFormat& that);
   1.238 +
   1.239 +    /**
   1.240 +     * Destructor.
   1.241 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.242 +     */
   1.243 +    virtual ~ChoiceFormat();
   1.244 +
   1.245 +    /**
   1.246 +     * Clones this Format object. The caller owns the
   1.247 +     * result and must delete it when done.
   1.248 +     *
   1.249 +     * @return a copy of this object
   1.250 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.251 +     */
   1.252 +    virtual Format* clone(void) const;
   1.253 +
   1.254 +    /**
   1.255 +     * Returns true if the given Format objects are semantically equal.
   1.256 +     * Objects of different subclasses are considered unequal.
   1.257 +     *
   1.258 +     * @param other    ChoiceFormat object to be compared
   1.259 +     * @return         true if other is the same as this.
   1.260 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.261 +     */
   1.262 +    virtual UBool operator==(const Format& other) const;
   1.263 +
   1.264 +    /**
   1.265 +     * Sets the pattern.
   1.266 +     * @param pattern   The pattern to be applied.
   1.267 +     * @param status    Output param set to success/failure code on
   1.268 +     *                  exit. If the pattern is invalid, this will be
   1.269 +     *                  set to a failure result.
   1.270 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.271 +     */
   1.272 +    virtual void applyPattern(const UnicodeString& pattern,
   1.273 +                              UErrorCode& status);
   1.274 +
   1.275 +    /**
   1.276 +     * Sets the pattern.
   1.277 +     * @param pattern    The pattern to be applied.
   1.278 +     * @param parseError Struct to receive information on position
   1.279 +     *                   of error if an error is encountered
   1.280 +     * @param status     Output param set to success/failure code on
   1.281 +     *                   exit. If the pattern is invalid, this will be
   1.282 +     *                   set to a failure result.
   1.283 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.284 +     */
   1.285 +    virtual void applyPattern(const UnicodeString& pattern,
   1.286 +                             UParseError& parseError,
   1.287 +                             UErrorCode& status);
   1.288 +    /**
   1.289 +     * Gets the pattern.
   1.290 +     *
   1.291 +     * @param pattern    Output param which will receive the pattern
   1.292 +     *                   Previous contents are deleted.
   1.293 +     * @return    A reference to 'pattern'
   1.294 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.295 +     */
   1.296 +    virtual UnicodeString& toPattern(UnicodeString &pattern) const;
   1.297 +
   1.298 +    /**
   1.299 +     * Sets the choices to be used in formatting.
   1.300 +     * For details see the constructor with the same parameter list.
   1.301 +     *
   1.302 +     * @param limitsToCopy      Contains the top value that you want
   1.303 +     *                          parsed with that format,and should be in
   1.304 +     *                          ascending sorted order. When formatting X,
   1.305 +     *                          the choice will be the i, where limit[i]
   1.306 +     *                          &lt;= X &lt; limit[i+1].
   1.307 +     * @param formatsToCopy     The format strings you want to use for each limit.
   1.308 +     * @param count             The size of the above arrays.
   1.309 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.310 +     */
   1.311 +    virtual void setChoices(const double* limitsToCopy,
   1.312 +                            const UnicodeString* formatsToCopy,
   1.313 +                            int32_t count );
   1.314 +
   1.315 +    /**
   1.316 +     * Sets the choices to be used in formatting.
   1.317 +     * For details see the constructor with the same parameter list.
   1.318 +     *
   1.319 +     * @param limits Array of limits
   1.320 +     * @param closures Array of limit booleans
   1.321 +     * @param formats Array of format string
   1.322 +     * @param count The size of the above arrays
   1.323 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.324 +     */
   1.325 +    virtual void setChoices(const double* limits,
   1.326 +                            const UBool* closures,
   1.327 +                            const UnicodeString* formats,
   1.328 +                            int32_t count);
   1.329 +
   1.330 +    /**
   1.331 +     * Returns NULL and 0.
   1.332 +     * Before ICU 4.8, this used to return the choice limits array.
   1.333 +     *
   1.334 +     * @param count Will be set to 0.
   1.335 +     * @return NULL
   1.336 +     * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
   1.337 +     */
   1.338 +    virtual const double* getLimits(int32_t& count) const;
   1.339 +
   1.340 +    /**
   1.341 +     * Returns NULL and 0.
   1.342 +     * Before ICU 4.8, this used to return the limit booleans array.
   1.343 +     *
   1.344 +     * @param count Will be set to 0.
   1.345 +     * @return NULL
   1.346 +     * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
   1.347 +     */
   1.348 +    virtual const UBool* getClosures(int32_t& count) const;
   1.349 +
   1.350 +    /**
   1.351 +     * Returns NULL and 0.
   1.352 +     * Before ICU 4.8, this used to return the array of choice strings.
   1.353 +     *
   1.354 +     * @param count Will be set to 0.
   1.355 +     * @return NULL
   1.356 +     * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
   1.357 +     */
   1.358 +    virtual const UnicodeString* getFormats(int32_t& count) const;
   1.359 +
   1.360 +
   1.361 +    using NumberFormat::format;
   1.362 +
   1.363 +    /**
   1.364 +     * Formats a double number using this object's choices.
   1.365 +     *
   1.366 +     * @param number    The value to be formatted.
   1.367 +     * @param appendTo  Output parameter to receive result.
   1.368 +     *                  Result is appended to existing contents.
   1.369 +     * @param pos       On input: an alignment field, if desired.
   1.370 +     *                  On output: the offsets of the alignment field.
   1.371 +     * @return          Reference to 'appendTo' parameter.
   1.372 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.373 +     */
   1.374 +    virtual UnicodeString& format(double number,
   1.375 +                                  UnicodeString& appendTo,
   1.376 +                                  FieldPosition& pos) const;
   1.377 +    /**
   1.378 +     * Formats an int32_t number using this object's choices.
   1.379 +     *
   1.380 +     * @param number    The value to be formatted.
   1.381 +     * @param appendTo  Output parameter to receive result.
   1.382 +     *                  Result is appended to existing contents.
   1.383 +     * @param pos       On input: an alignment field, if desired.
   1.384 +     *                  On output: the offsets of the alignment field.
   1.385 +     * @return          Reference to 'appendTo' parameter.
   1.386 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.387 +     */
   1.388 +    virtual UnicodeString& format(int32_t number,
   1.389 +                                  UnicodeString& appendTo,
   1.390 +                                  FieldPosition& pos) const;
   1.391 +
   1.392 +    /**
   1.393 +     * Formats an int64_t number using this object's choices.
   1.394 +     *
   1.395 +     * @param number    The value to be formatted.
   1.396 +     * @param appendTo  Output parameter to receive result.
   1.397 +     *                  Result is appended to existing contents.
   1.398 +     * @param pos       On input: an alignment field, if desired.
   1.399 +     *                  On output: the offsets of the alignment field.
   1.400 +     * @return          Reference to 'appendTo' parameter.
   1.401 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.402 +     */
   1.403 +    virtual UnicodeString& format(int64_t number,
   1.404 +                                  UnicodeString& appendTo,
   1.405 +                                  FieldPosition& pos) const;
   1.406 +
   1.407 +    /**
   1.408 +     * Formats an array of objects using this object's choices.
   1.409 +     *
   1.410 +     * @param objs      The array of objects to be formatted.
   1.411 +     * @param cnt       The size of objs.
   1.412 +     * @param appendTo  Output parameter to receive result.
   1.413 +     *                  Result is appended to existing contents.
   1.414 +     * @param pos       On input: an alignment field, if desired.
   1.415 +     *                  On output: the offsets of the alignment field.
   1.416 +     * @param success   Output param set to success/failure code on
   1.417 +     *                  exit.
   1.418 +     * @return          Reference to 'appendTo' parameter.
   1.419 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.420 +     */
   1.421 +    virtual UnicodeString& format(const Formattable* objs,
   1.422 +                                  int32_t cnt,
   1.423 +                                  UnicodeString& appendTo,
   1.424 +                                  FieldPosition& pos,
   1.425 +                                  UErrorCode& success) const;
   1.426 +
   1.427 +   using NumberFormat::parse;
   1.428 +
   1.429 +   /**
   1.430 +    * Looks for the longest match of any message string on the input text and,
   1.431 +    * if there is a match, sets the result object to the corresponding range's number.
   1.432 +    *
   1.433 +    * If no string matches, then the parsePosition is unchanged.
   1.434 +    *
   1.435 +    * @param text           The text to be parsed.
   1.436 +    * @param result         Formattable to be set to the parse result.
   1.437 +    *                       If parse fails, return contents are undefined.
   1.438 +    * @param parsePosition  The position to start parsing at on input.
   1.439 +    *                       On output, moved to after the last successfully
   1.440 +    *                       parse character. On parse failure, does not change.
   1.441 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.442 +    */
   1.443 +    virtual void parse(const UnicodeString& text,
   1.444 +                       Formattable& result,
   1.445 +                       ParsePosition& parsePosition) const;
   1.446 +
   1.447 +    /**
   1.448 +     * Returns a unique class ID POLYMORPHICALLY. Part of ICU's "poor man's RTTI".
   1.449 +     *
   1.450 +     * @return          The class ID for this object. All objects of a
   1.451 +     *                  given class have the same class ID.  Objects of
   1.452 +     *                  other classes have different class IDs.
   1.453 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.454 +     */
   1.455 +    virtual UClassID getDynamicClassID(void) const;
   1.456 +
   1.457 +    /**
   1.458 +     * Returns the class ID for this class.  This is useful only for
   1.459 +     * comparing to a return value from getDynamicClassID().  For example:
   1.460 +     * <pre>
   1.461 +     * .       Base* polymorphic_pointer = createPolymorphicObject();
   1.462 +     * .       if (polymorphic_pointer->getDynamicClassID() ==
   1.463 +     * .           Derived::getStaticClassID()) ...
   1.464 +     * </pre>
   1.465 +     * @return          The class ID for all objects of this class.
   1.466 +     * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
   1.467 +     */
   1.468 +    static UClassID U_EXPORT2 getStaticClassID(void);
   1.469 +
   1.470 +private:
   1.471 +    /**
   1.472 +     * Converts a double value to a string.
   1.473 +     * @param value the double number to be converted.
   1.474 +     * @param string the result string.
   1.475 +     * @return the converted string.
   1.476 +     */
   1.477 +    static UnicodeString& dtos(double value, UnicodeString& string);
   1.478 +
   1.479 +    ChoiceFormat(); // default constructor not implemented
   1.480 +
   1.481 +    /**
   1.482 +     * Construct a new ChoiceFormat with the limits and the corresponding formats
   1.483 +     * based on the pattern.
   1.484 +     *
   1.485 +     * @param newPattern   Pattern used to construct object.
   1.486 +     * @param parseError   Struct to receive information on position
   1.487 +     *                     of error if an error is encountered.
   1.488 +     * @param status       Output param to receive success code.  If the
   1.489 +     *                     pattern cannot be parsed, set to failure code.
   1.490 +     */
   1.491 +    ChoiceFormat(const UnicodeString& newPattern,
   1.492 +                 UParseError& parseError,
   1.493 +                 UErrorCode& status);
   1.494 +
   1.495 +    friend class MessageFormat;
   1.496 +
   1.497 +    virtual void setChoices(const double* limits,
   1.498 +                            const UBool* closures,
   1.499 +                            const UnicodeString* formats,
   1.500 +                            int32_t count,
   1.501 +                            UErrorCode &errorCode);
   1.502 +
   1.503 +    /**
   1.504 +     * Finds the ChoiceFormat sub-message for the given number.
   1.505 +     * @param pattern A MessagePattern.
   1.506 +     * @param partIndex the index of the first ChoiceFormat argument style part.
   1.507 +     * @param number a number to be mapped to one of the ChoiceFormat argument's intervals
   1.508 +     * @return the sub-message start part index.
   1.509 +     */
   1.510 +    static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
   1.511 +
   1.512 +    static double parseArgument(
   1.513 +            const MessagePattern &pattern, int32_t partIndex,
   1.514 +            const UnicodeString &source, ParsePosition &pos);
   1.515 +
   1.516 +    /**
   1.517 +     * Matches the pattern string from the end of the partIndex to
   1.518 +     * the beginning of the limitPartIndex,
   1.519 +     * including all syntax except SKIP_SYNTAX,
   1.520 +     * against the source string starting at sourceOffset.
   1.521 +     * If they match, returns the length of the source string match.
   1.522 +     * Otherwise returns -1.
   1.523 +     */
   1.524 +    static int32_t matchStringUntilLimitPart(
   1.525 +            const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
   1.526 +            const UnicodeString &source, int32_t sourceOffset);
   1.527 +
   1.528 +    /**
   1.529 +     * Some of the ChoiceFormat constructors do not have a UErrorCode paramater.
   1.530 +     * We need _some_ way to provide one for the MessagePattern constructor.
   1.531 +     * Alternatively, the MessagePattern could be a pointer field, but that is
   1.532 +     * not nice either.
   1.533 +     */
   1.534 +    UErrorCode constructorErrorCode;
   1.535 +
   1.536 +    /**
   1.537 +     * The MessagePattern which contains the parsed structure of the pattern string.
   1.538 +     *
   1.539 +     * Starting with ICU 4.8, the MessagePattern contains a sequence of
   1.540 +     * numeric/selector/message parts corresponding to the parsed pattern.
   1.541 +     * For details see the MessagePattern class API docs.
   1.542 +     */
   1.543 +    MessagePattern msgPattern;
   1.544 +
   1.545 +    /**
   1.546 +     * Docs & fields from before ICU 4.8, before MessagePattern was used.
   1.547 +     * Commented out, and left only for explanation of semantics.
   1.548 +     * --------
   1.549 +     * Each ChoiceFormat divides the range -Inf..+Inf into fCount
   1.550 +     * intervals.  The intervals are:
   1.551 +     *
   1.552 +     *         0: fChoiceLimits[0]..fChoiceLimits[1]
   1.553 +     *         1: fChoiceLimits[1]..fChoiceLimits[2]
   1.554 +     *        ...
   1.555 +     *  fCount-2: fChoiceLimits[fCount-2]..fChoiceLimits[fCount-1]
   1.556 +     *  fCount-1: fChoiceLimits[fCount-1]..+Inf
   1.557 +     *
   1.558 +     * Interval 0 is special; during formatting (mapping numbers to
   1.559 +     * strings), it also contains all numbers less than
   1.560 +     * fChoiceLimits[0], as well as NaN values.
   1.561 +     *
   1.562 +     * Interval i maps to and from string fChoiceFormats[i].  When
   1.563 +     * parsing (mapping strings to numbers), then intervals map to
   1.564 +     * their lower limit, that is, interval i maps to fChoiceLimit[i].
   1.565 +     *
   1.566 +     * The intervals may be closed, half open, or open.  This affects
   1.567 +     * formatting but does not affect parsing.  Interval i is affected
   1.568 +     * by fClosures[i] and fClosures[i+1].  If fClosures[i]
   1.569 +     * is FALSE, then the value fChoiceLimits[i] is in interval i.
   1.570 +     * That is, intervals i and i are:
   1.571 +     *
   1.572 +     *  i-1:                 ... x < fChoiceLimits[i]
   1.573 +     *    i: fChoiceLimits[i] <= x ...
   1.574 +     *
   1.575 +     * If fClosures[i] is TRUE, then the value fChoiceLimits[i] is
   1.576 +     * in interval i-1.  That is, intervals i-1 and i are:
   1.577 +     *
   1.578 +     *  i-1:                ... x <= fChoiceLimits[i]
   1.579 +     *    i: fChoiceLimits[i] < x ...
   1.580 +     *
   1.581 +     * Because of the nature of interval 0, fClosures[0] has no
   1.582 +     * effect.
   1.583 +     */
   1.584 +    // double*         fChoiceLimits;
   1.585 +    // UBool*          fClosures;
   1.586 +    // UnicodeString*  fChoiceFormats;
   1.587 +    // int32_t         fCount;
   1.588 +};
   1.589 +
   1.590 +
   1.591 +U_NAMESPACE_END
   1.592 +
   1.593 +#endif  // U_HIDE_DEPRECATED_API
   1.594 +#endif /* #if !UCONFIG_NO_FORMATTING */
   1.595 +
   1.596 +#endif // CHOICFMT_H
   1.597 +//eof

mercurial