Coverage Report

Created: 2026-05-06 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/unicode/numfmt.h
Line
Count
Source
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
********************************************************************************
5
* Copyright (C) 1997-2016, International Business Machines Corporation and others.
6
* All Rights Reserved.
7
********************************************************************************
8
*
9
* File NUMFMT.H
10
*
11
* Modification History:
12
*
13
*   Date        Name        Description
14
*   02/19/97    aliu        Converted from java.
15
*   03/18/97    clhuang     Updated per C++ implementation.
16
*   04/17/97    aliu        Changed DigitCount to int per code review.
17
*    07/20/98    stephen        JDK 1.2 sync up. Added scientific support.
18
*                            Changed naming conventions to match C++ guidelines
19
*                            Deprecated Java style constants (eg, INTEGER_FIELD)
20
********************************************************************************
21
*/
22
23
#ifndef NUMFMT_H
24
#define NUMFMT_H
25
26
27
#include "unicode/utypes.h"
28
29
#if U_SHOW_CPLUSPLUS_API
30
31
/**
32
 * \file
33
 * \brief C++ API: Compatibility APIs for number formatting.
34
 */
35
36
#if !UCONFIG_NO_FORMATTING
37
38
#include "unicode/unistr.h"
39
#include "unicode/format.h"
40
#include "unicode/unum.h" // UNumberFormatStyle
41
#include "unicode/locid.h"
42
#include "unicode/stringpiece.h"
43
#include "unicode/curramt.h"
44
#include "unicode/udisplaycontext.h"
45
46
class NumberFormatTest;
47
48
U_NAMESPACE_BEGIN
49
50
class SharedNumberFormat;
51
52
#if !UCONFIG_NO_SERVICE
53
class NumberFormatFactory;
54
class StringEnumeration;
55
#endif
56
57
/**
58
 * <p><strong>IMPORTANT:</strong> New users are strongly encouraged to see if
59
 * numberformatter.h fits their use case.  Although not deprecated, this header
60
 * is provided for backwards compatibility only.
61
 *
62
 * Abstract base class for all number formats.  Provides interface for
63
 * formatting and parsing a number.  Also provides methods for
64
 * determining which locales have number formats, and what their names
65
 * are.
66
 *
67
 * \headerfile unicode/numfmt.h "unicode/numfmt.h"
68
 * <P>
69
 * NumberFormat helps you to format and parse numbers for any locale.
70
 * Your code can be completely independent of the locale conventions
71
 * for decimal points, thousands-separators, or even the particular
72
 * decimal digits used, or whether the number format is even decimal.
73
 * <P>
74
 * To format a number for the current Locale, use one of the static
75
 * factory methods:
76
 * \code
77
 *    #include <iostream>
78
 *    #include "unicode/numfmt.h"
79
 *    #include "unicode/unistr.h"
80
 *    #include "unicode/ustream.h"
81
 *    using namespace std;
82
 *    
83
 *    int main() {
84
 *        double myNumber = 7.0;
85
 *        UnicodeString myString;
86
 *        UErrorCode success = U_ZERO_ERROR;
87
 *        NumberFormat* nf = NumberFormat::createInstance(success);
88
 *        nf->format(myNumber, myString);
89
 *        cout << " Example 1: " << myString << endl;
90
 *    }
91
 * \endcode
92
 * Note that there are additional factory methods within subclasses of
93
 * NumberFormat.
94
 * <P>
95
 * If you are formatting multiple numbers, it is more efficient to get
96
 * the format and use it multiple times so that the system doesn't
97
 * have to fetch the information about the local language and country
98
 * conventions multiple times.
99
 * \code
100
 *     UnicodeString myString;
101
 *     UErrorCode success = U_ZERO_ERROR;
102
 *     NumberFormat *nf = NumberFormat::createInstance( success );
103
 *     for (int32_t number: {123, 3333, -1234567}) {
104
 *         nf->format(number, myString);
105
 *         myString += "; ";
106
 *     }
107
 *     cout << " Example 2: " << myString << endl;
108
 * \endcode
109
 * To format a number for a different Locale, specify it in the
110
 * call to \c createInstance().
111
 * \code
112
 *     nf = NumberFormat::createInstance(Locale::getFrench(), success);
113
 * \endcode
114
 * You can use a \c NumberFormat to parse also.
115
 * \code
116
 *    UErrorCode success;
117
 *    Formattable result(-999);  // initialized with error code
118
 *    nf->parse(myString, result, success);
119
 * \endcode
120
 * Use \c createInstance() to get the normal number format for a \c Locale.
121
 * There are other static factory methods available.  Use \c createCurrencyInstance()
122
 * to get the currency number format for that country.  Use \c createPercentInstance()
123
 * to get a format for displaying percentages. With this format, a
124
 * fraction from 0.53 is displayed as 53%.
125
 * <P>
126
 * The type of number formatting can be specified by passing a 'style' parameter to \c createInstance().
127
 * For example, use\n
128
 * \c createInstance(locale, UNUM_DECIMAL, errorCode) to get the normal number format,\n
129
 * \c createInstance(locale, UNUM_PERCENT, errorCode) to get a format for displaying percentage,\n
130
 * \c createInstance(locale, UNUM_SCIENTIFIC, errorCode) to get a format for displaying scientific number,\n
131
 * \c createInstance(locale, UNUM_CURRENCY, errorCode) to get the currency number format,
132
 * in which the currency is represented by its symbol, for example, "$3.00".\n
133
 * \c createInstance(locale, UNUM_CURRENCY_ISO, errorCode)  to get the currency number format,
134
 * in which the currency is represented by its ISO code, for example "USD3.00".\n
135
 * \c createInstance(locale, UNUM_CURRENCY_PLURAL, errorCode) to get the currency number format,
136
 * in which the currency is represented by its full name in plural format,
137
 * for example, "3.00 US dollars" or "1.00 US dollar".
138
 * <P>
139
 * You can also control the display of numbers with such methods as
140
 * \c getMinimumFractionDigits().  If you want even more control over the
141
 * format or parsing, or want to give your users more control, you can
142
 * try dynamic_casting the \c NumberFormat you get from the factory methods to a
143
 * \c DecimalFormat. This will work for the vast majority of
144
 * countries; just remember to test for nullptr in case you
145
 * encounter an unusual one.
146
 * <P>
147
 * You can also use forms of the parse and format methods with
148
 * \c ParsePosition and \c FieldPosition to allow you to:
149
 * <ul type=round>
150
 *   <li>(a) progressively parse through pieces of a string.
151
 *   <li>(b) align the decimal point and other areas.
152
 * </ul>
153
 * For example, you can align numbers in two ways.
154
 * <P>
155
 * If you are using a monospaced font with spacing for alignment, you
156
 * can pass the \c FieldPosition in your format call, with field =
157
 * \c UNUM_INTEGER_FIELD. On output, \c getEndIndex will be set to the offset
158
 * between the last character of the integer and the decimal. Add
159
 * (desiredSpaceCount - getEndIndex) spaces at the front of the
160
 * string.
161
 * <P>
162
 * If you are using proportional fonts, instead of padding with
163
 * spaces, measure the width of the string in pixels from the start to
164
 * getEndIndex.  Then move the pen by (desiredPixelWidth -
165
 * widthToAlignmentPoint) before drawing the text.  It also works
166
 * where there is no decimal, but possibly additional characters at
167
 * the end, e.g. with parentheses in negative numbers: "(12)" for -12.
168
 * <p>
169
 * <em>User subclasses are not supported.</em> While clients may write
170
 * subclasses, such code will not necessarily work and will not be
171
 * guaranteed to work stably from release to release.
172
 *
173
 * @stable ICU 2.0
174
 */
175
class U_I18N_API NumberFormat : public Format {
176
public:
177
    /**
178
     * Rounding mode.
179
     *
180
     * <p>
181
     * For more detail on rounding modes, see:
182
     * https://unicode-org.github.io/icu/userguide/format_parse/numbers/rounding-modes
183
     *
184
     * @stable ICU 2.4
185
     */
186
    enum ERoundingMode {
187
        kRoundCeiling,  /**< Round towards positive infinity */
188
        kRoundFloor,    /**< Round towards negative infinity */
189
        kRoundDown,     /**< Round towards zero */
190
        kRoundUp,       /**< Round away from zero */
191
        kRoundHalfEven, /**< Round towards the nearest integer, or
192
                             towards the nearest even integer if equidistant */
193
        kRoundHalfDown, /**< Round towards the nearest integer, or
194
                             towards zero if equidistant */
195
        kRoundHalfUp,   /**< Round towards the nearest integer, or
196
                             away from zero if equidistant */
197
        /**
198
          *  Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
199
          *  @stable ICU 4.8
200
          */
201
        kRoundUnnecessary,
202
        /**
203
         * Rounds ties toward the odd number.
204
         * @stable ICU 73
205
         */
206
        kRoundHalfOdd,
207
        /**
208
         * Rounds ties toward +∞.
209
         * @stable ICU 73
210
         */
211
        kRoundHalfCeiling,
212
        /**
213
         * Rounds ties toward -∞.
214
         * @stable ICU 73
215
         */
216
        kRoundHalfFloor,
217
    };
218
219
    /**
220
     * Alignment Field constants used to construct a FieldPosition object.
221
     * Signifies that the position of the integer part or fraction part of
222
     * a formatted number should be returned.
223
     *
224
     * Note: as of ICU 4.4, the values in this enum have been extended to
225
     * support identification of all number format fields, not just those
226
     * pertaining to alignment.
227
     *
228
     * These constants are provided for backwards compatibility only.
229
     * Please use the C style constants defined in the header file unum.h.
230
     *
231
     * @see FieldPosition
232
     * @stable ICU 2.0
233
     */
234
    enum EAlignmentFields {
235
        /** @stable ICU 2.0 */
236
        kIntegerField = UNUM_INTEGER_FIELD,
237
        /** @stable ICU 2.0 */
238
        kFractionField = UNUM_FRACTION_FIELD,
239
        /** @stable ICU 2.0 */
240
        kDecimalSeparatorField = UNUM_DECIMAL_SEPARATOR_FIELD,
241
        /** @stable ICU 2.0 */
242
        kExponentSymbolField = UNUM_EXPONENT_SYMBOL_FIELD,
243
        /** @stable ICU 2.0 */
244
        kExponentSignField = UNUM_EXPONENT_SIGN_FIELD,
245
        /** @stable ICU 2.0 */
246
        kExponentField = UNUM_EXPONENT_FIELD,
247
        /** @stable ICU 2.0 */
248
        kGroupingSeparatorField = UNUM_GROUPING_SEPARATOR_FIELD,
249
        /** @stable ICU 2.0 */
250
        kCurrencyField = UNUM_CURRENCY_FIELD,
251
        /** @stable ICU 2.0 */
252
        kPercentField = UNUM_PERCENT_FIELD,
253
        /** @stable ICU 2.0 */
254
        kPermillField = UNUM_PERMILL_FIELD,
255
        /** @stable ICU 2.0 */
256
        kSignField = UNUM_SIGN_FIELD,
257
        /** @stable ICU 64 */
258
        kMeasureUnitField = UNUM_MEASURE_UNIT_FIELD,
259
        /** @stable ICU 64 */
260
        kCompactField = UNUM_COMPACT_FIELD,
261
262
    /**
263
     * These constants are provided for backwards compatibility only.
264
     * Please use the constants defined in the header file unum.h.
265
     */
266
        /** @stable ICU 2.0 */
267
        INTEGER_FIELD        = UNUM_INTEGER_FIELD,
268
        /** @stable ICU 2.0 */
269
        FRACTION_FIELD       = UNUM_FRACTION_FIELD
270
    };
271
272
    /**
273
     * Destructor.
274
     * @stable ICU 2.0
275
     */
276
    virtual ~NumberFormat();
277
278
    /**
279
     * Clones this object polymorphically.
280
     * The caller owns the result and should delete it when done.
281
     * @return clone, or nullptr if an error occurred
282
     * @stable ICU 2.0
283
     */
284
    virtual NumberFormat* clone() const override = 0;
285
286
    /**
287
     * Return true if the given Format objects are semantically equal.
288
     * Objects of different subclasses are considered unequal.
289
     * @return    true if the given Format objects are semantically equal.
290
     * @stable ICU 2.0
291
     */
292
    virtual bool operator==(const Format& other) const override;
293
294
295
    using Format::format;
296
297
    /**
298
     * Format an object to produce a string.  This method handles
299
     * Formattable objects with numeric types. If the Formattable
300
     * object type is not a numeric type, then it returns a failing
301
     * UErrorCode.
302
     *
303
     * @param obj       The object to format.
304
     * @param appendTo  Output parameter to receive result.
305
     *                  Result is appended to existing contents.
306
     * @param pos       On input: an alignment field, if desired.
307
     *                  On output: the offsets of the alignment field.
308
     * @param status    Output param filled with success/failure status.
309
     * @return          Reference to 'appendTo' parameter.
310
     * @stable ICU 2.0
311
     */
312
    virtual UnicodeString& format(const Formattable& obj,
313
                                  UnicodeString& appendTo,
314
                                  FieldPosition& pos,
315
                                  UErrorCode& status) const override;
316
317
    /**
318
     * Format an object to produce a string.  This method handles
319
     * Formattable objects with numeric types. If the Formattable
320
     * object type is not a numeric type, then it returns a failing
321
     * UErrorCode.
322
     *
323
     * @param obj       The object to format.
324
     * @param appendTo  Output parameter to receive result.
325
     *                  Result is appended to existing contents.
326
     * @param posIter   On return, can be used to iterate over positions
327
     *                  of fields generated by this format call.  Can be
328
     *                  nullptr.
329
     * @param status    Output param filled with success/failure status.
330
     * @return          Reference to 'appendTo' parameter.
331
     * @stable ICU 4.4
332
     */
333
    virtual UnicodeString& format(const Formattable& obj,
334
                                  UnicodeString& appendTo,
335
                                  FieldPositionIterator* posIter,
336
                                  UErrorCode& status) const override;
337
338
    /**
339
     * Parse a string to produce an object.  This methods handles
340
     * parsing of numeric strings into Formattable objects with numeric
341
     * types.
342
     * <P>
343
     * Before calling, set parse_pos.index to the offset you want to
344
     * start parsing at in the source. After calling, parse_pos.index
345
     * indicates the position after the successfully parsed text.  If
346
     * an error occurs, parse_pos.index is unchanged.
347
     * <P>
348
     * When parsing, leading whitespace is discarded (with successful
349
     * parse), while trailing whitespace is left as is.
350
     * <P>
351
     * See Format::parseObject() for more.
352
     *
353
     * @param source    The string to be parsed into an object.
354
     * @param result    Formattable to be set to the parse result.
355
     *                  If parse fails, return contents are undefined.
356
     * @param parse_pos The position to start parsing at. Upon return
357
     *                  this param is set to the position after the
358
     *                  last character successfully parsed. If the
359
     *                  source is not parsed successfully, this param
360
     *                  will remain unchanged.
361
     * @stable ICU 2.0
362
     */
363
    virtual void parseObject(const UnicodeString& source,
364
                             Formattable& result,
365
                             ParsePosition& parse_pos) const override;
366
367
    /**
368
     * Format a double number. These methods call the NumberFormat
369
     * pure virtual format() methods with the default FieldPosition.
370
     *
371
     * @param number    The value to be formatted.
372
     * @param appendTo  Output parameter to receive result.
373
     *                  Result is appended to existing contents.
374
     * @return          Reference to 'appendTo' parameter.
375
     * @stable ICU 2.0
376
     */
377
    UnicodeString& format(  double number,
378
                            UnicodeString& appendTo) const;
379
380
    /**
381
     * Format a long number. These methods call the NumberFormat
382
     * pure virtual format() methods with the default FieldPosition.
383
     *
384
     * @param number    The value to be formatted.
385
     * @param appendTo  Output parameter to receive result.
386
     *                  Result is appended to existing contents.
387
     * @return          Reference to 'appendTo' parameter.
388
     * @stable ICU 2.0
389
     */
390
    UnicodeString& format(  int32_t number,
391
                            UnicodeString& appendTo) const;
392
393
    /**
394
     * Format an int64 number. These methods call the NumberFormat
395
     * pure virtual format() methods with the default FieldPosition.
396
     *
397
     * @param number    The value to be formatted.
398
     * @param appendTo  Output parameter to receive result.
399
     *                  Result is appended to existing contents.
400
     * @return          Reference to 'appendTo' parameter.
401
     * @stable ICU 2.8
402
     */
403
    UnicodeString& format(  int64_t number,
404
                            UnicodeString& appendTo) const;
405
406
    /**
407
     * Format a double number. Concrete subclasses must implement
408
     * these pure virtual methods.
409
     *
410
     * @param number    The value to be formatted.
411
     * @param appendTo  Output parameter to receive result.
412
     *                  Result is appended to existing contents.
413
     * @param pos       On input: an alignment field, if desired.
414
     *                  On output: the offsets of the alignment field.
415
     * @return          Reference to 'appendTo' parameter.
416
     * @stable ICU 2.0
417
     */
418
    virtual UnicodeString& format(double number,
419
                                  UnicodeString& appendTo,
420
                                  FieldPosition& pos) const = 0;
421
    /**
422
     * Format a double number. By default, the parent function simply
423
     * calls the base class and does not return an error status.
424
     * Therefore, the status may be ignored in some subclasses.
425
     *
426
     * @param number    The value to be formatted.
427
     * @param appendTo  Output parameter to receive result.
428
     *                  Result is appended to existing contents.
429
     * @param pos       On input: an alignment field, if desired.
430
     *                  On output: the offsets of the alignment field.
431
     * @param status    error status
432
     * @return          Reference to 'appendTo' parameter.
433
     * @internal
434
     */
435
    virtual UnicodeString& format(double number,
436
                                  UnicodeString& appendTo,
437
                                  FieldPosition& pos,
438
                                  UErrorCode &status) const;
439
    /**
440
     * Format a double number. Subclasses must implement
441
     * this method.
442
     *
443
     * @param number    The value to be formatted.
444
     * @param appendTo  Output parameter to receive result.
445
     *                  Result is appended to existing contents.
446
     * @param posIter   On return, can be used to iterate over positions
447
     *                  of fields generated by this format call.
448
     *                  Can be nullptr.
449
     * @param status    Output param filled with success/failure status.
450
     * @return          Reference to 'appendTo' parameter.
451
     * @stable ICU 4.4
452
     */
453
    virtual UnicodeString& format(double number,
454
                                  UnicodeString& appendTo,
455
                                  FieldPositionIterator* posIter,
456
                                  UErrorCode& status) const;
457
    /**
458
     * Format a long number. Concrete subclasses must implement
459
     * these pure virtual methods.
460
     *
461
     * @param number    The value to be formatted.
462
     * @param appendTo  Output parameter to receive result.
463
     *                  Result is appended to existing contents.
464
     * @param pos       On input: an alignment field, if desired.
465
     *                  On output: the offsets of the alignment field.
466
     * @return          Reference to 'appendTo' parameter.
467
     * @stable ICU 2.0
468
    */
469
    virtual UnicodeString& format(int32_t number,
470
                                  UnicodeString& appendTo,
471
                                  FieldPosition& pos) const = 0;
472
473
    /**
474
     * Format a long number. Concrete subclasses may override
475
     * this function to provide status return.
476
     *
477
     * @param number    The value to be formatted.
478
     * @param appendTo  Output parameter to receive result.
479
     *                  Result is appended to existing contents.
480
     * @param pos       On input: an alignment field, if desired.
481
     *                  On output: the offsets of the alignment field.
482
     * @param status the output status.
483
     * @return          Reference to 'appendTo' parameter.
484
     * @internal
485
    */
486
    virtual UnicodeString& format(int32_t number,
487
                                  UnicodeString& appendTo,
488
                                  FieldPosition& pos,
489
                                  UErrorCode &status) const;
490
491
    /**
492
     * Format an int32 number. Subclasses must implement
493
     * this method.
494
     *
495
     * @param number    The value to be formatted.
496
     * @param appendTo  Output parameter to receive result.
497
     *                  Result is appended to existing contents.
498
     * @param posIter   On return, can be used to iterate over positions
499
     *                  of fields generated by this format call.
500
     *                  Can be nullptr.
501
     * @param status    Output param filled with success/failure status.
502
     * @return          Reference to 'appendTo' parameter.
503
     * @stable ICU 4.4
504
     */
505
    virtual UnicodeString& format(int32_t number,
506
                                  UnicodeString& appendTo,
507
                                  FieldPositionIterator* posIter,
508
                                  UErrorCode& status) const;
509
    /**
510
     * Format an int64 number. (Not abstract to retain compatibility
511
     * with earlier releases, however subclasses should override this
512
     * method as it just delegates to format(int32_t number...);
513
     *
514
     * @param number    The value to be formatted.
515
     * @param appendTo  Output parameter to receive result.
516
     *                  Result is appended to existing contents.
517
     * @param pos       On input: an alignment field, if desired.
518
     *                  On output: the offsets of the alignment field.
519
     * @return          Reference to 'appendTo' parameter.
520
     * @stable ICU 2.8
521
    */
522
    virtual UnicodeString& format(int64_t number,
523
                                  UnicodeString& appendTo,
524
                                  FieldPosition& pos) const;
525
526
    /**
527
     * Format an int64 number. (Not abstract to retain compatibility
528
     * with earlier releases, however subclasses should override this
529
     * method as it just delegates to format(int32_t number...);
530
     *
531
     * @param number    The value to be formatted.
532
     * @param appendTo  Output parameter to receive result.
533
     *                  Result is appended to existing contents.
534
     * @param pos       On input: an alignment field, if desired.
535
     *                  On output: the offsets of the alignment field.
536
     * @param status    Output param filled with success/failure status.
537
     * @return          Reference to 'appendTo' parameter.
538
     * @internal
539
    */
540
    virtual UnicodeString& format(int64_t number,
541
                                  UnicodeString& appendTo,
542
                                  FieldPosition& pos,
543
                                  UErrorCode& status) const;
544
    /**
545
     * Format an int64 number. Subclasses must implement
546
     * this method.
547
     *
548
     * @param number    The value to be formatted.
549
     * @param appendTo  Output parameter to receive result.
550
     *                  Result is appended to existing contents.
551
     * @param posIter   On return, can be used to iterate over positions
552
     *                  of fields generated by this format call.
553
     *                  Can be nullptr.
554
     * @param status    Output param filled with success/failure status.
555
     * @return          Reference to 'appendTo' parameter.
556
     * @stable ICU 4.4
557
     */
558
    virtual UnicodeString& format(int64_t number,
559
                                  UnicodeString& appendTo,
560
                                  FieldPositionIterator* posIter,
561
                                  UErrorCode& status) const;
562
563
    /**
564
     * Format a decimal number. Subclasses must implement
565
     * this method.  The syntax of the unformatted number is a "numeric string"
566
     * as defined in the Decimal Arithmetic Specification, available at
567
     * http://speleotrove.com/decimal
568
     *
569
     * @param number    The unformatted number, as a string, to be formatted.
570
     * @param appendTo  Output parameter to receive result.
571
     *                  Result is appended to existing contents.
572
     * @param posIter   On return, can be used to iterate over positions
573
     *                  of fields generated by this format call.
574
     *                  Can be nullptr.
575
     * @param status    Output param filled with success/failure status.
576
     * @return          Reference to 'appendTo' parameter.
577
     * @stable ICU 4.4
578
     */
579
    virtual UnicodeString& format(StringPiece number,
580
                                  UnicodeString& appendTo,
581
                                  FieldPositionIterator* posIter,
582
                                  UErrorCode& status) const;
583
584
// Can't use #ifndef U_HIDE_INTERNAL_API because these are virtual methods
585
586
    /**
587
     * Format a decimal number.
588
     * The number is a DecimalQuantity wrapper onto a floating point decimal number.
589
     * The default implementation in NumberFormat converts the decimal number
590
     * to a double and formats that.  Subclasses of NumberFormat that want
591
     * to specifically handle big decimal numbers must override this method.
592
     * class DecimalFormat does so.
593
     *
594
     * @param number    The number, a DecimalQuantity format Decimal Floating Point.
595
     * @param appendTo  Output parameter to receive result.
596
     *                  Result is appended to existing contents.
597
     * @param posIter   On return, can be used to iterate over positions
598
     *                  of fields generated by this format call.
599
     * @param status    Output param filled with success/failure status.
600
     * @return          Reference to 'appendTo' parameter.
601
     * @internal
602
     */
603
    virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
604
                                  UnicodeString& appendTo,
605
                                  FieldPositionIterator* posIter,
606
                                  UErrorCode& status) const;
607
608
    /**
609
     * Format a decimal number.
610
     * The number is a DecimalQuantity wrapper onto a floating point decimal number.
611
     * The default implementation in NumberFormat converts the decimal number
612
     * to a double and formats that.  Subclasses of NumberFormat that want
613
     * to specifically handle big decimal numbers must override this method.
614
     * class DecimalFormat does so.
615
     *
616
     * @param number    The number, a DecimalQuantity format Decimal Floating Point.
617
     * @param appendTo  Output parameter to receive result.
618
     *                  Result is appended to existing contents.
619
     * @param pos       On input: an alignment field, if desired.
620
     *                  On output: the offsets of the alignment field.
621
     * @param status    Output param filled with success/failure status.
622
     * @return          Reference to 'appendTo' parameter.
623
     * @internal
624
     */
625
    virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
626
                                  UnicodeString& appendTo,
627
                                  FieldPosition& pos,
628
                                  UErrorCode& status) const;
629
630
   /**
631
    * Return a long if possible (e.g. within range LONG_MAX,
632
    * LONG_MAX], and with no decimals), otherwise a double.  If
633
    * IntegerOnly is set, will stop at a decimal point (or equivalent;
634
    * e.g. for rational numbers "1 2/3", will stop after the 1).
635
    * <P>
636
    * If no object can be parsed, index is unchanged, and nullptr is
637
    * returned.
638
    * <P>
639
    * This is a pure virtual which concrete subclasses must implement.
640
    *
641
    * @param text           The text to be parsed.
642
    * @param result         Formattable to be set to the parse result.
643
    *                       If parse fails, return contents are undefined.
644
    * @param parsePosition  The position to start parsing at on input.
645
    *                       On output, moved to after the last successfully
646
    *                       parse character. On parse failure, does not change.
647
    * @stable ICU 2.0
648
    */
649
    virtual void parse(const UnicodeString& text,
650
                       Formattable& result,
651
                       ParsePosition& parsePosition) const = 0;
652
653
    /**
654
     * Parse a string as a numeric value, and return a Formattable
655
     * numeric object. This method parses integers only if IntegerOnly
656
     * is set.
657
     *
658
     * @param text          The text to be parsed.
659
     * @param result        Formattable to be set to the parse result.
660
     *                      If parse fails, return contents are undefined.
661
     * @param status        Output parameter set to a failure error code
662
     *                      when a failure occurs. The error code when the
663
     *                      string fails to parse is U_INVALID_FORMAT_ERROR,
664
     *                      unless overridden by a subclass.
665
     * @see                 NumberFormat::isParseIntegerOnly
666
     * @stable ICU 2.0
667
     */
668
    virtual void parse(const UnicodeString& text,
669
                       Formattable& result,
670
                       UErrorCode& status) const;
671
672
    /**
673
     * Parses text from the given string as a currency amount.  Unlike
674
     * the parse() method, this method will attempt to parse a generic
675
     * currency name, searching for a match of this object's locale's
676
     * currency display names, or for a 3-letter ISO currency code.
677
     * This method will fail if this format is not a currency format,
678
     * that is, if it does not contain the currency pattern symbol
679
     * (U+00A4) in its prefix or suffix.
680
     *
681
     * @param text the string to parse
682
     * @param pos  input-output position; on input, the position within text
683
     *             to match; must have 0 <= pos.getIndex() < text.length();
684
     *             on output, the position after the last matched character.
685
     *             If the parse fails, the position in unchanged upon output.
686
     * @return     if parse succeeds, a pointer to a newly-created CurrencyAmount
687
     *             object (owned by the caller) containing information about
688
     *             the parsed currency; if parse fails, this is nullptr.
689
     * @stable ICU 49
690
     */
691
    virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
692
                                          ParsePosition& pos) const;
693
694
    /**
695
     * Return true if this format will parse numbers as integers
696
     * only.  For example in the English locale, with ParseIntegerOnly
697
     * true, the string "1234." would be parsed as the integer value
698
     * 1234 and parsing would stop at the "." character.  Of course,
699
     * the exact format accepted by the parse operation is locale
700
     * dependent and determined by sub-classes of NumberFormat.
701
     * @return    true if this format will parse numbers as integers
702
     *            only.
703
     * @stable ICU 2.0
704
     */
705
    UBool isParseIntegerOnly() const;
706
707
    /**
708
     * Sets whether or not numbers should be parsed as integers only.
709
     * @param value    set True, this format will parse numbers as integers
710
     *                 only.
711
     * @see isParseIntegerOnly
712
     * @stable ICU 2.0
713
     */
714
    virtual void setParseIntegerOnly(UBool value);
715
716
    /**
717
     * Sets whether lenient parsing should be enabled (it is off by default).
718
     *
719
     * @param enable \c true if lenient parsing should be used,
720
     *               \c false otherwise.
721
     * @stable ICU 4.8
722
     */
723
    virtual void setLenient(UBool enable);
724
725
    /**
726
     * Returns whether lenient parsing is enabled (it is off by default).
727
     *
728
     * @return \c true if lenient parsing is enabled,
729
     *         \c false otherwise.
730
     * @see #setLenient
731
     * @stable ICU 4.8
732
     */
733
    virtual UBool isLenient() const;
734
735
    /**
736
     * Create a default style NumberFormat for the current default locale.
737
     * The default formatting style is locale dependent.
738
     * <p>
739
     * <strong>NOTE:</strong> New users are strongly encouraged to use
740
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
741
     * @stable ICU 2.0
742
     */
743
    static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
744
745
    /**
746
     * Create a default style NumberFormat for the specified locale.
747
     * The default formatting style is locale dependent.
748
     * @param inLocale    the given locale.
749
     * <p>
750
     * <strong>NOTE:</strong> New users are strongly encouraged to use
751
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
752
     * @stable ICU 2.0
753
     */
754
    static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
755
                                        UErrorCode&);
756
757
    /**
758
     * Create a specific style NumberFormat for the specified locale.
759
     * <p>
760
     * <strong>NOTE:</strong> New users are strongly encouraged to use
761
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
762
     * @param desiredLocale    the given locale.
763
     * @param style            the given style.
764
     * @param errorCode        Output param filled with success/failure status.
765
     * @return                 A new NumberFormat instance.
766
     * @stable ICU 4.8
767
     */
768
    static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale,
769
                                                  UNumberFormatStyle style,
770
                                                  UErrorCode& errorCode);
771
772
#ifndef U_HIDE_INTERNAL_API
773
774
    /**
775
     * ICU use only.
776
     * Creates NumberFormat instance without using the cache.
777
     * @internal
778
     */
779
    static NumberFormat* internalCreateInstance(
780
            const Locale& desiredLocale,
781
            UNumberFormatStyle style,
782
            UErrorCode& errorCode);
783
784
    /**
785
     * ICU use only.
786
     * Returns handle to the shared, cached NumberFormat instance for given
787
     * locale. On success, caller must call removeRef() on returned value
788
     * once it is done with the shared instance.
789
     * @internal
790
     */
791
    static const SharedNumberFormat* U_EXPORT2 createSharedInstance(
792
            const Locale& inLocale, UNumberFormatStyle style, UErrorCode& status);
793
794
#endif  /* U_HIDE_INTERNAL_API */
795
796
    /**
797
     * Returns a currency format for the current default locale.
798
     * <p>
799
     * <strong>NOTE:</strong> New users are strongly encouraged to use
800
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
801
     * @stable ICU 2.0
802
     */
803
    static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
804
805
    /**
806
     * Returns a currency format for the specified locale.
807
     * <p>
808
     * <strong>NOTE:</strong> New users are strongly encouraged to use
809
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
810
     * @param inLocale    the given locale.
811
     * @stable ICU 2.0
812
     */
813
    static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
814
                                                UErrorCode&);
815
816
    /**
817
     * Returns a percentage format for the current default locale.
818
     * <p>
819
     * <strong>NOTE:</strong> New users are strongly encouraged to use
820
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
821
     * @stable ICU 2.0
822
     */
823
    static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
824
825
    /**
826
     * Returns a percentage format for the specified locale.
827
     * <p>
828
     * <strong>NOTE:</strong> New users are strongly encouraged to use
829
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
830
     * @param inLocale    the given locale.
831
     * @stable ICU 2.0
832
     */
833
    static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
834
                                               UErrorCode&);
835
836
    /**
837
     * Returns a scientific format for the current default locale.
838
     * <p>
839
     * <strong>NOTE:</strong> New users are strongly encouraged to use
840
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
841
     * @stable ICU 2.0
842
     */
843
    static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
844
845
    /**
846
     * Returns a scientific format for the specified locale.
847
     * <p>
848
     * <strong>NOTE:</strong> New users are strongly encouraged to use
849
     * {@link icu::number::NumberFormatter} instead of NumberFormat.
850
     * @param inLocale    the given locale.
851
     * @stable ICU 2.0
852
     */
853
    static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
854
                                                UErrorCode&);
855
856
    /**
857
     * Get the set of Locales for which NumberFormats are installed.
858
     * @param count    Output param to receive the size of the locales
859
     * @stable ICU 2.0
860
     */
861
    static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
862
863
#if !UCONFIG_NO_SERVICE
864
    /**
865
     * Register a new NumberFormatFactory.  The factory will be adopted.
866
     * Because ICU may choose to cache NumberFormat objects internally,
867
     * this must be called at application startup, prior to any calls to
868
     * NumberFormat::createInstance to avoid undefined behavior.
869
     * @param toAdopt the NumberFormatFactory instance to be adopted
870
     * @param status the in/out status code, no special meanings are assigned
871
     * @return a registry key that can be used to unregister this factory
872
     * @stable ICU 2.6
873
     */
874
    static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
875
876
    /**
877
     * Unregister a previously-registered NumberFormatFactory using the key returned from the
878
     * register call.  Key becomes invalid after a successful call and should not be used again.
879
     * The NumberFormatFactory corresponding to the key will be deleted.
880
     * Because ICU may choose to cache NumberFormat objects internally,
881
     * this should be called during application shutdown, after all calls to
882
     * NumberFormat::createInstance to avoid undefined behavior.
883
     * @param key the registry key returned by a previous call to registerFactory
884
     * @param status the in/out status code, no special meanings are assigned
885
     * @return true if the factory for the key was successfully unregistered
886
     * @stable ICU 2.6
887
     */
888
    static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
889
890
    /**
891
     * Return a StringEnumeration over the locales available at the time of the call,
892
     * including registered locales.
893
     * @return a StringEnumeration over the locales available at the time of the call
894
     * @stable ICU 2.6
895
     */
896
    static StringEnumeration* U_EXPORT2 getAvailableLocales();
897
#endif /* UCONFIG_NO_SERVICE */
898
899
    /**
900
     * Returns true if grouping is used in this format. For example,
901
     * in the English locale, with grouping on, the number 1234567
902
     * might be formatted as "1,234,567". The grouping separator as
903
     * well as the size of each group is locale dependent and is
904
     * determined by sub-classes of NumberFormat.
905
     * @see setGroupingUsed
906
     * @stable ICU 2.0
907
     */
908
    UBool isGroupingUsed() const;
909
910
    /**
911
     * Set whether or not grouping will be used in this format.
912
     * @param newValue    True, grouping will be used in this format.
913
     * @see getGroupingUsed
914
     * @stable ICU 2.0
915
     */
916
    virtual void setGroupingUsed(UBool newValue);
917
918
    /**
919
     * Returns the maximum number of digits allowed in the integer portion of a
920
     * number.
921
     * @return     the maximum number of digits allowed in the integer portion of a
922
     *             number.
923
     * @see setMaximumIntegerDigits
924
     * @stable ICU 2.0
925
     */
926
    int32_t getMaximumIntegerDigits() const;
927
928
    /**
929
     * Sets the maximum number of digits allowed in the integer portion of a
930
     * number. maximumIntegerDigits must be >= minimumIntegerDigits.  If the
931
     * new value for maximumIntegerDigits is less than the current value
932
     * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
933
     * the new value.
934
     *
935
     * @param newValue    the new value for the maximum number of digits
936
     *                    allowed in the integer portion of a number.
937
     * @see getMaximumIntegerDigits
938
     * @stable ICU 2.0
939
     */
940
    virtual void setMaximumIntegerDigits(int32_t newValue);
941
942
    /**
943
     * Returns the minimum number of digits allowed in the integer portion of a
944
     * number.
945
     * @return    the minimum number of digits allowed in the integer portion of a
946
     *            number.
947
     * @see setMinimumIntegerDigits
948
     * @stable ICU 2.0
949
     */
950
    int32_t getMinimumIntegerDigits() const;
951
952
    /**
953
     * Sets the minimum number of digits allowed in the integer portion of a
954
     * number. minimumIntegerDigits must be &lt;= maximumIntegerDigits.  If the
955
     * new value for minimumIntegerDigits exceeds the current value
956
     * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
957
     * the new value.
958
     * @param newValue    the new value to be set.
959
     * @see getMinimumIntegerDigits
960
     * @stable ICU 2.0
961
     */
962
    virtual void setMinimumIntegerDigits(int32_t newValue);
963
964
    /**
965
     * Returns the maximum number of digits allowed in the fraction portion of a
966
     * number.
967
     * @return    the maximum number of digits allowed in the fraction portion of a
968
     *            number.
969
     * @see setMaximumFractionDigits
970
     * @stable ICU 2.0
971
     */
972
    int32_t getMaximumFractionDigits() const;
973
974
    /**
975
     * Sets the maximum number of digits allowed in the fraction portion of a
976
     * number. maximumFractionDigits must be >= minimumFractionDigits.  If the
977
     * new value for maximumFractionDigits is less than the current value
978
     * of minimumFractionDigits, then minimumFractionDigits will also be set to
979
     * the new value.
980
     * @param newValue    the new value to be set.
981
     * @see getMaximumFractionDigits
982
     * @stable ICU 2.0
983
     */
984
    virtual void setMaximumFractionDigits(int32_t newValue);
985
986
    /**
987
     * Returns the minimum number of digits allowed in the fraction portion of a
988
     * number.
989
     * @return    the minimum number of digits allowed in the fraction portion of a
990
     *            number.
991
     * @see setMinimumFractionDigits
992
     * @stable ICU 2.0
993
     */
994
    int32_t getMinimumFractionDigits() const;
995
996
    /**
997
     * Sets the minimum number of digits allowed in the fraction portion of a
998
     * number. minimumFractionDigits must be &lt;= maximumFractionDigits.   If the
999
     * new value for minimumFractionDigits exceeds the current value
1000
     * of maximumFractionDigits, then maximumIntegerDigits will also be set to
1001
     * the new value
1002
     * @param newValue    the new value to be set.
1003
     * @see getMinimumFractionDigits
1004
     * @stable ICU 2.0
1005
     */
1006
    virtual void setMinimumFractionDigits(int32_t newValue);
1007
1008
    /**
1009
     * Sets the currency used to display currency
1010
     * amounts.  This takes effect immediately, if this format is a
1011
     * currency format.  If this format is not a currency format, then
1012
     * the currency is used if and when this object becomes a
1013
     * currency format.
1014
     * @param theCurrency a 3-letter ISO code indicating new currency
1015
     * to use.  It need not be null-terminated.  May be the empty
1016
     * string or nullptr to indicate no currency.
1017
     * @param ec input-output error code
1018
     * @stable ICU 3.0
1019
     */
1020
    virtual void setCurrency(const char16_t* theCurrency, UErrorCode& ec);
1021
1022
    /**
1023
     * Gets the currency used to display currency
1024
     * amounts.  This may be an empty string for some subclasses.
1025
     * @return a 3-letter null-terminated ISO code indicating
1026
     * the currency in use, or a pointer to the empty string.
1027
     * @stable ICU 2.6
1028
     */
1029
    const char16_t* getCurrency() const;
1030
1031
    /**
1032
     * Set a particular UDisplayContext value in the formatter, such as
1033
     * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1034
     * @param value The UDisplayContext value to set.
1035
     * @param status Input/output status. If at entry this indicates a failure
1036
     *               status, the function will do nothing; otherwise this will be
1037
     *               updated with any new status from the function.
1038
     * @stable ICU 53
1039
     */
1040
    virtual void setContext(UDisplayContext value, UErrorCode& status);
1041
1042
    /**
1043
     * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1044
     * such as UDISPCTX_TYPE_CAPITALIZATION.
1045
     * @param type The UDisplayContextType whose value to return
1046
     * @param status Input/output status. If at entry this indicates a failure
1047
     *               status, the function will do nothing; otherwise this will be
1048
     *               updated with any new status from the function.
1049
     * @return The UDisplayContextValue for the specified type.
1050
     * @stable ICU 53
1051
     */
1052
    virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
1053
1054
    /**
1055
     * Get the rounding mode. This will always return NumberFormat::ERoundingMode::kRoundUnnecessary
1056
     * if the subclass does not support rounding. 
1057
     * @return A rounding mode
1058
     * @stable ICU 60
1059
     */
1060
    virtual ERoundingMode getRoundingMode() const;
1061
1062
    /**
1063
     * Set the rounding mode. If a subclass does not support rounding, this will do nothing.
1064
     * @param roundingMode A rounding mode
1065
     * @stable ICU 60
1066
     */
1067
    virtual void setRoundingMode(ERoundingMode roundingMode);
1068
1069
public:
1070
1071
    /**
1072
     * Return the class ID for this class.  This is useful for
1073
     * comparing to a return value from getDynamicClassID(). Note that,
1074
     * because NumberFormat is an abstract base class, no fully constructed object
1075
     * will have the class ID returned by NumberFormat::getStaticClassID().
1076
     * @return The class ID for all objects of this class.
1077
     * @stable ICU 2.0
1078
     */
1079
    static UClassID U_EXPORT2 getStaticClassID();
1080
1081
    /**
1082
     * Returns a unique class ID POLYMORPHICALLY.  Pure virtual override.
1083
     * This method is to implement a simple version of RTTI, since not all
1084
     * C++ compilers support genuine RTTI.  Polymorphic operator==() and
1085
     * clone() methods call this method.
1086
     * <P>
1087
     * @return The class ID for this object. All objects of a
1088
     * given class have the same class ID.  Objects of
1089
     * other classes have different class IDs.
1090
     * @stable ICU 2.0
1091
     */
1092
    virtual UClassID getDynamicClassID() const override = 0;
1093
1094
protected:
1095
1096
    /**
1097
     * Default constructor for subclass use only.
1098
     * @stable ICU 2.0
1099
     */
1100
    NumberFormat();
1101
1102
    /**
1103
     * Copy constructor.
1104
     * @stable ICU 2.0
1105
     */
1106
    NumberFormat(const NumberFormat&);
1107
1108
    /**
1109
     * Assignment operator.
1110
     * @stable ICU 2.0
1111
     */
1112
    NumberFormat& operator=(const NumberFormat&);
1113
1114
    /**
1115
     * Returns the currency in effect for this formatter.  Subclasses
1116
     * should override this method as needed.  Unlike getCurrency(),
1117
     * this method should never return "".
1118
     * @param result output parameter for null-terminated result, which must
1119
     * have a capacity of at least 4
1120
     * @param ec Output parameter filled with success/failure status.
1121
     * @internal
1122
     */
1123
    virtual void getEffectiveCurrency(char16_t* result, UErrorCode& ec) const;
1124
1125
#ifndef U_HIDE_INTERNAL_API
1126
    /**
1127
     * Creates the specified number format style of the desired locale.
1128
     * If mustBeDecimalFormat is true, then the returned pointer is
1129
     * either a DecimalFormat or it is nullptr.
1130
     * @internal
1131
     */
1132
    static NumberFormat* makeInstance(const Locale& desiredLocale,
1133
                                      UNumberFormatStyle style,
1134
                                      UBool mustBeDecimalFormat,
1135
                                      UErrorCode& errorCode);
1136
#endif  /* U_HIDE_INTERNAL_API */
1137
1138
private:
1139
1140
    static UBool isStyleSupported(UNumberFormatStyle style);
1141
1142
    /**
1143
     * Creates the specified decimal format style of the desired locale.
1144
     * @param desiredLocale    the given locale.
1145
     * @param style            the given style.
1146
     * @param errorCode        Output param filled with success/failure status.
1147
     * @return                 A new NumberFormat instance.
1148
     */
1149
    static NumberFormat* makeInstance(const Locale& desiredLocale,
1150
                                      UNumberFormatStyle style,
1151
                                      UErrorCode& errorCode);
1152
1153
    UBool       fGroupingUsed;
1154
    int32_t     fMaxIntegerDigits;
1155
    int32_t     fMinIntegerDigits;
1156
    int32_t     fMaxFractionDigits;
1157
    int32_t     fMinFractionDigits;
1158
1159
  protected:
1160
    /** \internal */
1161
    static const int32_t gDefaultMaxIntegerDigits;
1162
    /** \internal */
1163
    static const int32_t gDefaultMinIntegerDigits;
1164
1165
  private:
1166
    UBool      fParseIntegerOnly;
1167
    UBool      fLenient; // true => lenient parse is enabled
1168
1169
    // ISO currency code
1170
    char16_t      fCurrency[4];
1171
1172
    UDisplayContext fCapitalizationContext;
1173
1174
    friend class ICUNumberFormatFactory; // access to makeInstance
1175
    friend class ICUNumberFormatService;
1176
    friend class ::NumberFormatTest;  // access to isStyleSupported()
1177
};
1178
1179
#if !UCONFIG_NO_SERVICE
1180
/**
1181
 * A NumberFormatFactory is used to register new number formats.  The factory
1182
 * should be able to create any of the predefined formats for each locale it
1183
 * supports.  When registered, the locales it supports extend or override the
1184
 * locale already supported by ICU.
1185
 *
1186
 * @stable ICU 2.6
1187
 */
1188
class U_I18N_API NumberFormatFactory : public UObject {
1189
public:
1190
1191
    /**
1192
     * Destructor
1193
     * @stable ICU 3.0
1194
     */
1195
    virtual ~NumberFormatFactory();
1196
1197
    /**
1198
     * Return true if this factory will be visible.  Default is true.
1199
     * If not visible, the locales supported by this factory will not
1200
     * be listed by getAvailableLocales.
1201
     * @stable ICU 2.6
1202
     */
1203
    virtual UBool visible() const = 0;
1204
1205
    /**
1206
     * Return the locale names directly supported by this factory.  The number of names
1207
     * is returned in count;
1208
     * @stable ICU 2.6
1209
     */
1210
    virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
1211
1212
    /**
1213
     * Return a number format of the appropriate type.  If the locale
1214
     * is not supported, return null.  If the locale is supported, but
1215
     * the type is not provided by this service, return null.  Otherwise
1216
     * return an appropriate instance of NumberFormat.
1217
     * @stable ICU 2.6
1218
     */
1219
    virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
1220
};
1221
1222
/**
1223
 * A NumberFormatFactory that supports a single locale.  It can be visible or invisible.
1224
 * @stable ICU 2.6
1225
 */
1226
class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
1227
protected:
1228
    /**
1229
     * True if the locale supported by this factory is visible.
1230
     * @stable ICU 2.6
1231
     */
1232
    const UBool _visible;
1233
1234
    /**
1235
     * The locale supported by this factory, as a UnicodeString.
1236
     * @stable ICU 2.6
1237
     */
1238
    UnicodeString _id;
1239
1240
public:
1241
    /**
1242
     * @stable ICU 2.6
1243
     */
1244
    SimpleNumberFormatFactory(const Locale& locale, UBool visible = true);
1245
1246
    /**
1247
     * @stable ICU 3.0
1248
     */
1249
    virtual ~SimpleNumberFormatFactory();
1250
1251
    /**
1252
     * @stable ICU 2.6
1253
     */
1254
    virtual UBool visible() const override;
1255
1256
    /**
1257
     * @stable ICU 2.6
1258
     */
1259
    virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const override;
1260
};
1261
#endif /* #if !UCONFIG_NO_SERVICE */
1262
1263
// -------------------------------------
1264
1265
inline UBool
1266
NumberFormat::isParseIntegerOnly() const
1267
0
{
1268
0
    return fParseIntegerOnly;
1269
0
}
1270
1271
inline UBool
1272
NumberFormat::isLenient() const
1273
0
{
1274
0
    return fLenient;
1275
0
}
1276
1277
U_NAMESPACE_END
1278
1279
#endif /* #if !UCONFIG_NO_FORMATTING */
1280
1281
#endif /* U_SHOW_CPLUSPLUS_API */
1282
1283
#endif // _NUMFMT
1284
//eof