ICU 55.1 55.1

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

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rbnf.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 *******************************************************************************
6 */
7
8 #ifndef RBNF_H
9 #define RBNF_H
10
11 #include "unicode/utypes.h"
12
25 #if UCONFIG_NO_FORMATTING
26 #define U_HAVE_RBNF 0
27 #else
28 #define U_HAVE_RBNF 1
29
30 #include "unicode/dcfmtsym.h"
31 #include "unicode/fmtable.h"
32 #include "unicode/locid.h"
33 #include "unicode/numfmt.h"
34 #include "unicode/unistr.h"
35 #include "unicode/strenum.h"
36 #include "unicode/brkiter.h"
37 #include "unicode/upluralrules.h"
38
39 U_NAMESPACE_BEGIN
40
41 class NFRuleSet;
42 class LocalizationInfo;
43 class PluralFormat;
44 class RuleBasedCollator;
45
51 enum URBNFRuleSetTag {
52 URBNF_SPELLOUT,
53 URBNF_ORDINAL,
54 URBNF_DURATION,
55 URBNF_NUMBERING_SYSTEM,
56 URBNF_COUNT
57 };
58
522 class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
523 public:
524
525 //-----------------------------------------------------------------------
526 // constructors
527 //-----------------------------------------------------------------------
528
539 RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
540
564 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
565 UParseError& perror, UErrorCode& status);
566
582 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
583 UParseError& perror, UErrorCode& status);
584
611 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
612 const Locale& locale, UParseError& perror, UErrorCode& status);
613
629 RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
630
631 //-----------------------------------------------------------------------
632 // boilerplate
633 //-----------------------------------------------------------------------
634
640 RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
641
647 RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
648
653 virtual ~RuleBasedNumberFormat();
654
661 virtual Format* clone(void) const;
662
670 virtual UBool operator==(const Format& other) const;
671
672 //-----------------------------------------------------------------------
673 // public API functions
674 //-----------------------------------------------------------------------
675
681 virtual UnicodeString getRules() const;
682
688 virtual int32_t getNumberOfRuleSetNames() const;
689
697 virtual UnicodeString getRuleSetName(int32_t index) const;
698
704 virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
705
714 virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
715
729 virtual UnicodeString getRuleSetDisplayName(int32_t index,
730 const Locale& locale = Locale::getDefault());
731
740 virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
741 const Locale& locale = Locale::getDefault());
742
743
744 using NumberFormat::format;
745
754 virtual UnicodeString& format(int32_t number,
755 UnicodeString& toAppendTo,
756 FieldPosition& pos) const;
757
766 virtual UnicodeString& format(int64_t number,
767 UnicodeString& toAppendTo,
768 FieldPosition& pos) const;
777 virtual UnicodeString& format(double number,
778 UnicodeString& toAppendTo,
779 FieldPosition& pos) const;
780
792 virtual UnicodeString& format(int32_t number,
793 const UnicodeString& ruleSetName,
794 UnicodeString& toAppendTo,
795 FieldPosition& pos,
796 UErrorCode& status) const;
808 virtual UnicodeString& format(int64_t number,
809 const UnicodeString& ruleSetName,
810 UnicodeString& toAppendTo,
811 FieldPosition& pos,
812 UErrorCode& status) const;
824 virtual UnicodeString& format(double number,
825 const UnicodeString& ruleSetName,
826 UnicodeString& toAppendTo,
827 FieldPosition& pos,
828 UErrorCode& status) const;
829
830 using NumberFormat::parse;
831
846 virtual void parse(const UnicodeString& text,
847 Formattable& result,
848 ParsePosition& parsePosition) const;
849
850 #if !UCONFIG_NO_COLLATION
851
885 virtual void setLenient(UBool enabled);
886
894 virtual inline UBool isLenient(void) const;
895
896 #endif
897
906 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
907
914 virtual UnicodeString getDefaultRuleSetName() const;
915
926 virtual void setContext(UDisplayContext value, UErrorCode& status);
927
928 public:
934 static UClassID U_EXPORT2 getStaticClassID(void);
935
941 virtual UClassID getDynamicClassID(void) const;
942
951 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
952
962 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
963
964 private:
965 RuleBasedNumberFormat(); // default constructor not implemented
966
967 // this will ref the localizations if they are not NULL
968 // caller must deref to get adoption
969 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
970 const Locale& locale, UParseError& perror, UErrorCode& status);
971
972 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
973 void initCapitalizationContextInfo(const Locale& thelocale);
974 void dispose();
975 void stripWhitespace(UnicodeString& src);
976 void initDefaultRuleSet();
977 void format(double number, NFRuleSet& ruleSet);
978 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
979
980 /* friend access */
981 friend class NFSubstitution;
982 friend class NFRule;
983 friend class FractionalPartSubstitution;
984
985 inline NFRuleSet * getDefaultRuleSet() const;
986 const RuleBasedCollator * getCollator() const;
987 DecimalFormatSymbols * getDecimalFormatSymbols() const;
988 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
989 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult) const;
990
991 private:
992 NFRuleSet **ruleSets;
993 UnicodeString* ruleSetDescriptions;
994 int32_t numRuleSets;
995 NFRuleSet *defaultRuleSet;
996 Locale locale;
997 RuleBasedCollator* collator;
998 DecimalFormatSymbols* decimalFormatSymbols;
999 UBool lenient;
1000 UnicodeString* lenientParseRules;
1001 LocalizationInfo* localizations;
1002 UnicodeString originalDescription;
1003 UBool capitalizationInfoSet;
1004 UBool capitalizationForUIListMenu;
1005 UBool capitalizationForStandAlone;
1006 BreakIterator* capitalizationBrkIter;
1007 };
1008
1009 // ---------------
1010
1011 #if !UCONFIG_NO_COLLATION
1012
1013 inline UBool
1014 RuleBasedNumberFormat::isLenient(void) const {
1015 return lenient;
1016 }
1017
1018 #endif
1019
1020 inline NFRuleSet*
1021 RuleBasedNumberFormat::getDefaultRuleSet() const {
1022 return defaultRuleSet;
1023 }
1024
1025 U_NAMESPACE_END
1026
1027 /* U_HAVE_RBNF */
1028 #endif
1029
1030 /* RBNF_H */
1031 #endif