ICU 78.3 78.3
Loading...
Searching...
No Matches
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
32#if U_SHOW_CPLUSPLUS_API
33
34#if !UCONFIG_NO_FORMATTING
35
36#include "unicode/uchar.h"
37#include "unicode/uobject.h"
38#include "unicode/locid.h"
39#include "unicode/numsys.h"
40#include "unicode/unum.h"
41#include "unicode/unistr.h"
42
47
48
49U_NAMESPACE_BEGIN
50
87public:
181
191
209
221
238
244
250
256
265
273 U_I18N_API bool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
274
284 U_I18N_API inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
285
298 U_I18N_API void setSymbol(ENumberFormatSymbol symbol,
299 const UnicodeString& value,
300 const UBool propagateDigits);
301
302#ifndef U_HIDE_INTERNAL_API
310 U_I18N_API void setCurrency(const char16_t* currency, UErrorCode& status);
311#endif // U_HIDE_INTERNAL_API
312
317 U_I18N_API inline Locale getLocale() const;
318
325
343 UBool beforeCurrency,
344 UErrorCode& status) const;
345
357 UBool beforeCurrency,
358 const UnicodeString& pattern);
359
365 U_I18N_API virtual UClassID getDynamicClassID() const override;
366
373
374private:
376
389 void initialize(const Locale& locale, UErrorCode& success,
390 UBool useLastResortData = false, const NumberingSystem* ns = nullptr);
391
395 void initialize();
396
397public:
398
399#ifndef U_HIDE_INTERNAL_API
404 return fIsCustomCurrencySymbol;
405 }
406
411 return fIsCustomIntlCurrencySymbol;
412 }
413
418 return fCodePointZero;
419 }
420#endif /* U_HIDE_INTERNAL_API */
421
437 U_I18N_API inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
438
439#ifndef U_HIDE_INTERNAL_API
455 U_I18N_API inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
456
461 U_I18N_API inline const char16_t* getCurrencyPattern() const;
462
467 U_I18N_API inline const char* getNumberingSystemName() const;
468#endif /* U_HIDE_INTERNAL_API */
469
470private:
485 UnicodeString fSymbols[kFormatSymbolCount];
486
490 UnicodeString fNoSymbol;
491
506 UChar32 fCodePointZero;
507
508 Locale locale;
509
510 Locale actualLocale;
511 Locale validLocale;
512 const char16_t* currPattern = nullptr;
513
514 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
515 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
516 UBool fIsCustomCurrencySymbol;
517 UBool fIsCustomIntlCurrencySymbol;
518 char nsName[kInternalNumSysNameCapacity+1] = {};
519};
520
521// -------------------------------------
522
523inline UnicodeString
525 const UnicodeString *strPtr;
526 if(symbol < kFormatSymbolCount) {
527 strPtr = &fSymbols[symbol];
528 } else {
529 strPtr = &fNoSymbol;
530 }
531 return *strPtr;
532}
533
534// See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
535inline const UnicodeString &
537 const UnicodeString *strPtr;
538 if(symbol < kFormatSymbolCount) {
539 strPtr = &fSymbols[symbol];
540 } else {
541 strPtr = &fNoSymbol;
542 }
543 return *strPtr;
544}
545
546#ifndef U_HIDE_INTERNAL_API
548 if (digit < 0 || digit > 9) {
549 digit = 0;
550 }
551 if (digit == 0) {
552 return fSymbols[kZeroDigitSymbol];
553 }
554 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
555 return fSymbols[key];
556}
557#endif /* U_HIDE_INTERNAL_API */
558
559// -------------------------------------
560
561inline void
562DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = true) {
563 if (symbol == kCurrencySymbol) {
564 fIsCustomCurrencySymbol = true;
565 }
566 else if (symbol == kIntlCurrencySymbol) {
567 fIsCustomIntlCurrencySymbol = true;
568 }
569 if(symbol<kFormatSymbolCount) {
570 fSymbols[symbol]=value;
571 }
572
573 // If the zero digit is being set to a known zero digit according to Unicode,
574 // then we automatically set the corresponding 1-9 digits
575 // Also record updates to fCodePointZero. Be conservative if in doubt.
576 if (symbol == kZeroDigitSymbol) {
577 UChar32 sym = value.char32At(0);
578 if ( propagateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
579 fCodePointZero = sym;
580 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
581 sym++;
582 fSymbols[static_cast<int>(kOneDigitSymbol) + i - 1] = UnicodeString(sym);
583 }
584 } else {
585 fCodePointZero = -1;
586 }
587 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
588 fCodePointZero = -1;
589 }
590}
591
592// -------------------------------------
593
594inline Locale
596 return locale;
597}
598
599#ifndef U_HIDE_INTERNAL_API
600inline const char16_t*
602 return currPattern;
603}
604inline const char*
606 return nsName;
607}
608#endif /* U_HIDE_INTERNAL_API */
609
610U_NAMESPACE_END
611
612#endif /* #if !UCONFIG_NO_FORMATTING */
613
614#endif /* U_SHOW_CPLUSPLUS_API */
615
616#endif // _DCFMTSYM
617//eof
U_I18N_API bool operator==(const DecimalFormatSymbols &other) const
Return true if another object is semantically equal to this one.
U_I18N_API DecimalFormatSymbols(UErrorCode &status)
Create a DecimalFormatSymbols object for the default locale.
virtual U_I18N_API ~DecimalFormatSymbols()
Destructor.
U_I18N_API UBool isCustomIntlCurrencySymbol() const
Definition dcfmtsym.h:410
U_I18N_API DecimalFormatSymbols & operator=(const DecimalFormatSymbols &)
Assignment operator.
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition dcfmtsym.h:92
@ kDecimalSeparatorSymbol
The decimal separator.
Definition dcfmtsym.h:94
@ kPlusSignSymbol
The plus sign.
Definition dcfmtsym.h:108
@ kMinusSignSymbol
The minus sign.
Definition dcfmtsym.h:106
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition dcfmtsym.h:171
@ kFormatSymbolCount
count symbol constants
Definition dcfmtsym.h:179
@ kInfinitySymbol
Infinity symbol.
Definition dcfmtsym.h:122
@ kExponentialSymbol
The exponential symbol.
Definition dcfmtsym.h:116
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition dcfmtsym.h:118
@ kPatternSeparatorSymbol
The pattern separator.
Definition dcfmtsym.h:98
@ kCurrencySymbol
The currency symbol.
Definition dcfmtsym.h:110
@ kSignificantDigitSymbol
Significant digit symbol.
Definition dcfmtsym.h:127
@ kIntlCurrencySymbol
The international currency symbol.
Definition dcfmtsym.h:112
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition dcfmtsym.h:131
@ kPadEscapeSymbol
Escape padding character.
Definition dcfmtsym.h:120
@ kPercentSymbol
The percent sign.
Definition dcfmtsym.h:100
@ kNaNSymbol
Nan symbol.
Definition dcfmtsym.h:124
@ kApproximatelySignSymbol
Approximately sign.
Definition dcfmtsym.h:176
@ kDigitSymbol
Character representing a digit in the pattern.
Definition dcfmtsym.h:104
@ kMonetarySeparatorSymbol
The monetary separator.
Definition dcfmtsym.h:114
@ kGroupingSeparatorSymbol
The grouping separator.
Definition dcfmtsym.h:96
U_I18N_API const char * getNumberingSystemName() const
Returns the numbering system with which this DecimalFormatSymbols was initialized.
Definition dcfmtsym.h:605
U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
U_I18N_API const char16_t * getCurrencyPattern() const
Returns that pattern stored in currency info.
Definition dcfmtsym.h:601
U_I18N_API const UnicodeString & getConstSymbol(ENumberFormatSymbol symbol) const
Internal function - more efficient version of getSymbol, returning a const reference to one of the sy...
Definition dcfmtsym.h:536
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
U_I18N_API DecimalFormatSymbols(const DecimalFormatSymbols &)
Copy constructor.
U_I18N_API void setPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, const UnicodeString &pattern)
Set pattern string for 'CurrencySpacing' that can be applied to currency format.
U_I18N_API DecimalFormatSymbols(const Locale &locale, UErrorCode &status)
Create a DecimalFormatSymbols object for the given locale.
U_I18N_API UBool isCustomCurrencySymbol() const
Definition dcfmtsym.h:403
U_I18N_API UnicodeString getSymbol(ENumberFormatSymbol symbol) const
Get one of the format symbols by its enum constant.
Definition dcfmtsym.h:524
U_I18N_API const UnicodeString & getConstDigitSymbol(int32_t digit) const
Returns the const UnicodeString reference, like getConstSymbol, corresponding to the digit with the g...
Definition dcfmtsym.h:547
U_I18N_API void setCurrency(const char16_t *currency, UErrorCode &status)
Loads symbols for the specified currency into this instance.
U_I18N_API Locale getLocale() const
Returns the locale for which this object was constructed.
Definition dcfmtsym.h:595
U_I18N_API UChar32 getCodePointZero() const
Definition dcfmtsym.h:417
U_I18N_API const UnicodeString & getPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, UErrorCode &status) const
Get pattern string for 'CurrencySpacing' that can be applied to currency format.
U_I18N_API DecimalFormatSymbols(const Locale &locale, const NumberingSystem &ns, UErrorCode &status)
Creates a DecimalFormatSymbols instance for the given locale with digits and symbols corresponding to...
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
U_I18N_API void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits)
Set one of the format symbols by its enum constant.
Definition dcfmtsym.h:562
U_I18N_API bool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition dcfmtsym.h:273
static U_I18N_API DecimalFormatSymbols * createWithLastResortData(UErrorCode &status)
Creates a DecimalFormatSymbols object with last-resort data.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
Defines numbering systems.
Definition numsys.h:60
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
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_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
constexpr const size_t kInternalNumSysNameCapacity
Size of a numbering system name.
Definition numsys.h:42
C++ API: NumberingSystem object.
C API: Unicode Properties.
U_CAPI int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
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:449
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
C++ API: Unicode String.
C API: Compatibility APIs for number formatting.
UCurrencySpacing
Constants for specifying currency spacing.
Definition unum.h:301
@ UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition unum.h:316
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316