haiku/headers/os/locale/MessageFormat.h
Adrien Destugues 961fdd8cc3 BMessageFormat: parse the pattern at construction
* Instead of parsing the pattern everytime Format() is called, parse it
only once when the object is created.
* Adjust all callers to make use of the feature and reuse the instance
as much as possible. This also allows calling B_TRANSLATE only once
instead of everytime the formatting needs to be done. We use either a
static instance (when the message pattern is constant) or a field (when
it is not known to be constant).
* Since the BMessageFormat instances are now reused, add locking to
avoid race conditions (ICU itself is thread safe, but the format pattern
is recreated when the locale is changed)
2014-10-08 15:12:48 +02:00

42 lines
756 B
C++

/*
* Copyright 2014, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_MESSAGE_FORMAT_H_
#define _B_MESSAGE_FORMAT_H_
#include <Format.h>
namespace icu {
class MessageFormat;
class UnicodeString;
}
class BMessageFormat: public BFormat {
public:
BMessageFormat(const BString pattern);
~BMessageFormat();
status_t InitCheck();
status_t SetLanguage(const BLanguage& newLanguage);
status_t SetFormattingConventions(
const BFormattingConventions&
conventions);
status_t Format(BString& buffer, const int32 arg) const;
private:
status_t _Initialize(const icu::UnicodeString&);
private:
status_t fInitStatus;
icu::MessageFormat* fFormatter;
};
#endif