2 * Copyright 2014-2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Adrien Destugues, pulkomandy@pulkomandy.tk
7 * John Scipione, jscipione@gmail.com
10 #include <unicode/uversion.h>
11 #include <MessageFormat.h>
14 #include <FormattingConventionsPrivate.h>
15 #include <LanguagePrivate.h>
17 #include <ICUWrapper.h>
19 #include <unicode/msgfmt.h>
22 BMessageFormat::BMessageFormat(const BLanguage
& language
, const BString pattern
)
23 : BFormat(language
, BFormattingConventions())
25 _Initialize(UnicodeString::fromUTF8(pattern
.String()));
29 BMessageFormat::BMessageFormat(const BString pattern
)
32 _Initialize(UnicodeString::fromUTF8(pattern
.String()));
36 BMessageFormat::~BMessageFormat()
43 BMessageFormat::InitCheck()
50 BMessageFormat::Format(BString
& output
, const int64 arg
) const
52 if (fInitStatus
!= B_OK
)
56 UErrorCode error
= U_ZERO_ERROR
;
58 Formattable arguments
[] = {
63 buffer
= fFormatter
->format(arguments
, 1, buffer
, pos
, error
);
64 if (!U_SUCCESS(error
))
67 BStringByteSink
byteSink(&output
);
68 buffer
.toUTF8(byteSink
);
75 BMessageFormat::_Initialize(const UnicodeString
& pattern
)
78 UErrorCode error
= U_ZERO_ERROR
;
80 = BLanguage::Private(&fLanguage
).ICULocale();
82 fFormatter
= new MessageFormat(pattern
, *icuLocale
, error
);
84 if (fFormatter
== NULL
)
85 fInitStatus
= B_NO_MEMORY
;
87 if (!U_SUCCESS(error
)) {
89 fInitStatus
= B_ERROR
;