1 #ifndef _B_LOCALE_H_ 2 #define _B_LOCALE_H_ 3 4 5 #include <Collator.h> 6 #include <Language.h> 7 #include <Country.h> 8 9 class BCatalog; 10 class BLocaleRoster; 11 class BString; 12 13 14 class BLocale { 15 public: 16 BLocale(); 17 ~BLocale(); 18 19 BCollator *Collator() const { return fCollator; } 20 BCountry *Country() const { return fCountry; } 21 BLanguage *Language() const { return fLanguage; } 22 23 // see definitions in LocaleStrings.h 24 const char *GetString(uint32 id); 25 26 void FormatString(char *target, size_t maxSize, char *fmt, ...); 27 void FormatString(BString *, char *fmt, ...); 28 void FormatDateTime(char *target, size_t maxSize, const char *fmt, 29 time_t); 30 void FormatDateTime(BString *, const char *fmt, time_t); 31 32 // Country short-hands 33 34 void FormatDate(char *target, size_t maxSize, time_t, bool longFormat); 35 void FormatDate(BString *target, time_t, bool longFormat); 36 void FormatTime(char *target, size_t maxSize, time_t, bool longFormat); 37 void FormatTime(BString *target, time_t, bool longFormat); 38 39 // Collator short-hands 40 41 int StringCompare(const char *, const char *, int32 len = -1, 42 int8 strength = B_COLLATE_DEFAULT) const; 43 int StringCompare(const BString *, const BString *, 44 int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const; 45 46 void GetSortKey(const char *string, BString *key); 47 48 status_t GetAppCatalog(BCatalog *); 49 50 protected: 51 BCollator *fCollator; 52 BLanguage *fLanguage; 53 BCountry *fCountry; 54 }; 55 56 // global objects 57 extern BLocale *be_locale; 58 extern BLocaleRoster *be_locale_roster; 59 60 //---------------------------------------------------------------------- 61 //--- country short-hands inlines --- 62 63 inline void 64 BLocale::FormatDate(char *target, size_t maxSize, time_t timer, bool longFormat) 65 { 66 fCountry->FormatDate(target, maxSize, timer, longFormat); 67 } 68 69 70 inline void 71 BLocale::FormatDate(BString *target, time_t timer, bool longFormat) 72 { 73 fCountry->FormatDate(target, timer, longFormat); 74 } 75 76 77 inline void 78 BLocale::FormatTime(char *target, size_t maxSize, time_t timer, bool longFormat) 79 { 80 fCountry->FormatTime(target, maxSize, timer, longFormat); 81 } 82 83 84 inline void 85 BLocale::FormatTime(BString *target, time_t timer, bool longFormat) 86 { 87 fCountry->FormatTime(target, timer, longFormat); 88 } 89 90 91 //--- locale short-hands inlines --- 92 // #pragma mark - 93 94 inline int 95 BLocale::StringCompare(const char *string1, const char *string2, int32 length, int8 strength) const 96 { 97 return fCollator->Compare(string1, string2, length, strength); 98 } 99 100 101 inline int 102 BLocale::StringCompare(const BString *string1, const BString *string2, int32 length, int8 strength) const 103 { 104 return fCollator->Compare(string1->String(), string2->String(), length, strength); 105 } 106 107 108 inline void 109 BLocale::GetSortKey(const char *string, BString *key) 110 { 111 fCollator->GetSortKey(string, key); 112 } 113 114 #endif /* _B_LOCALE_H_ */ 115