home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / include / dcfmtsym.h < prev    next >
C/C++ Source or Header  |  1999-11-12  |  15KB  |  544 lines

  1. /*
  2. ********************************************************************************
  3. *                                                                              *
  4. * COPYRIGHT:                                                                   *
  5. *   (C) Copyright Taligent, Inc.,  1997                                        *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999      *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  10. *                                                                              *
  11. ********************************************************************************
  12. *
  13. * File DCFMTSYM.H
  14. *
  15. * Modification History:
  16. *
  17. *   Date        Name        Description
  18. *   02/19/97    aliu        Converted from java.
  19. *   03/18/97    clhuang     Updated per C++ implementation.
  20. *   03/27/97    helena      Updated to pass the simple test after code review.
  21. *   08/26/97    aliu        Added currency/intl currency symbol support.
  22. *    07/22/98    stephen        Changed to match C++ style 
  23. *                            currencySymbol -> fCurrencySymbol
  24. *                            Constants changed from CAPS to kCaps
  25. *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
  26. ********************************************************************************
  27. */
  28.  
  29. #ifndef DCFMTSYM_H
  30. #define DCFMTSYM_H
  31.  
  32. #include "utypes.h"
  33. #include "locid.h"
  34.  
  35. /**
  36.  * This class represents the set of symbols needed by DecimalFormat
  37.  * to format numbers. DecimalFormat creates for itself an instance of
  38.  * DecimalFormatSymbols from its locale data.  If you need to change any
  39.  * of these symbols, you can get the DecimalFormatSymbols object from
  40.  * your DecimalFormat and modify it.
  41.  * <P>
  42.  * Here are the special characters used in the parts of the
  43.  * subpattern, with notes on their usage.
  44.  * <pre>
  45.  * .       Symbol   Meaning
  46.  * .         0      a digit
  47.  * .         #      a digit, zero shows as absent
  48.  * .         .      placeholder for decimal separator
  49.  * .         ,      placeholder for grouping separator.
  50.  * .         ;      separates formats.
  51.  * .         -      default negative prefix.
  52.  * .         %      divide by 100 and show as percentage
  53.  * .         X      any other characters can be used in the prefix or suffix
  54.  * .         '      used to quote special characters in a prefix or suffix.
  55.  *  </pre>
  56.  * [Notes] 
  57.  * <P>
  58.  * If there is no explicit negative subpattern, - is prefixed to the
  59.  * positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
  60.  * <P>
  61.  * The grouping separator is commonly used for thousands, but in some
  62.  * countries for ten-thousands. The interval is a constant number of
  63.  * digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
  64.  * If you supply a pattern with multiple grouping characters, the interval
  65.  * between the last one and the end of the integer is the one that is
  66.  * used. So "#,##,###,####" == "######,####" == "##,####,####".
  67.  * <P>
  68.  * This class only handles localized digits where the 10 digits are
  69.  * contiguous in Unicode, from 0 to 9. Other digits sets (such as
  70.  * superscripts) would need a different subclass.
  71.  */
  72.        
  73. class U_I18N_API DecimalFormatSymbols {
  74. public:
  75.     /**
  76.      * Create a DecimalFormatSymbols object for the given locale.
  77.      *
  78.      * @param locale    The locale to get symbols for.
  79.      * @param status    Input/output parameter, set to success or
  80.      *                  failure code upon return.
  81.      */
  82.     DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
  83.  
  84.     /**
  85.      * Create a DecimalFormatSymbols object for the default locale.
  86.      * This constructor will not fail.  If the resource file data is
  87.      * not available, it will use hard-coded last-resort data and
  88.      * set status to U_USING_FALLBACK_ERROR.
  89.      *
  90.      * @param status    Input/output parameter, set to success or
  91.      *                  failure code upon return.
  92.      */
  93.     DecimalFormatSymbols( UErrorCode& status);
  94.  
  95.     /**
  96.      * Copy constructor.
  97.      */
  98.     DecimalFormatSymbols(const DecimalFormatSymbols&);
  99.  
  100.     /**
  101.      * Assignment operator.
  102.      */
  103.     DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
  104.  
  105.     /**
  106.      * Destructor.
  107.      */
  108.     ~DecimalFormatSymbols();
  109.  
  110.     /**
  111.      * Return true if another object is semantically equal to this one.
  112.      */
  113.     bool_t operator==(const DecimalFormatSymbols& other) const;
  114.  
  115.     /**
  116.      * Return true if another object is semantically unequal to this one.
  117.      */
  118.     bool_t operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
  119.  
  120.     /**
  121.      * character used for zero. Different for Arabic, etc.
  122.      */
  123.     UChar getZeroDigit(void) const;
  124.     void setZeroDigit(UChar zeroDigit);
  125.  
  126.     /**
  127.      * character used for thousands separator. Different for French, etc.
  128.      */
  129.     UChar getGroupingSeparator(void) const;
  130.     void setGroupingSeparator(UChar groupingSeparator);
  131.  
  132.     /**
  133.      * character used for decimal sign. Different for French, etc.
  134.      */
  135.     UChar getDecimalSeparator(void) const;
  136.     void setDecimalSeparator(UChar decimalSeparator);
  137.  
  138.     /**
  139.      * character used for per mill sign. Different for Arabic, etc.
  140.      */
  141.     UChar getPerMill(void) const;
  142.     void setPerMill(UChar perMill);
  143.  
  144.     /**
  145.      * character used for percent sign. Different for Arabic, etc.
  146.      */
  147.     UChar getPercent(void) const;
  148.     void setPercent(UChar percent);
  149.  
  150.     /**
  151.      * character used for a digit in a pattern.
  152.      */
  153.     UChar getDigit(void) const;
  154.     void setDigit(UChar digit);
  155.  
  156.     /**
  157.      * character used to separate positive and negative subpatterns
  158.      * in a pattern.
  159.      */
  160.     UChar getPatternSeparator(void) const;
  161.     void setPatternSeparator(UChar patternSeparator);
  162.  
  163.     /**
  164.      * character used to represent infinity. Almost always left
  165.      * unchanged.
  166.      */
  167.     UnicodeString& getInfinity(UnicodeString& result) const;
  168.     void setInfinity(const UnicodeString& infinity);
  169.  
  170.     /**
  171.      * character used to represent NaN. Almost always left
  172.      * unchanged.
  173.      */
  174.     UnicodeString& getNaN(UnicodeString& result) const;
  175.     void setNaN(const UnicodeString& NaN);
  176.  
  177.     /**
  178.      * character used to represent plus sign
  179.      */
  180.     UChar getPlusSign(void) const;
  181.     void setPlusSign(UChar minusSign);
  182.  
  183.     /**
  184.      * character used to represent minus sign. If no explicit
  185.      * negative format is specified, one is formed by prefixing
  186.      * minusSign to the positive format.
  187.      */
  188.     UChar getMinusSign(void) const;
  189.     void setMinusSign(UChar minusSign);
  190.  
  191.     /**
  192.      * character used to represent exponential. Almost always left
  193.      * unchanged.
  194.      */
  195.     UChar getExponentialSymbol(void) const;
  196.     void setExponentialSymbol(UChar exponential);
  197.  
  198.     /**
  199.      * Return the string denoting the local currency.
  200.      */
  201.     UnicodeString& getCurrencySymbol(UnicodeString& result) const;
  202.     void setCurrencySymbol(const UnicodeString& currency);
  203.  
  204.     /**
  205.      * Return the international string denoting the local currency.
  206.      */
  207.     UnicodeString& getInternationalCurrencySymbol(UnicodeString& result) const;
  208.     void setInternationalCurrencySymbol(const UnicodeString& currency);
  209.  
  210.     /**
  211.      * Return the monetary decimal separator.
  212.      */
  213.     UChar getMonetaryDecimalSeparator(void) const;
  214.     void setMonetaryDecimalSeparator(UChar sep);
  215.  
  216.     /**
  217.      * Return the character used to pad numbers out to a specified width.  This
  218.      * is not the pad character itself; rather, it is the special pattern
  219.      * character <em>preceding</em> the pad character.  In the pattern
  220.      * "*_#,##0", '*' is the pad escape, and '_' is the pad character.
  221.      * @return the character 
  222.      * @see #setPadEscape
  223.      * @see DecimalFormat#getFormatWidth
  224.      * @see DecimalFormat#getPadPosition
  225.      * @see DecimalFormat#getPadCharacter
  226.      */
  227.     UChar getPadEscape(void) const;
  228.  
  229.     /**
  230.      * Set the character used to pad numbers out to a specified width.  This is
  231.      * not the pad character itself; rather, it is the special pattern character
  232.      * <em>preceding</em> the pad character.  In the pattern "*_#,##0", '*' is
  233.      * the pad escape, and '_' is the pad character.
  234.      * @see #getPadEscape
  235.      * @see DecimalFormat#setFormatWidth
  236.      * @see DecimalFormat#setPadPosition
  237.      * @see DecimalFormat#setPadCharacter
  238.      */
  239.     void setPadEscape(UChar c);
  240.  
  241. private:
  242.     /**
  243.      * Initializes the symbols from the LocaleElements resource bundle.
  244.      * Note: The organization of LocaleElements badly needs to be
  245.      * cleaned up.
  246.      */
  247.     void initialize(const Locale& locale, UErrorCode& success, bool_t useLastResortData = FALSE);
  248.  
  249.     /**
  250.      * Initialize the symbols from the given array of UnicodeStrings.
  251.      * The array must be of the correct size.
  252.      */
  253.     void initialize(const UnicodeString* numberElements, const UnicodeString* currencyElements);
  254.     
  255.     /**
  256.      * The resource tags we use to retrieve decimal format data from
  257.      * locale resource bundles.
  258.      */
  259.     static const UnicodeString     fgNumberElements;
  260.     static const UnicodeString     fgCurrencyElements;
  261.     static const int32_t         fgNumberElementsLength;
  262.     static const int32_t         fgCurrencyElementsLength;
  263.     static const UnicodeString     fgLastResortNumberElements[];
  264.     static const UnicodeString     fgLastResortCurrencyElements[];
  265.     static const UChar         fgLastResortPerMill[];
  266.     static const UChar         fgLastResortInfinity[];
  267.     static const UChar         fgLastResortNaN[];
  268.     static const UChar         fgLastResortCurrency[];
  269.     static const UChar         fgLastResortIntlCurrency[];
  270.  
  271.     UChar         fDecimalSeparator;
  272.     UChar         fGroupingSeparator;
  273.     UChar         fPatternSeparator;
  274.     UChar         fPercent;
  275.     UChar         fZeroDigit;
  276.     UChar         fDigit;
  277.     UChar         fPlusSign;
  278.     UChar         fMinusSign;
  279.     UnicodeString   fCurrencySymbol;
  280.     UnicodeString   fIntlCurrencySymbol;
  281.     UChar         fMonetarySeparator;
  282.     UChar         fExponential;
  283.     UChar         fPadEscape;
  284.  
  285.     UChar         fPerMill;
  286.     UnicodeString   fInfinity;
  287.     UnicodeString   fNaN;
  288. };
  289.  
  290. // -------------------------------------
  291.  
  292. inline UChar
  293. DecimalFormatSymbols::getZeroDigit() const
  294. {
  295.     return fZeroDigit;
  296. }
  297.  
  298. // -------------------------------------
  299.  
  300. inline void
  301. DecimalFormatSymbols::setZeroDigit(UChar zeroDigit)
  302. {
  303.     fZeroDigit = zeroDigit;
  304. }
  305.  
  306. // -------------------------------------
  307.  
  308. inline UChar
  309. DecimalFormatSymbols::getGroupingSeparator() const
  310. {
  311.     return fGroupingSeparator;
  312. }
  313.  
  314. // -------------------------------------
  315.  
  316. inline void
  317. DecimalFormatSymbols::setGroupingSeparator(UChar groupingSeparator)
  318. {
  319.     fGroupingSeparator = groupingSeparator;
  320. }
  321.  
  322. // -------------------------------------
  323.  
  324. inline UChar
  325. DecimalFormatSymbols::getDecimalSeparator() const
  326. {
  327.     return fDecimalSeparator;
  328. }
  329.  
  330. // -------------------------------------
  331.  
  332. inline void
  333. DecimalFormatSymbols::setDecimalSeparator(UChar decimalSeparator)
  334. {
  335.     fDecimalSeparator = decimalSeparator;
  336. }
  337.  
  338. // -------------------------------------
  339.  
  340. inline UChar
  341. DecimalFormatSymbols::getPerMill() const
  342. {
  343.     return fPerMill;
  344. }
  345.  
  346. // -------------------------------------
  347.  
  348. inline void
  349. DecimalFormatSymbols::setPerMill(UChar perMill)
  350. {
  351.     fPerMill = perMill;
  352. }
  353.  
  354. // -------------------------------------
  355.  
  356. inline UChar
  357. DecimalFormatSymbols::getPercent() const
  358. {
  359.     return fPercent;
  360. }
  361.  
  362. // -------------------------------------
  363.  
  364. inline void
  365. DecimalFormatSymbols::setPercent(UChar percent)
  366. {
  367.     fPercent = percent;
  368. }
  369.  
  370. // -------------------------------------
  371.  
  372. inline UChar
  373. DecimalFormatSymbols::getDigit() const
  374. {
  375.     return fDigit;
  376. }
  377.  
  378. // -------------------------------------
  379.  
  380. inline void
  381. DecimalFormatSymbols::setDigit(UChar digit)
  382. {
  383.     fDigit = digit;
  384. }
  385.  
  386. // -------------------------------------
  387.  
  388. inline UChar
  389. DecimalFormatSymbols::getPatternSeparator() const
  390. {
  391.     return fPatternSeparator;
  392. }
  393.  
  394. // -------------------------------------
  395.  
  396. inline void
  397. DecimalFormatSymbols::setPatternSeparator(UChar patternSeparator)
  398. {
  399.     fPatternSeparator = patternSeparator;
  400. }
  401.  
  402. // -------------------------------------
  403.  
  404. inline UnicodeString&
  405. DecimalFormatSymbols::getInfinity(UnicodeString& result) const
  406. {
  407.     result = fInfinity;
  408.     return result;
  409. }
  410.  
  411. // -------------------------------------
  412.  
  413. inline void
  414. DecimalFormatSymbols::setInfinity(const UnicodeString& infinity)
  415. {
  416.     fInfinity = infinity;
  417. }
  418.  
  419. // -------------------------------------
  420.  
  421. inline UnicodeString&
  422. DecimalFormatSymbols::getNaN(UnicodeString& result) const
  423. {
  424.     result = fNaN;
  425.     return result;
  426. }
  427.  
  428. // -------------------------------------
  429.  
  430. inline void
  431. DecimalFormatSymbols::setNaN(const UnicodeString& NaN)
  432. {
  433.     fNaN = NaN;
  434. }
  435.  
  436. // -------------------------------------
  437.  
  438. inline UChar
  439. DecimalFormatSymbols::getPlusSign() const
  440. {
  441.     return fPlusSign;
  442. }
  443.  
  444. // -------------------------------------
  445.  
  446. inline void
  447. DecimalFormatSymbols::setPlusSign(UChar plusSign)
  448. {
  449.     fPlusSign = plusSign;
  450. }
  451.  
  452. // -------------------------------------
  453.  
  454. inline UChar
  455. DecimalFormatSymbols::getMinusSign() const
  456. {
  457.     return fMinusSign;
  458. }
  459.  
  460. // -------------------------------------
  461.  
  462. inline void
  463. DecimalFormatSymbols::setMinusSign(UChar minusSign)
  464. {
  465.     fMinusSign = minusSign;
  466. }
  467.  
  468. // -------------------------------------
  469.  
  470. inline UChar
  471. DecimalFormatSymbols::getExponentialSymbol(void) const
  472. {
  473.     return fExponential;
  474. }
  475.  
  476. // -------------------------------------
  477.  
  478. inline void
  479. DecimalFormatSymbols::setExponentialSymbol(UChar exponential)
  480. {
  481.     fExponential = exponential;
  482. }
  483.  
  484. // -------------------------------------
  485.  
  486. inline UnicodeString&
  487. DecimalFormatSymbols::getCurrencySymbol(UnicodeString& result) const
  488. {
  489.     result = fCurrencySymbol;
  490.     return result;
  491. }
  492.  
  493. // -------------------------------------
  494.  
  495. inline void
  496. DecimalFormatSymbols::setCurrencySymbol(const UnicodeString& str)
  497. {
  498.     fCurrencySymbol = str;
  499. }
  500.  
  501. // -------------------------------------
  502.  
  503. inline UnicodeString&
  504. DecimalFormatSymbols::getInternationalCurrencySymbol(UnicodeString& result) const
  505. {
  506.     result = fIntlCurrencySymbol;
  507.     return result;
  508. }
  509.  
  510. // -------------------------------------
  511.  
  512. inline void
  513. DecimalFormatSymbols::setInternationalCurrencySymbol(const UnicodeString& str)
  514. {
  515.     fIntlCurrencySymbol = str;
  516. }
  517.  
  518. // -------------------------------------
  519.  
  520. inline UChar
  521. DecimalFormatSymbols::getMonetaryDecimalSeparator(void) const
  522. {
  523.     return fMonetarySeparator;
  524. }
  525.  
  526. // -------------------------------------
  527.  
  528. inline void
  529. DecimalFormatSymbols::setMonetaryDecimalSeparator(UChar sep)
  530. {
  531.     fMonetarySeparator = sep;
  532. }
  533.  
  534. inline UChar DecimalFormatSymbols::getPadEscape(void) const {
  535.     return fPadEscape;
  536. }
  537.  
  538. inline void DecimalFormatSymbols::setPadEscape(UChar c) {
  539.     fPadEscape = c;
  540. }
  541.  
  542. #endif // _DCFMTSYM
  543. //eof
  544.