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

- File List
- Globals

# rbnf.h

Go to the documentation of this file.

    00001 /*
    00002 *******************************************************************************
    00003 * Copyright (C) 1997-2010, 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
    00724
    00725   using NumberFormat::format;
    00726
    00735   virtual UnicodeString& format(int32_t number,
    00736                                 UnicodeString& toAppendTo,
    00737                                 FieldPosition& pos) const;
    00738
    00747   virtual UnicodeString& format(int64_t number,
    00748                                 UnicodeString& toAppendTo,
    00749                                 FieldPosition& pos) const;
    00758   virtual UnicodeString& format(double number,
    00759                                 UnicodeString& toAppendTo,
    00760                                 FieldPosition& pos) const;
    00761
    00773   virtual UnicodeString& format(int32_t number,
    00774                                 const UnicodeString& ruleSetName,
    00775                                 UnicodeString& toAppendTo,
    00776                                 FieldPosition& pos,
    00777                                 UErrorCode& status) const;
    00789   virtual UnicodeString& format(int64_t number,
    00790                                 const UnicodeString& ruleSetName,
    00791                                 UnicodeString& toAppendTo,
    00792                                 FieldPosition& pos,
    00793                                 UErrorCode& status) const;
    00805   virtual UnicodeString& format(double number,
    00806                                 const UnicodeString& ruleSetName,
    00807                                 UnicodeString& toAppendTo,
    00808                                 FieldPosition& pos,
    00809                                 UErrorCode& status) const;
    00810
    00820   virtual UnicodeString& format(const Formattable& obj,
    00821                                 UnicodeString& toAppendTo,
    00822                                 FieldPosition& pos,
    00823                                 UErrorCode& status) const;
    00832   UnicodeString& format(const Formattable& obj,
    00833                         UnicodeString& result,
    00834                         UErrorCode& status) const;
    00835
    00843    UnicodeString& format(double number,
    00844                          UnicodeString& output) const;
    00845
    00853    UnicodeString& format(int32_t number,
    00854                          UnicodeString& output) const;
    00855
    00870   virtual void parse(const UnicodeString& text,
    00871                      Formattable& result,
    00872                      ParsePosition& parsePosition) const;
    00873
    00874
    00882   virtual inline void parse(const UnicodeString& text,
    00883                       Formattable& result,
    00884                       UErrorCode& status) const;
    00885
    00886 #if !UCONFIG_NO_COLLATION
    00887
    00921   virtual void setLenient(UBool enabled);
    00922
    00930   virtual inline UBool isLenient(void) const;
    00931
    00932 #endif
    00933
    00942   virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
    00943
    00950   virtual UnicodeString getDefaultRuleSetName() const;
    00951
    00952 public:
    00958     static UClassID U_EXPORT2 getStaticClassID(void);
    00959
    00965     virtual UClassID getDynamicClassID(void) const;
    00966
    00967 private:
    00968     RuleBasedNumberFormat(); // default constructor not implemented
    00969
    00970     // this will ref the localizations if they are not NULL
    00971     // caller must deref to get adoption
    00972     RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
    00973               const Locale& locale, UParseError& perror, UErrorCode& status);
    00974
    00975     void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
    00976     void dispose();
    00977     void stripWhitespace(UnicodeString& src);
    00978     void initDefaultRuleSet();
    00979     void format(double number, NFRuleSet& ruleSet);
    00980     NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
    00981
    00982     /* friend access */
    00983     friend class NFSubstitution;
    00984     friend class NFRule;
    00985     friend class FractionalPartSubstitution;
    00986
    00987     inline NFRuleSet * getDefaultRuleSet() const;
    00988     Collator * getCollator() const;
    00989     DecimalFormatSymbols * getDecimalFormatSymbols() const;
    00990
    00991 private:
    00992     NFRuleSet **ruleSets;
    00993     NFRuleSet *defaultRuleSet;
    00994     Locale locale;
    00995     Collator* collator;
    00996     DecimalFormatSymbols* decimalFormatSymbols;
    00997     UBool lenient;
    00998     UnicodeString* lenientParseRules;
    00999     LocalizationInfo* localizations;
    01000
    01001     // Temporary workaround - when noParse is true, do noting in parse.
    01002     // TODO: We need a real fix - see #6895/#6896
    01003     UBool noParse;
    01004 };
    01005
    01006 // ---------------
    01007
    01008 inline UnicodeString&
    01009 RuleBasedNumberFormat::format(const Formattable& obj,
    01010                               UnicodeString& result,
    01011                               UErrorCode& status) const
    01012 {
    01013     // Don't use Format:: - use immediate base class only,
    01014     // in case immediate base modifies behavior later.
    01015     // dlf - the above comment is bogus, if there were a reason to modify
    01016     // it, it would be virtual, and there's no reason because it is
    01017     // a one-line macro in NumberFormat anyway, just like this one.
    01018     return NumberFormat::format(obj, result, status);
    01019 }
    01020
    01021 inline UnicodeString&
    01022 RuleBasedNumberFormat::format(double number, UnicodeString& output) const {
    01023     FieldPosition pos(0);
    01024     return format(number, output, pos);
    01025 }
    01026
    01027 inline UnicodeString&
    01028 RuleBasedNumberFormat::format(int32_t number, UnicodeString& output) const {
    01029     FieldPosition pos(0);
    01030     return format(number, output, pos);
    01031 }
    01032
    01033 inline void
    01034 RuleBasedNumberFormat::parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const
    01035 {
    01036     NumberFormat::parse(text, result, status);
    01037 }
    01038
    01039 #if !UCONFIG_NO_COLLATION
    01040
    01041 inline UBool
    01042 RuleBasedNumberFormat::isLenient(void) const {
    01043     return lenient;
    01044 }
    01045
    01046 #endif
    01047
    01048 inline NFRuleSet*
    01049 RuleBasedNumberFormat::getDefaultRuleSet() const {
    01050     return defaultRuleSet;
    01051 }
    01052
    01053 U_NAMESPACE_END
    01054
    01055 /* U_HAVE_RBNF */
    01056 #endif
    01057
    01058 /* RBNF_H */
    01059 #endif

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines