* reintroduced be_locale as global information point for the current locale

values
* added locking to BLocale (needed since the data of the global object may
  change any time)
* BLocale no longer passes out pointers to internal objects, it fill objects
  passed in by the client instead (just like be_locale_roster does)
* dropped default language as member from RosterData, it is no part of the
  default locale
* fleshed out implementation of TimeUnitFormat and DurationFormat, both
  of which can now be given a BLocale in order to set the strings being used
  during formatting


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38428 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-08-29 20:55:00 +00:00
parent 279125fbd9
commit a9faf94392
11 changed files with 374 additions and 51 deletions
+28 -3
View File
@@ -6,18 +6,43 @@
#define _B_DURATION_FORMAT_H_
#include <DateTimeFormat.h>
#include <Format.h>
#include <String.h>
#include <TimeUnitFormat.h>
class BTimeZone;
namespace icu_44 {
class GregorianCalendar;
}
class BDurationFormat : public BFormat {
typedef BFormat Inherited;
public:
BDurationFormat(
const BString& separator = ", ");
BDurationFormat(const BDurationFormat& other);
virtual ~BDurationFormat();
BDurationFormat& operator=(const BDurationFormat& other);
void SetSeparator(const BString& separator);
virtual status_t SetLocale(const BLocale* locale);
status_t SetTimeZone(const BTimeZone* timeZone);
status_t Format(bigtime_t startValue,
bigtime_t stopValue, BString* buffer,
time_unit_style style = B_TIME_UNIT_FULL,
const BString& separator = ", "
time_unit_style style = B_TIME_UNIT_FULL
) const;
private:
BString fSeparator;
BTimeUnitFormat fTimeUnitFormat;
icu_44::GregorianCalendar* fCalendar;
};
+8 -2
View File
@@ -36,16 +36,22 @@ struct format_field_position {
};
class BFormatImpl;
class BLocale;
class BFormat {
public:
status_t InitCheck() const;
virtual status_t SetLocale(const BLocale* locale);
protected:
BFormat();
BFormat(const BFormat& other);
virtual ~BFormat();
BFormat& operator=(const BFormat& other);
BFormat();
status_t fInitStatus;
BLocale* fLocale;
};
+11 -4
View File
@@ -9,6 +9,7 @@
#include <Collator.h>
#include <Country.h>
#include <Language.h>
#include <Locker.h>
class BCatalog;
@@ -40,12 +41,13 @@ public:
BLocale(const char* languageAndCountryCode
= "en_US");
BLocale(const BLocale& other);
BLocale& operator=(const BLocale& other);
~BLocale();
const BCollator* Collator() const { return &fCollator; }
const BCountry* Country() const { return &fCountry; }
const BLanguage* Language() const { return &fLanguage; }
BLocale& operator=(const BLocale& other);
status_t GetCollator(BCollator* collator) const;
status_t GetLanguage(BLanguage* language) const;
status_t GetCountry(BCountry* country) const;
const char* Code() const;
bool GetName(BString& name) const;
@@ -135,6 +137,7 @@ public:
BString* key) const;
protected:
mutable BLocker fLock;
BCollator fCollator;
BCountry fCountry;
BLanguage fLanguage;
@@ -147,6 +150,10 @@ protected:
};
// global locale object
extern const BLocale* be_locale;
//--- collator short-hands inlines ---
// #pragma mark -
+17 -1
View File
@@ -6,12 +6,16 @@
#define _B_TIME_UNIT_FORMAT_H_
#include <DateTimeFormat.h>
#include <Format.h>
#include <SupportDefs.h>
class BString;
namespace icu_44 {
class TimeUnitFormat;
}
enum time_unit_style {
B_TIME_UNIT_ABBREVIATED, // e.g. '5 hrs.'
@@ -33,11 +37,23 @@ enum time_unit_element {
class BTimeUnitFormat : public BFormat {
typedef BFormat Inherited;
public:
BTimeUnitFormat();
BTimeUnitFormat(const BTimeUnitFormat& other);
virtual ~BTimeUnitFormat();
BTimeUnitFormat& operator=(const BTimeUnitFormat& other);
virtual status_t SetLocale(const BLocale* locale);
status_t Format(int32 value, time_unit_element unit,
BString* buffer,
time_unit_style style = B_TIME_UNIT_FULL
) const;
private:
icu_44::TimeUnitFormat* fFormatter;
};
@@ -109,7 +109,6 @@ struct RosterData {
BMessage fPreferredLanguages;
BLocale fDefaultLocale;
BLanguage fDefaultLanguage;
BTimeZone fDefaultTimeZone;
RosterData();