44f11d0982
* Move relevant parts up into BFormat so other format classes can use those * Adjust BDurationFormat and BTimeUnitFormat for the changes * Remove the "default" date format, it is better to keep only a default locale and let applications create B*Formats from it as needed. * Creating a B*Format without arguments to the constructor now configures it for the default locale, which allows for easy use in standard cases (formatting something with the current language and format) * Creating a B*Format is potentially an expansive operation, it is advised to keep the instance around and reuse it whenever possible. However it must be "refreshed" when the locale changes, for apps which supports that, since it keeps a copy of the language and formatting convention, rather than a pointer to the locale as it did before.
69 lines
1.3 KiB
C++
69 lines
1.3 KiB
C++
/*
|
|
* Copyright 2003-2010, Haiku, Inc.
|
|
* Distributed under the terms of the MIT Licence.
|
|
*/
|
|
#ifndef _B_FORMAT_H_
|
|
#define _B_FORMAT_H_
|
|
|
|
#include <FormatParameters.h>
|
|
#include <FormattingConventions.h>
|
|
#include <Locker.h>
|
|
#include <Language.h>
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
// types of fields contained in formatted strings
|
|
enum {
|
|
// number format fields
|
|
B_CURRENCY_FIELD,
|
|
B_DECIMAL_SEPARATOR_FIELD,
|
|
B_EXPONENT_FIELD,
|
|
B_EXPONENT_SIGN_FIELD,
|
|
B_EXPONENT_SYMBOL_FIELD,
|
|
B_FRACTION_FIELD,
|
|
B_GROUPING_SEPARATOR_FIELD,
|
|
B_INTEGER_FIELD,
|
|
B_PERCENT_FIELD,
|
|
B_PERMILLE_FIELD,
|
|
B_SIGN_FIELD,
|
|
|
|
// date format fields
|
|
// TODO: ...
|
|
};
|
|
|
|
// structure filled in while formatting
|
|
struct format_field_position {
|
|
uint32 field_type;
|
|
int32 start;
|
|
int32 length;
|
|
};
|
|
|
|
|
|
class BLocale;
|
|
|
|
class BFormat {
|
|
public:
|
|
status_t SetLocale(const BLocale& locale);
|
|
virtual status_t SetLanguage(const BLanguage& newLanguage);
|
|
virtual status_t SetFormattingConventions(
|
|
const BFormattingConventions&
|
|
conventions);
|
|
|
|
status_t InitCheck() const;
|
|
protected:
|
|
BFormat();
|
|
BFormat(const BFormat& other);
|
|
virtual ~BFormat();
|
|
|
|
BFormat& operator=(const BFormat& other);
|
|
|
|
protected:
|
|
mutable BLocker fLock;
|
|
BFormattingConventions fConventions;
|
|
BLanguage fLanguage;
|
|
status_t fInitStatus;
|
|
};
|
|
|
|
|
|
#endif // _B_FORMAT_H_
|