2010-07-26 22:05:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2003-2010, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2009-05-01 19:23:59 +00:00
|
|
|
#ifndef _B_LOCALE_H_
|
|
|
|
#define _B_LOCALE_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <Collator.h>
|
|
|
|
#include <Country.h>
|
2010-08-01 20:28:19 +00:00
|
|
|
#include <Language.h>
|
|
|
|
|
2009-05-01 19:23:59 +00:00
|
|
|
|
|
|
|
class BCatalog;
|
|
|
|
class BString;
|
|
|
|
|
|
|
|
|
2009-05-01 21:56:16 +00:00
|
|
|
class BLocale {
|
2010-08-01 20:28:19 +00:00
|
|
|
public:
|
|
|
|
BLocale();
|
|
|
|
~BLocale();
|
|
|
|
|
|
|
|
const BCollator* Collator() const { return &fCollator; }
|
|
|
|
const BCountry* Country() const { return &fCountry; }
|
|
|
|
const BLanguage* Language() const { return &fLanguage; }
|
|
|
|
|
|
|
|
// see definitions in LocaleStrings.h
|
|
|
|
const char* GetString(uint32 id);
|
|
|
|
|
|
|
|
void FormatString(char* target, size_t maxSize,
|
|
|
|
char* fmt, ...);
|
|
|
|
void FormatString(BString* buffer, char* fmt, ...);
|
|
|
|
void FormatDateTime(char* target, size_t maxSize,
|
|
|
|
const char* fmt, time_t value);
|
|
|
|
void FormatDateTime(BString* buffer, const char* fmt,
|
|
|
|
time_t value);
|
|
|
|
|
|
|
|
// Country short-hands, TODO: all these should go, once the
|
|
|
|
// Date...Format classes are done
|
|
|
|
void FormatDate(char* target, size_t maxSize,
|
|
|
|
time_t value, bool longFormat);
|
|
|
|
void FormatDate(BString* target, time_t value,
|
|
|
|
bool longFormat);
|
|
|
|
void FormatTime(char* target, size_t maxSize,
|
|
|
|
time_t value, bool longFormat);
|
|
|
|
void FormatTime(BString* target, time_t value,
|
|
|
|
bool longFormat);
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
BCollator fCollator;
|
|
|
|
BCountry fCountry;
|
|
|
|
BLanguage fLanguage;
|
2009-05-01 19:23:59 +00:00
|
|
|
};
|
|
|
|
|
2010-08-01 20:28:19 +00:00
|
|
|
|
2009-05-01 19:23:59 +00:00
|
|
|
// global objects
|
2010-08-01 20:28:19 +00:00
|
|
|
extern BLocale* be_locale;
|
|
|
|
|
2009-05-01 19:23:59 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//--- country short-hands inlines ---
|
2009-05-01 21:56:16 +00:00
|
|
|
inline void
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::FormatDate(char* target, size_t maxSize, time_t timer, bool longFormat)
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
fCountry.FormatDate(target, maxSize, timer, longFormat);
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 21:56:16 +00:00
|
|
|
inline void
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::FormatDate(BString* target, time_t timer, bool longFormat)
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
fCountry.FormatDate(target, timer, longFormat);
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 21:56:16 +00:00
|
|
|
inline void
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::FormatTime(char* target, size_t maxSize, time_t timer, bool longFormat)
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
fCountry.FormatTime(target, maxSize, timer, longFormat);
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 21:56:16 +00:00
|
|
|
inline void
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::FormatTime(BString* target, time_t timer, bool longFormat)
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
fCountry.FormatTime(target, timer, longFormat);
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--- locale short-hands inlines ---
|
|
|
|
// #pragma mark -
|
|
|
|
|
2009-05-01 21:56:16 +00:00
|
|
|
inline int
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::StringCompare(const char* s1, const char* s2) const
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
return fCollator.Compare(s1, s2);
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 21:56:16 +00:00
|
|
|
inline int
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::StringCompare(const BString* s1, const BString* s2) const
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
return fCollator.Compare(s1->String(), s2->String());
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
2010-08-01 20:28:19 +00:00
|
|
|
BLocale::GetSortKey(const char* string, BString* key) const
|
2009-05-01 19:23:59 +00:00
|
|
|
{
|
2010-08-01 20:28:19 +00:00
|
|
|
fCollator.GetSortKey(string, key);
|
2009-05-01 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 20:28:19 +00:00
|
|
|
|
2009-05-01 19:23:59 +00:00
|
|
|
#endif /* _B_LOCALE_H_ */
|