- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- Search for |

- File List
- Globals

# rbnf.h

Go to the documentation of this file.

    00001 /*
    00002 *******************************************************************************
    00003 * Copyright (C) 1997-2006, International Business Machines Corporation and others.
    00004 * All Rights Reserved.
    00005 *******************************************************************************
    00006 */
    00007
    00008 #ifndef RBNF_H
    00009 #define RBNF_H
    00010
    00011 #include "unicode/utypes.h"
    00012
    00025 #if UCONFIG_NO_FORMATTING
    00026 #define U_HAVE_RBNF 0
    00027 #else
    00028 #define U_HAVE_RBNF 1
    00029
    00030 #include "unicode/coll.h"
    00031 #include "unicode/dcfmtsym.h"
    00032 #include "unicode/fmtable.h"
    00033 #include "unicode/locid.h"
    00034 #include "unicode/numfmt.h"
    00035 #include "unicode/unistr.h"
    00036 #include "unicode/strenum.h"
    00037
    00038 U_NAMESPACE_BEGIN
    00039
    00040 class NFRuleSet;
    00041 class LocalizationInfo;
    00042
    00048 enum URBNFRuleSetTag {
    00049     URBNF_SPELLOUT,
    00050     URBNF_ORDINAL,
    00051     URBNF_DURATION,
    00052     URBNF_COUNT
    00053 };
    00054
    00055 #if UCONFIG_NO_COLLATION
    00056 class Collator;
    00057 #endif
    00058
    00502 class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
    00503 public:
    00504
    00505   //-----------------------------------------------------------------------
    00506   // constructors
    00507   //-----------------------------------------------------------------------
    00508
    00519     RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
    00520
    00544     RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
    00545                         UParseError& perror, UErrorCode& status);
    00546
    00562   RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
    00563                         UParseError& perror, UErrorCode& status);
    00564
    00591     RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
    00592                         const Locale& locale, UParseError& perror, UErrorCode& status);
    00593
    00607   RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
    00608
    00609   //-----------------------------------------------------------------------
    00610   // boilerplate
    00611   //-----------------------------------------------------------------------
    00612
    00618   RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
    00619
    00625   RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
    00626
    00631   virtual ~RuleBasedNumberFormat();
    00632
    00639   virtual Format* clone(void) const;
    00640
    00648   virtual UBool operator==(const Format& other) const;
    00649
    00650 //-----------------------------------------------------------------------
    00651 // public API functions
    00652 //-----------------------------------------------------------------------
    00653
    00659   virtual UnicodeString getRules() const;
    00660
    00666   virtual int32_t getNumberOfRuleSetNames() const;
    00667
    00675   virtual UnicodeString getRuleSetName(int32_t index) const;
    00676
    00682   virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
    00683
    00692   virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
    00693
    00707   virtual UnicodeString getRuleSetDisplayName(int32_t index,
    00708                           const Locale& locale = Locale::getDefault());
    00709
    00718   virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
    00719                           const Locale& locale = Locale::getDefault());
    00720
    00729   virtual UnicodeString& format(int32_t number,
    00730                                 UnicodeString& toAppendTo,
    00731                                 FieldPosition& pos) const;
    00732
    00741   virtual UnicodeString& format(int64_t number,
    00742                                 UnicodeString& toAppendTo,
    00743                                 FieldPosition& pos) const;
    00752   virtual UnicodeString& format(double number,
    00753                                 UnicodeString& toAppendTo,
    00754                                 FieldPosition& pos) const;
    00755
    00767   virtual UnicodeString& format(int32_t number,
    00768                                 const UnicodeString& ruleSetName,
    00769                                 UnicodeString& toAppendTo,
    00770                                 FieldPosition& pos,
    00771                                 UErrorCode& status) const;
    00783   virtual UnicodeString& format(int64_t number,
    00784                                 const UnicodeString& ruleSetName,
    00785                                 UnicodeString& toAppendTo,
    00786                                 FieldPosition& pos,
    00787                                 UErrorCode& status) const;
    00799   virtual UnicodeString& format(double number,
    00800                                 const UnicodeString& ruleSetName,
    00801                                 UnicodeString& toAppendTo,
    00802                                 FieldPosition& pos,
    00803                                 UErrorCode& status) const;
    00804
    00814   virtual UnicodeString& format(const Formattable& obj,
    00815                                 UnicodeString& toAppendTo,
    00816                                 FieldPosition& pos,
    00817                                 UErrorCode& status) const;
    00826   UnicodeString& format(const Formattable& obj,
    00827                         UnicodeString& result,
    00828                         UErrorCode& status) const;
    00829
    00837    UnicodeString& format(double number,
    00838                          UnicodeString& output) const;
    00839
    00847    UnicodeString& format(int32_t number,
    00848                          UnicodeString& output) const;
    00849
    00864   virtual void parse(const UnicodeString& text,
    00865                      Formattable& result,
    00866                      ParsePosition& parsePosition) const;
    00867
    00868
    00876   virtual inline void parse(const UnicodeString& text,
    00877                       Formattable& result,
    00878                       UErrorCode& status) const;
    00879
    00880 #if !UCONFIG_NO_COLLATION
    00881
    00915   virtual void setLenient(UBool enabled);
    00916
    00924   virtual inline UBool isLenient(void) const;
    00925
    00926 #endif
    00927
    00936   virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
    00937
    00944   virtual UnicodeString getDefaultRuleSetName() const;
    00945
    00946 public:
    00952     static UClassID U_EXPORT2 getStaticClassID(void);
    00953
    00959     virtual UClassID getDynamicClassID(void) const;
    00960
    00961 private:
    00962     RuleBasedNumberFormat(); // default constructor not implemented
    00963
    00964     // this will ref the localizations if they are not NULL
    00965     // caller must deref to get adoption
    00966     RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
    00967               const Locale& locale, UParseError& perror, UErrorCode& status);
    00968
    00969     void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
    00970     void dispose();
    00971     void stripWhitespace(UnicodeString& src);
    00972     void initDefaultRuleSet();
    00973     void format(double number, NFRuleSet& ruleSet);
    00974     NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
    00975
    00976     /* friend access */
    00977     friend class NFSubstitution;
    00978     friend class NFRule;
    00979     friend class FractionalPartSubstitution;
    00980
    00981     inline NFRuleSet * getDefaultRuleSet() const;
    00982     Collator * getCollator() const;
    00983     DecimalFormatSymbols * getDecimalFormatSymbols() const;
    00984
    00985 private:
    00986     NFRuleSet **ruleSets;
    00987     NFRuleSet *defaultRuleSet;
    00988     Locale locale;
    00989     Collator* collator;
    00990     DecimalFormatSymbols* decimalFormatSymbols;
    00991     UBool lenient;
    00992     UnicodeString* lenientParseRules;
    00993     LocalizationInfo* localizations;
    00994 };
    00995
    00996 // ---------------
    00997
    00998 inline UnicodeString&
    00999 RuleBasedNumberFormat::format(const Formattable& obj,
    01000                               UnicodeString& result,
    01001                               UErrorCode& status) const
    01002 {
    01003     // Don't use Format:: - use immediate base class only,
    01004     // in case immediate base modifies behavior later.
    01005     // dlf - the above comment is bogus, if there were a reason to modify
    01006     // it, it would be virtual, and there's no reason because it is
    01007     // a one-line macro in NumberFormat anyway, just like this one.
    01008     return NumberFormat::format(obj, result, status);
    01009 }
    01010
    01011 inline UnicodeString&
    01012 RuleBasedNumberFormat::format(double number, UnicodeString& output) const {
    01013     FieldPosition pos(0);
    01014     return format(number, output, pos);
    01015 }
    01016
    01017 inline UnicodeString&
    01018 RuleBasedNumberFormat::format(int32_t number, UnicodeString& output) const {
    01019     FieldPosition pos(0);
    01020     return format(number, output, pos);
    01021 }
    01022
    01023 inline void
    01024 RuleBasedNumberFormat::parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const
    01025 {
    01026     NumberFormat::parse(text, result, status);
    01027 }
    01028
    01029 #if !UCONFIG_NO_COLLATION
    01030
    01031 inline UBool
    01032 RuleBasedNumberFormat::isLenient(void) const {
    01033     return lenient;
    01034 }
    01035
    01036 #endif
    01037
    01038 inline NFRuleSet*
    01039 RuleBasedNumberFormat::getDefaultRuleSet() const {
    01040     return defaultRuleSet;
    01041 }
    01042
    01043 U_NAMESPACE_END
    01044
    01045 /* U_HAVE_RBNF */
    01046 #endif
    01047
    01048 /* RBNF_H */
    01049 #endif