ICU 62.1 62.1
dcfmtsym.h
Go to the documentation of this file.
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
6* Corporation and others. All Rights Reserved.
7********************************************************************************
8*
9* File DCFMTSYM.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* 03/27/97 helena Updated to pass the simple test after code review.
17* 08/26/97 aliu Added currency/intl currency symbol support.
18* 07/22/98 stephen Changed to match C++ style
19* currencySymbol -> fCurrencySymbol
20* Constants changed from CAPS to kCaps
21* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
22* 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
23* functions.
24********************************************************************************
25*/
26
27#ifndef DCFMTSYM_H
28#define DCFMTSYM_H
29
30#include "unicode/utypes.h"
31#include "unicode/uchar.h"
32
33#if !UCONFIG_NO_FORMATTING
34
35#include "unicode/uobject.h"
36#include "unicode/locid.h"
37#include "unicode/numsys.h"
38#include "unicode/unum.h"
39#include "unicode/unistr.h"
40
48
85public:
173
183
184#ifndef U_HIDE_DRAFT_API
202#endif /* U_HIDE_DRAFT_API */
203
215
232
238
244
250
259
268
278 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
279
292 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
293
298 inline Locale getLocale() const;
299
306
325 UErrorCode& status) const;
338 const UnicodeString& pattern);
339
346
353
354private:
356
369 void initialize(const Locale& locale, UErrorCode& success,
370 UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
371
375 void initialize();
376
377 void setCurrencyForSymbols();
378
379public:
380
381#ifndef U_HIDE_INTERNAL_API
386 return fIsCustomCurrencySymbol;
387 }
388
393 return fIsCustomIntlCurrencySymbol;
394 }
395
399 inline UChar32 getCodePointZero() const {
400 return fCodePointZero;
401 }
402#endif /* U_HIDE_INTERNAL_API */
403
419 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
420
421#ifndef U_HIDE_INTERNAL_API
437 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
438
443 inline const char16_t* getCurrencyPattern(void) const;
444#endif /* U_HIDE_INTERNAL_API */
445
446private:
462 UnicodeString fSymbols[kFormatSymbolCount];
463
468 UnicodeString fNoSymbol;
469
484 UChar32 fCodePointZero;
485
486 Locale locale;
487
488 char actualLocale[ULOC_FULLNAME_CAPACITY];
489 char validLocale[ULOC_FULLNAME_CAPACITY];
490 const char16_t* currPattern;
491
492 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
493 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
494 UBool fIsCustomCurrencySymbol;
495 UBool fIsCustomIntlCurrencySymbol;
496};
497
498// -------------------------------------
499
500inline UnicodeString
501DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
502 const UnicodeString *strPtr;
503 if(symbol < kFormatSymbolCount) {
504 strPtr = &fSymbols[symbol];
505 } else {
506 strPtr = &fNoSymbol;
507 }
508 return *strPtr;
509}
510
511// See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
512inline const UnicodeString &
513DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
514 const UnicodeString *strPtr;
515 if(symbol < kFormatSymbolCount) {
516 strPtr = &fSymbols[symbol];
517 } else {
518 strPtr = &fNoSymbol;
519 }
520 return *strPtr;
521}
522
523#ifndef U_HIDE_INTERNAL_API
524inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
525 if (digit < 0 || digit > 9) {
526 digit = 0;
527 }
528 if (digit == 0) {
529 return fSymbols[kZeroDigitSymbol];
530 }
531 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
532 return fSymbols[key];
533}
534#endif
535
536// -------------------------------------
537
538inline void
539DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
540 if (symbol == kCurrencySymbol) {
541 fIsCustomCurrencySymbol = TRUE;
542 }
543 else if (symbol == kIntlCurrencySymbol) {
544 fIsCustomIntlCurrencySymbol = TRUE;
545 }
546 if(symbol<kFormatSymbolCount) {
547 fSymbols[symbol]=value;
548 }
549
550 // If the zero digit is being set to a known zero digit according to Unicode,
551 // then we automatically set the corresponding 1-9 digits
552 // Also record updates to fCodePointZero. Be conservative if in doubt.
553 if (symbol == kZeroDigitSymbol) {
554 UChar32 sym = value.char32At(0);
555 if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
556 fCodePointZero = sym;
557 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
558 sym++;
559 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
560 }
561 } else {
562 fCodePointZero = -1;
563 }
564 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
565 fCodePointZero = -1;
566 }
567}
568
569// -------------------------------------
570
571inline Locale
572DecimalFormatSymbols::getLocale() const {
573 return locale;
574}
575
576#ifndef U_HIDE_INTERNAL_API
577inline const char16_t*
578DecimalFormatSymbols::getCurrencyPattern() const {
579 return currPattern;
580}
581#endif /* U_HIDE_INTERNAL_API */
582
584
585#endif /* #if !UCONFIG_NO_FORMATTING */
586
587#endif // _DCFMTSYM
588//eof
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition dcfmtsym.h:84
void setPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, const UnicodeString &pattern)
Set pattern string for 'CurrencySpacing' that can be applied to currency format.
UBool isCustomCurrencySymbol() const
Definition dcfmtsym.h:385
virtual ~DecimalFormatSymbols()
Destructor.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition dcfmtsym.h:90
@ kDecimalSeparatorSymbol
The decimal separator.
Definition dcfmtsym.h:92
@ kPlusSignSymbol
The plus sign.
Definition dcfmtsym.h:106
@ kMinusSignSymbol
The minus sign.
Definition dcfmtsym.h:104
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition dcfmtsym.h:169
@ kInfinitySymbol
Infinity symbol.
Definition dcfmtsym.h:120
@ kExponentialSymbol
The exponential symbol.
Definition dcfmtsym.h:114
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition dcfmtsym.h:116
@ kPatternSeparatorSymbol
The pattern separator.
Definition dcfmtsym.h:96
@ kCurrencySymbol
The currency symbol.
Definition dcfmtsym.h:108
@ kSignificantDigitSymbol
Significant digit symbol.
Definition dcfmtsym.h:125
@ kIntlCurrencySymbol
The international currency symbol.
Definition dcfmtsym.h:110
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition dcfmtsym.h:129
@ kPadEscapeSymbol
Escape padding character.
Definition dcfmtsym.h:118
@ kPercentSymbol
The percent sign.
Definition dcfmtsym.h:98
@ kNaNSymbol
Nan symbol.
Definition dcfmtsym.h:122
@ kDigitSymbol
Character representing a digit in the pattern.
Definition dcfmtsym.h:102
@ kMonetarySeparatorSymbol
The monetary separator.
Definition dcfmtsym.h:112
@ kGroupingSeparatorSymbol
The grouping separator.
Definition dcfmtsym.h:94
UBool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition dcfmtsym.h:267
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
DecimalFormatSymbols(UErrorCode &status)
Create a DecimalFormatSymbols object for the default locale.
const UnicodeString & getPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, UErrorCode &status) const
Get pattern string for 'CurrencySpacing' that can be applied to currency format.
DecimalFormatSymbols(const Locale &locale, UErrorCode &status)
Create a DecimalFormatSymbols object for the given locale.
DecimalFormatSymbols(const DecimalFormatSymbols &)
Copy constructor.
UChar32 getCodePointZero() const
Definition dcfmtsym.h:399
UBool operator==(const DecimalFormatSymbols &other) const
Return true if another object is semantically equal to this one.
DecimalFormatSymbols & operator=(const DecimalFormatSymbols &)
Assignment operator.
static DecimalFormatSymbols * createWithLastResortData(UErrorCode &status)
Creates a DecimalFormatSymbols object with last-resort data.
DecimalFormatSymbols(const Locale &locale, const NumberingSystem &ns, UErrorCode &status)
Creates a DecimalFormatSymbols instance for the given locale with digits and symbols corresponding to...
UBool isCustomIntlCurrencySymbol() const
Definition dcfmtsym.h:392
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
Defines numbering systems.
Definition numsys.h:60
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length char16_t code units of the string.
C++ API: Locale ID object.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: NumberingSystem object.
C API: Unicode Properties.
int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition uloc.h:264
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition uloc.h:338
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:400
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
#define TRUE
The TRUE value of a UBool.
Definition umachine.h:240
#define FALSE
The FALSE value of a UBool.
Definition umachine.h:244
C++ API: Unicode String.
C API: Compatibility APIs for number formatting.
UCurrencySpacing
Constants for specifying currency spacing.
Definition unum.h:331
@ UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition unum.h:345
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137