xref: /haiku/headers/os/locale/Locale.h (revision a1163de83ea633463a79de234b8742ee106531b2)
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, time_t);
29 		void FormatDateTime(BString *, const char *fmt, time_t);
30 
31 		// Country short-hands
32 
33 		void FormatDate(char *target, size_t maxSize, time_t, bool longFormat);
34 		void FormatDate(BString *target, time_t, bool longFormat);
35 		void FormatTime(char *target, size_t maxSize, time_t, bool longFormat);
36 		void FormatTime(BString *target, time_t, bool longFormat);
37 
38 		// Collator short-hands
39 
40 		int StringCompare(const char *, const char *, int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const;
41 		int StringCompare(const BString *, const BString *, int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const;
42 
43 		void GetSortKey(const char *string, BString *key);
44 
45 		status_t GetAppCatalog(BCatalog *);
46 
47 	protected:
48 		BCollator	*fCollator;
49 		BLanguage	*fLanguage;
50 		BCountry	*fCountry;
51 };
52 
53 // global objects
54 extern BLocale *be_locale;
55 extern BLocaleRoster *be_locale_roster;
56 
57 //----------------------------------------------------------------------
58 //--- country short-hands inlines ---
59 
60 inline void
61 BLocale::FormatDate(char *target, size_t maxSize, time_t timer, bool longFormat)
62 {
63 	fCountry->FormatDate(target, maxSize, timer, longFormat);
64 }
65 
66 
67 inline void
68 BLocale::FormatDate(BString *target, time_t timer, bool longFormat)
69 {
70 	fCountry->FormatDate(target, timer, longFormat);
71 }
72 
73 
74 inline void
75 BLocale::FormatTime(char *target, size_t maxSize, time_t timer, bool longFormat)
76 {
77 	fCountry->FormatTime(target, maxSize, timer, longFormat);
78 }
79 
80 
81 inline void
82 BLocale::FormatTime(BString *target, time_t timer, bool longFormat)
83 {
84 	fCountry->FormatTime(target, timer, longFormat);
85 }
86 
87 
88 //--- locale short-hands inlines ---
89 //	#pragma mark -
90 
91 inline int
92 BLocale::StringCompare(const char *string1, const char *string2, int32 length, int8 strength) const
93 {
94 	return fCollator->Compare(string1, string2, length, strength);
95 }
96 
97 
98 inline int
99 BLocale::StringCompare(const BString *string1, const BString *string2, int32 length, int8 strength) const
100 {
101 	return fCollator->Compare(string1->String(), string2->String(), length, strength);
102 }
103 
104 
105 inline void
106 BLocale::GetSortKey(const char *string, BString *key)
107 {
108 	fCollator->GetSortKey(string, key);
109 }
110 
111 #endif	/* _B_LOCALE_H_ */
112