xref: /haiku/headers/os/locale/Locale.h (revision 4d978eea2f9530892046f3344341ed85c9e0b1cf)
1 /*
2  * Copyright 2003-2010, 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 <Country.h>
11 #include <Language.h>
12 
13 
14 class BCatalog;
15 class BString;
16 
17 
18 class BLocale {
19 public:
20 								BLocale();
21 								~BLocale();
22 
23 			const BCollator*	Collator() const { return &fCollator; }
24 			const BCountry*		Country() const { return &fCountry; }
25 			const BLanguage*	Language() const { return &fLanguage; }
26 
27 			// see definitions in LocaleStrings.h
28 			const char*			GetString(uint32 id);
29 
30 			void				FormatString(char* target, size_t maxSize,
31 									char* fmt, ...);
32 			void				FormatString(BString* buffer, char* fmt, ...);
33 			void				FormatDateTime(char* target, size_t maxSize,
34 									const char* fmt, time_t value);
35 			void				FormatDateTime(BString* buffer, const char* fmt,
36 									time_t value);
37 
38 			// Country short-hands, TODO: all these should go, once the
39 			// Date...Format classes are done
40 			void				FormatDate(char* target, size_t maxSize,
41 									time_t value, bool longFormat);
42 			void				FormatDate(BString* target, time_t value,
43 									bool longFormat);
44 			void				FormatTime(char* target, size_t maxSize,
45 									time_t value, bool longFormat);
46 			void				FormatTime(BString* target, time_t value,
47 									bool longFormat);
48 
49 			// Collator short-hands
50 			int					StringCompare(const char* s1,
51 									const char* s2) const;
52 			int					StringCompare(const BString* s1,
53 									const BString* s2) const;
54 
55 			void				GetSortKey(const char* string,
56 									BString* key) const;
57 
58 protected:
59 			BCollator			fCollator;
60 			BCountry			fCountry;
61 			BLanguage			fLanguage;
62 };
63 
64 
65 // global objects
66 extern BLocale* be_locale;
67 
68 
69 //----------------------------------------------------------------------
70 //--- country short-hands inlines ---
71 inline void
72 BLocale::FormatDate(char* target, size_t maxSize, time_t timer, bool longFormat)
73 {
74 	fCountry.FormatDate(target, maxSize, timer, longFormat);
75 }
76 
77 
78 inline void
79 BLocale::FormatDate(BString* target, time_t timer, bool longFormat)
80 {
81 	fCountry.FormatDate(target, timer, longFormat);
82 }
83 
84 
85 inline void
86 BLocale::FormatTime(char* target, size_t maxSize, time_t timer, bool longFormat)
87 {
88 	fCountry.FormatTime(target, maxSize, timer, longFormat);
89 }
90 
91 
92 inline void
93 BLocale::FormatTime(BString* target, time_t timer, bool longFormat)
94 {
95 	fCountry.FormatTime(target, timer, longFormat);
96 }
97 
98 
99 //--- locale short-hands inlines ---
100 //	#pragma mark -
101 
102 inline int
103 BLocale::StringCompare(const char* s1, const char* s2) const
104 {
105 	return fCollator.Compare(s1, s2);
106 }
107 
108 
109 inline int
110 BLocale::StringCompare(const BString* s1, const BString* s2) const
111 {
112 	return fCollator.Compare(s1->String(), s2->String());
113 }
114 
115 
116 inline void
117 BLocale::GetSortKey(const char* string, BString* key) const
118 {
119 	fCollator.GetSortKey(string, key);
120 }
121 
122 
123 #endif	/* _B_LOCALE_H_ */
124