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

- Search for |

- File List
- Globals

# rbnf.h

Go to the documentation of this file.

    00001 /*
    00002 *******************************************************************************
    00003 * Copyright (C) 1997-2009, 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_NUMBERING_SYSTEM,
    00053     URBNF_COUNT
    00054 };
    00055
    00056 #if UCONFIG_NO_COLLATION
    00057 class Collator;
    00058 #endif
    00059
    00503 class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
    00504 public:
    00505
    00506   //-----------------------------------------------------------------------
    00507   // constructors
    00508   //-----------------------------------------------------------------------
    00509
    00520     RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
    00521
    00545     RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
    00546                         UParseError& perror, UErrorCode& status);
    00547
    00563   RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
    00564                         UParseError& perror, UErrorCode& status);
    00565
    00592     RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
    00593                         const Locale& locale, UParseError& perror, UErrorCode& status);
    00594
    00610   RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
    00611
    00612   //-----------------------------------------------------------------------
    00613   // boilerplate
    00614   //-----------------------------------------------------------------------
    00615
    00621   RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
    00622
    00628   RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
    00629
    00634   virtual ~RuleBasedNumberFormat();
    00635
    00642   virtual Format* clone(void) const;
    00643
    00651   virtual UBool operator==(const Format& other) const;
    00652
    00653 //-----------------------------------------------------------------------
    00654 // public API functions
    00655 //-----------------------------------------------------------------------
    00656
    00662   virtual UnicodeString getRules() const;
    00663
    00669   virtual int32_t getNumberOfRuleSetNames() const;
    00670
    00678   virtual UnicodeString getRuleSetName(int32_t index) const;
    00679
    00685   virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
    00686
    00695   virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
    00696
    00710   virtual UnicodeString getRuleSetDisplayName(int32_t index,
    00711                           const Locale& locale = Locale::getDefault());
    00712
    00721   virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
    00722                           const Locale& locale = Locale::getDefault());
    00723
    00732   virtual UnicodeString& format(int32_t number,
    00733                                 UnicodeString& toAppendTo,
    00734                                 FieldPosition& pos) const;
    00735
    00744   virtual UnicodeString& format(int64_t number,
    00745                                 UnicodeString& toAppendTo,
    00746                                 FieldPosition& pos) const;
    00755   virtual UnicodeString& format(double number,
    00756                                 UnicodeString& toAppendTo,
    00757                                 FieldPosition& pos) const;
    00758
    00770   virtual UnicodeString& format(int32_t number,
    00771                                 const UnicodeString& ruleSetName,
    00772                                 UnicodeString& toAppendTo,
    00773                                 FieldPosition& pos,
    00774                                 UErrorCode& status) const;
    00786   virtual UnicodeString& format(int64_t number,
    00787                                 const UnicodeString& ruleSetName,
    00788                                 UnicodeString& toAppendTo,
    00789                                 FieldPosition& pos,
    00790                                 UErrorCode& status) const;
    00802   virtual UnicodeString& format(double number,
    00803                                 const UnicodeString& ruleSetName,
    00804                                 UnicodeString& toAppendTo,
    00805                                 FieldPosition& pos,
    00806                                 UErrorCode& status) const;
    00807
    00817   virtual UnicodeString& format(const Formattable& obj,
    00818                                 UnicodeString& toAppendTo,
    00819                                 FieldPosition& pos,
    00820                                 UErrorCode& status) const;
    00829   UnicodeString& format(const Formattable& obj,
    00830                         UnicodeString& result,
    00831                         UErrorCode& status) const;
    00832
    00840    UnicodeString& format(double number,
    00841                          UnicodeString& output) const;
    00842
    00850    UnicodeString& format(int32_t number,
    00851                          UnicodeString& output) const;
    00852
    00867   virtual void parse(const UnicodeString& text,
    00868                      Formattable& result,
    00869                      ParsePosition& parsePosition) const;
    00870
    00871
    00879   virtual inline void parse(const UnicodeString& text,
    00880                       Formattable& result,
    00881                       UErrorCode& status) const;
    00882
    00883 #if !UCONFIG_NO_COLLATION
    00884
    00918   virtual void setLenient(UBool enabled);
    00919
    00927   virtual inline UBool isLenient(void) const;
    00928
    00929 #endif
    00930
    00939   virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
    00940
    00947   virtual UnicodeString getDefaultRuleSetName() const;
    00948
    00949 public:
    00955     static UClassID U_EXPORT2 getStaticClassID(void);
    00956
    00962     virtual UClassID getDynamicClassID(void) const;
    00963
    00964 private:
    00965     RuleBasedNumberFormat(); // default constructor not implemented
    00966
    00967     // this will ref the localizations if they are not NULL
    00968     // caller must deref to get adoption
    00969     RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
    00970               const Locale& locale, UParseError& perror, UErrorCode& status);
    00971
    00972     void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
    00973     void dispose();
    00974     void stripWhitespace(UnicodeString& src);
    00975     void initDefaultRuleSet();
    00976     void format(double number, NFRuleSet& ruleSet);
    00977     NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
    00978
    00979     /* friend access */
    00980     friend class NFSubstitution;
    00981     friend class NFRule;
    00982     friend class FractionalPartSubstitution;
    00983
    00984     inline NFRuleSet * getDefaultRuleSet() const;
    00985     Collator * getCollator() const;
    00986     DecimalFormatSymbols * getDecimalFormatSymbols() const;
    00987
    00988 private:
    00989     NFRuleSet **ruleSets;
    00990     NFRuleSet *defaultRuleSet;
    00991     Locale locale;
    00992     Collator* collator;
    00993     DecimalFormatSymbols* decimalFormatSymbols;
    00994     UBool lenient;
    00995     UnicodeString* lenientParseRules;
    00996     LocalizationInfo* localizations;
    00997 };
    00998
    00999 // ---------------
    01000
    01001 inline UnicodeString&
    01002 RuleBasedNumberFormat::format(const Formattable& obj,
    01003                               UnicodeString& result,
    01004                               UErrorCode& status) const
    01005 {
    01006     // Don't use Format:: - use immediate base class only,
    01007     // in case immediate base modifies behavior later.
    01008     // dlf - the above comment is bogus, if there were a reason to modify
    01009     // it, it would be virtual, and there's no reason because it is
    01010     // a one-line macro in NumberFormat anyway, just like this one.
    01011     return NumberFormat::format(obj, result, status);
    01012 }
    01013
    01014 inline UnicodeString&
    01015 RuleBasedNumberFormat::format(double number, UnicodeString& output) const {
    01016     FieldPosition pos(0);
    01017     return format(number, output, pos);
    01018 }
    01019
    01020 inline UnicodeString&
    01021 RuleBasedNumberFormat::format(int32_t number, UnicodeString& output) const {
    01022     FieldPosition pos(0);
    01023     return format(number, output, pos);
    01024 }
    01025
    01026 inline void
    01027 RuleBasedNumberFormat::parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const
    01028 {
    01029     NumberFormat::parse(text, result, status);
    01030 }
    01031
    01032 #if !UCONFIG_NO_COLLATION
    01033
    01034 inline UBool
    01035 RuleBasedNumberFormat::isLenient(void) const {
    01036     return lenient;
    01037 }
    01038
    01039 #endif
    01040
    01041 inline NFRuleSet*
    01042 RuleBasedNumberFormat::getDefaultRuleSet() const {
    01043     return defaultRuleSet;
    01044 }
    01045
    01046 U_NAMESPACE_END
    01047
    01048 /* U_HAVE_RBNF */
    01049 #endif
    01050
    01051 /* RBNF_H */
    01052 #endif