1/* 2 * Copyright 2003-2014, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _B_LOCALE_H_ 6#define _B_LOCALE_H_ 7 8 9#include <Collator.h> 10#include <FormattingConventions.h> 11#include <Language.h> 12#include <Locker.h> 13 14 15class BCatalog; 16class BString; 17 18 19class BLocale { 20public: 21 BLocale(const BLanguage* language = NULL, 22 const BFormattingConventions* conventions 23 = NULL); 24 BLocale(const BLocale& other); 25 ~BLocale(); 26 27 static const BLocale* Default(); 28 29 BLocale& operator=(const BLocale& other); 30 31 status_t GetCollator(BCollator* collator) const; 32 status_t GetLanguage(BLanguage* language) const; 33 status_t GetFormattingConventions( 34 BFormattingConventions* conventions) const; 35 36 void SetFormattingConventions( 37 const BFormattingConventions& conventions); 38 void SetCollator(const BCollator& newCollator); 39 void SetLanguage(const BLanguage& newLanguage); 40 41 // see definitions in LocaleStrings.h 42 const char* GetString(uint32 id) const; 43 44 // Collator short-hands 45 int StringCompare(const char* s1, 46 const char* s2) const; 47 int StringCompare(const BString* s1, 48 const BString* s2) const; 49 50 void GetSortKey(const char* string, 51 BString* sortKey) const; 52 53private: 54 mutable BLocker fLock; 55 BCollator fCollator; 56 BFormattingConventions fConventions; 57 BLanguage fLanguage; 58}; 59 60 61//--- collator short-hands inlines --- 62// #pragma mark - 63 64inline int 65BLocale::StringCompare(const char* s1, const char* s2) const 66{ 67 return fCollator.Compare(s1, s2); 68} 69 70 71inline int 72BLocale::StringCompare(const BString* s1, const BString* s2) const 73{ 74 return fCollator.Compare(s1->String(), s2->String()); 75} 76 77 78inline void 79BLocale::GetSortKey(const char* string, BString* sortKey) const 80{ 81 fCollator.GetSortKey(string, sortKey); 82} 83 84 85#endif /* _B_LOCALE_H_ */ 86