2010-07-27 02:05:39 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003-2010, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2009-05-01 23:23:59 +04:00
|
|
|
#ifndef _B_LOCALE_H_
|
|
|
|
#define _B_LOCALE_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <Collator.h>
|
|
|
|
#include <Country.h>
|
2010-08-02 00:28:19 +04:00
|
|
|
#include <Language.h>
|
2010-08-30 00:55:00 +04:00
|
|
|
#include <Locker.h>
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
|
|
|
|
class BCatalog;
|
|
|
|
class BString;
|
2010-08-16 19:03:54 +04:00
|
|
|
class BTimeZone;
|
2009-05-01 23:23:59 +04:00
|
|
|
|
|
|
|
|
2010-08-17 00:19:51 +04:00
|
|
|
typedef enum {
|
|
|
|
B_DATE_ELEMENT_INVALID = B_BAD_DATA,
|
|
|
|
B_DATE_ELEMENT_YEAR = 0,
|
|
|
|
B_DATE_ELEMENT_MONTH,
|
|
|
|
B_DATE_ELEMENT_DAY,
|
|
|
|
B_DATE_ELEMENT_AM_PM,
|
|
|
|
B_DATE_ELEMENT_HOUR,
|
|
|
|
B_DATE_ELEMENT_MINUTE,
|
|
|
|
B_DATE_ELEMENT_SECOND
|
|
|
|
} BDateElement;
|
|
|
|
|
2010-08-24 21:49:12 +04:00
|
|
|
typedef enum {
|
|
|
|
B_NUMBER_ELEMENT_INVALID = B_BAD_DATA,
|
|
|
|
B_NUMBER_ELEMENT_INTEGER = 0,
|
|
|
|
B_NUMBER_ELEMENT_FRACTIONAL,
|
|
|
|
B_NUMBER_ELEMENT_CURRENCY
|
|
|
|
} BNumberElement;
|
|
|
|
|
2010-08-17 00:19:51 +04:00
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
class BLocale {
|
2010-08-02 00:28:19 +04:00
|
|
|
public:
|
2010-08-04 22:45:06 +04:00
|
|
|
BLocale(const char* languageAndCountryCode
|
|
|
|
= "en_US");
|
|
|
|
BLocale(const BLocale& other);
|
2010-08-02 00:28:19 +04:00
|
|
|
~BLocale();
|
|
|
|
|
2010-08-30 00:55:00 +04:00
|
|
|
BLocale& operator=(const BLocale& other);
|
|
|
|
|
|
|
|
status_t GetCollator(BCollator* collator) const;
|
|
|
|
status_t GetLanguage(BLanguage* language) const;
|
|
|
|
status_t GetCountry(BCountry* country) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
const char* Code() const;
|
2010-08-05 14:19:22 +04:00
|
|
|
bool GetName(BString& name) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
|
|
|
void SetCountry(const BCountry& newCountry);
|
|
|
|
void SetCollator(const BCollator& newCollator);
|
|
|
|
void SetLanguage(const char* languageCode);
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
// see definitions in LocaleStrings.h
|
2010-08-30 22:57:17 +04:00
|
|
|
const char* GetString(uint32 id) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
void FormatString(char* target, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
char* fmt, ...) const;
|
|
|
|
void FormatString(BString* buffer, char* fmt,
|
|
|
|
...) const;
|
2010-08-07 15:22:16 +04:00
|
|
|
status_t FormatDateTime(char* target, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
time_t time, bool longFormat) const;
|
2010-08-07 15:22:16 +04:00
|
|
|
status_t FormatDateTime(BString* buffer, time_t time,
|
2010-08-27 02:17:40 +04:00
|
|
|
bool longFormat,
|
2010-08-30 22:57:17 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2010-08-04 22:45:06 +04:00
|
|
|
// Date
|
|
|
|
|
2010-08-16 19:03:54 +04:00
|
|
|
// TODO: drop some of these once BDateFormat
|
|
|
|
// has been implemented!
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatDate(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
time_t time, bool longFormat) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatDate(BString* string, time_t time,
|
2010-08-27 02:17:40 +04:00
|
|
|
bool longFormat,
|
2010-08-30 22:57:17 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatDate(BString* string,
|
|
|
|
int*& fieldPositions, int& fieldCount,
|
2010-08-30 22:57:17 +04:00
|
|
|
time_t time, bool longFormat) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t GetDateFields(BDateElement*& fields,
|
|
|
|
int& fieldCount, bool longFormat) const;
|
|
|
|
status_t GetDateFormat(BString&, bool longFormat) const;
|
|
|
|
status_t SetDateFormat(const char* formatString,
|
|
|
|
bool longFormat = true);
|
|
|
|
|
|
|
|
int StartOfWeek() const;
|
|
|
|
|
|
|
|
// Time
|
|
|
|
|
2010-08-16 19:03:54 +04:00
|
|
|
// TODO: drop some of these once BTimeFormat
|
|
|
|
// has been implemented!
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatTime(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
time_t time, bool longFormat) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatTime(BString* string, time_t time,
|
2010-08-16 19:03:54 +04:00
|
|
|
bool longFormat,
|
2010-08-30 22:57:17 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatTime(BString* string,
|
|
|
|
int*& fieldPositions, int& fieldCount,
|
2010-08-30 22:57:17 +04:00
|
|
|
time_t time, bool longFormat) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t GetTimeFields(BDateElement*& fields,
|
|
|
|
int& fieldCount, bool longFormat) const;
|
|
|
|
|
|
|
|
status_t SetTimeFormat(const char* formatString,
|
|
|
|
bool longFormat = true);
|
|
|
|
status_t GetTimeFormat(BString& out,
|
|
|
|
bool longFormat) const;
|
|
|
|
|
|
|
|
// numbers
|
|
|
|
|
|
|
|
status_t FormatNumber(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
double value) const;
|
|
|
|
status_t FormatNumber(BString* string,
|
|
|
|
double value) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatNumber(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
int32 value) const;
|
|
|
|
status_t FormatNumber(BString* string,
|
|
|
|
int32 value) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
|
|
|
// monetary
|
|
|
|
|
|
|
|
ssize_t FormatMonetary(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
double value) const;
|
|
|
|
ssize_t FormatMonetary(BString* string,
|
|
|
|
double value) const;
|
2010-08-24 21:49:12 +04:00
|
|
|
status_t FormatMonetary(BString* string,
|
|
|
|
int*& fieldPositions,
|
|
|
|
BNumberElement*& fieldTypes,
|
2010-08-30 22:57:17 +04:00
|
|
|
int& fieldCount, double value) const;
|
|
|
|
status_t GetCurrencySymbol(BString& result) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
// Collator short-hands
|
|
|
|
int StringCompare(const char* s1,
|
|
|
|
const char* s2) const;
|
|
|
|
int StringCompare(const BString* s1,
|
|
|
|
const BString* s2) const;
|
|
|
|
|
|
|
|
void GetSortKey(const char* string,
|
|
|
|
BString* key) const;
|
|
|
|
|
|
|
|
protected:
|
2010-08-30 00:55:00 +04:00
|
|
|
mutable BLocker fLock;
|
2010-08-02 00:28:19 +04:00
|
|
|
BCollator fCollator;
|
|
|
|
BCountry fCountry;
|
|
|
|
BLanguage fLanguage;
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-08-04 22:45:06 +04:00
|
|
|
icu_44::Locale* fICULocale;
|
|
|
|
BString fLongDateFormat;
|
|
|
|
BString fShortDateFormat;
|
|
|
|
BString fLongTimeFormat;
|
|
|
|
BString fShortTimeFormat;
|
|
|
|
};
|
2009-05-01 23:23:59 +04:00
|
|
|
|
|
|
|
|
2010-08-30 00:55:00 +04:00
|
|
|
// global locale object
|
|
|
|
extern const BLocale* be_locale;
|
|
|
|
|
|
|
|
|
2010-08-04 22:45:06 +04:00
|
|
|
//--- collator short-hands inlines ---
|
2009-05-01 23:23:59 +04:00
|
|
|
// #pragma mark -
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline int
|
2010-08-02 00:28:19 +04:00
|
|
|
BLocale::StringCompare(const char* s1, const char* s2) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return fCollator.Compare(s1, s2);
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline int
|
2010-08-02 00:28:19 +04:00
|
|
|
BLocale::StringCompare(const BString* s1, const BString* s2) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return fCollator.Compare(s1->String(), s2->String());
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
2010-08-02 00:28:19 +04:00
|
|
|
BLocale::GetSortKey(const char* string, BString* key) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
fCollator.GetSortKey(string, key);
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
#endif /* _B_LOCALE_H_ */
|