Move DateTimeFormat and NumberFormat out of BLocale
* ... and adjust all callers * Remove NumberFormatImpl: we rely on ICU to provide this and it can be fully wrapped into the C++ file. The class was a stub anyway. * "Monetary" format is included in NumberFormat for now. There may be a more generic solution to handle monetary and BTimeUnitFormat (and other arbitrary units)
This commit is contained in:
@@ -7,16 +7,32 @@
|
||||
|
||||
|
||||
#include <DateTime.h>
|
||||
#include <DateTimeFormat.h>
|
||||
#include <Format.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Language.h>
|
||||
#include <Locker.h>
|
||||
|
||||
|
||||
namespace icu {
|
||||
class DateFormat;
|
||||
}
|
||||
|
||||
|
||||
class BString;
|
||||
class BTimeZone;
|
||||
|
||||
|
||||
enum BDateElement {
|
||||
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
|
||||
};
|
||||
|
||||
enum BWeekday {
|
||||
B_WEEKDAY_MONDAY = 1,
|
||||
B_WEEKDAY_TUESDAY,
|
||||
|
||||
@@ -6,25 +6,15 @@
|
||||
#define _B_DATE_TIME_FORMAT_H_
|
||||
|
||||
|
||||
#include <DateFormat.h>
|
||||
#include <Format.h>
|
||||
#include <FormatParameters.h>
|
||||
#include <TimeFormat.h>
|
||||
|
||||
|
||||
class BString;
|
||||
|
||||
|
||||
enum BDateElement {
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
class BDateTimeFormat : public BFormat {
|
||||
public:
|
||||
BDateTimeFormat();
|
||||
@@ -33,13 +23,20 @@ public:
|
||||
|
||||
// formatting
|
||||
|
||||
// no-frills version: Simply appends the
|
||||
// formatted date to the string buffer.
|
||||
// Can fail only with B_NO_MEMORY or
|
||||
// B_BAD_VALUE.
|
||||
virtual status_t Format(bigtime_t value, BString* buffer) const;
|
||||
ssize_t Format(char* target, const size_t maxSize,
|
||||
const time_t time,
|
||||
BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle) const;
|
||||
status_t Format(BString& buffer, const time_t time,
|
||||
BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
|
||||
// TODO: ... basically, all of it!
|
||||
private:
|
||||
icu::DateFormat* _CreateDateFormatter(
|
||||
const BString& format) const;
|
||||
icu::DateFormat* _CreateTimeFormatter(
|
||||
const BString& format) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012, Haiku, Inc.
|
||||
* Copyright 2003-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_LOCALE_H_
|
||||
@@ -7,29 +7,13 @@
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <DateTimeFormat.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Language.h>
|
||||
#include <Locker.h>
|
||||
|
||||
|
||||
namespace icu {
|
||||
class DateFormat;
|
||||
}
|
||||
|
||||
|
||||
class BCatalog;
|
||||
class BDateFormat;
|
||||
class BString;
|
||||
class BTimeZone;
|
||||
|
||||
|
||||
enum BNumberElement {
|
||||
B_NUMBER_ELEMENT_INVALID = B_BAD_DATA,
|
||||
B_NUMBER_ELEMENT_INTEGER = 0,
|
||||
B_NUMBER_ELEMENT_FRACTIONAL,
|
||||
B_NUMBER_ELEMENT_CURRENCY
|
||||
};
|
||||
|
||||
|
||||
class BLocale {
|
||||
@@ -57,36 +41,6 @@ public:
|
||||
// see definitions in LocaleStrings.h
|
||||
const char* GetString(uint32 id) const;
|
||||
|
||||
// DateTime
|
||||
|
||||
// TODO: drop some of these once BDateTimeFormat
|
||||
// has been implemented!
|
||||
ssize_t FormatDateTime(char* target, size_t maxSize,
|
||||
time_t time, BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle) const;
|
||||
status_t FormatDateTime(BString* buffer, time_t time,
|
||||
BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
|
||||
// numbers
|
||||
|
||||
ssize_t FormatNumber(char* string, size_t maxSize,
|
||||
double value) const;
|
||||
status_t FormatNumber(BString* string,
|
||||
double value) const;
|
||||
ssize_t FormatNumber(char* string, size_t maxSize,
|
||||
int32 value) const;
|
||||
status_t FormatNumber(BString* string,
|
||||
int32 value) const;
|
||||
|
||||
// monetary
|
||||
|
||||
ssize_t FormatMonetary(char* string, size_t maxSize,
|
||||
double value) const;
|
||||
status_t FormatMonetary(BString* string,
|
||||
double value) const;
|
||||
|
||||
// Collator short-hands
|
||||
int StringCompare(const char* s1,
|
||||
const char* s2) const;
|
||||
@@ -97,11 +51,6 @@ public:
|
||||
BString* sortKey) const;
|
||||
|
||||
private:
|
||||
icu::DateFormat* _CreateDateFormatter(
|
||||
const BString& format) const;
|
||||
icu::DateFormat* _CreateTimeFormatter(
|
||||
const BString& format) const;
|
||||
|
||||
mutable BLocker fLock;
|
||||
BCollator fCollator;
|
||||
BFormattingConventions fConventions;
|
||||
|
||||
@@ -1,19 +1,47 @@
|
||||
/*
|
||||
* Copyright 2003-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_NUMBER_FORMAT_H_
|
||||
#define _B_NUMBER_FORMAT_H_
|
||||
|
||||
#include <Format.h>
|
||||
#include <NumberFormatParameters.h>
|
||||
|
||||
class BNumberFormatImpl;
|
||||
#include <Format.h>
|
||||
|
||||
|
||||
enum BNumberElement {
|
||||
B_NUMBER_ELEMENT_INVALID = B_BAD_DATA,
|
||||
B_NUMBER_ELEMENT_INTEGER = 0,
|
||||
B_NUMBER_ELEMENT_FRACTIONAL,
|
||||
B_NUMBER_ELEMENT_CURRENCY
|
||||
};
|
||||
|
||||
|
||||
class BNumberFormat : public BFormat {
|
||||
protected:
|
||||
public:
|
||||
BNumberFormat();
|
||||
BNumberFormat(const BNumberFormat &other);
|
||||
~BNumberFormat();
|
||||
|
||||
BNumberFormat &operator=(const BNumberFormat &other);
|
||||
BNumberFormat& operator=(const BNumberFormat &other);
|
||||
|
||||
BNumberFormat();
|
||||
// formatting
|
||||
|
||||
ssize_t Format(char* string, size_t maxSize,
|
||||
const double value) const;
|
||||
status_t Format(BString& string, const double value)
|
||||
const;
|
||||
ssize_t Format(char* string, size_t maxSize,
|
||||
const int32 value) const;
|
||||
status_t Format(BString& string, const int32 value)
|
||||
const;
|
||||
|
||||
// monetary
|
||||
|
||||
ssize_t FormatMonetary(char* string, size_t maxSize,
|
||||
const double value) const;
|
||||
status_t FormatMonetary(BString& string,
|
||||
const double value) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef _B_NUMBER_FORMAT_IMPL_H_
|
||||
#define _B_NUMBER_FORMAT_IMPL_H_
|
||||
|
||||
#include <FormatImpl.h>
|
||||
|
||||
struct format_field_position;
|
||||
class BNumberFormatParameters;
|
||||
|
||||
class BNumberFormatImpl : public BFormatImpl {
|
||||
public:
|
||||
BNumberFormatImpl();
|
||||
virtual ~BNumberFormatImpl();
|
||||
|
||||
virtual BFormatParameters *DefaultFormatParameters();
|
||||
virtual const BFormatParameters *DefaultFormatParameters() const;
|
||||
|
||||
virtual BNumberFormatParameters *DefaultNumberFormatParameters() = 0;
|
||||
virtual const BNumberFormatParameters *DefaultNumberFormatParameters()
|
||||
const = 0;
|
||||
};
|
||||
|
||||
#endif // _B_NUMBER_FORMAT_IMPL_H_
|
||||
Reference in New Issue
Block a user