BMessageFormat: Rename to BStringFormat.

The ICU class is named MessageFormat, but on Haiku, it sounds too much
like something related to BMessage (which it isn't in the slightest)
and not part of the Locale system. It works almost entirely with BStrings,
so naming it BStringFormat makes much more sense.

OK'ed by PulkoMandy and Humdinger.
This commit is contained in:
Augustin Cavalier 2018-08-13 20:49:00 -04:00
parent 8906767241
commit 7457ccb4b2
30 changed files with 89 additions and 89 deletions

View File

@ -6,8 +6,8 @@
* Adrien Destugues, pulkomandy@pulkomandy.tk
* John Scipione, jscipione@gmail.com
*/
#ifndef _B_MESSAGE_FORMAT_H_
#define _B_MESSAGE_FORMAT_H_
#ifndef _B_STRING_FORMAT_H_
#define _B_STRING_FORMAT_H_
#include <Format.h>
@ -22,12 +22,12 @@ namespace U_ICU_NAMESPACE {
}
class BMessageFormat: public BFormat {
class BStringFormat : public BFormat {
public:
BMessageFormat(const BLanguage& language,
BStringFormat(const BLanguage& language,
const BString pattern);
BMessageFormat(const BString pattern);
~BMessageFormat();
BStringFormat(const BString pattern);
~BStringFormat();
status_t InitCheck();
@ -41,4 +41,4 @@ private:
};
#endif // _B_MESSAGE_FORMAT_H_
#endif // _B_STRING_FORMAT_H_

View File

@ -15,9 +15,9 @@
#include <Beep.h>
#include <Catalog.h>
#include <Message.h>
#include <MessageFormat.h>
#include <Path.h>
#include <String.h>
#include <StringFormat.h>
#include <MailFilter.h>
@ -77,7 +77,7 @@ NotifyFilter::MailboxSynchronized(status_t status)
system_beep("New E-mail");
if ((fStrategy & NOTIFY_ALERT) != 0) {
BMessageFormat format(B_TRANSLATE(
BStringFormat format(B_TRANSLATE(
"You have {0, plural, one{One new message} other{# new messages}} "
"for %account."));
@ -107,7 +107,7 @@ NotifyFilter::MailboxSynchronized(status_t status)
}
if ((fStrategy & NOTIFY_NOTIFICATION) != 0) {
BMessageFormat format(B_TRANSLATE("{0, plural, "
BStringFormat format(B_TRANSLATE("{0, plural, "
"one{One new message} other{# new messages}}"));
BString message;

View File

@ -10,8 +10,8 @@
#include "ZipOMatic.h"
#include <Alert.h>
#include <MessageFormat.h>
#include <Roster.h>
#include <StringFormat.h>
#include <TrackerAddOnAppLaunch.h>
#include "ZipOMaticMisc.h"
@ -154,7 +154,7 @@ ZipOMatic::QuitRequested(void)
// The multi-zipper case differs from the single-zipper case
// in that zippers are not paused while the BAlert is up.
static BMessageFormat format(
static BStringFormat format(
B_TRANSLATE("You have {0, plural, one{# Zip-O-Matic} "
"other{# Zip-O-Matics}} running.\n\n"));

View File

@ -21,12 +21,12 @@
#include <GroupLayout.h>
#include <LayoutBuilder.h>
#include <Locale.h>
#include <MessageFormat.h>
#include <Path.h>
#include <Roster.h>
#include <Screen.h>
#include <SeparatorView.h>
#include <String.h>
#include <StringFormat.h>
#include "ZipOMatic.h"
#include "ZipOMaticActivity.h"
@ -152,7 +152,7 @@ ZippoWindow::MessageReceived(BMessage* message)
// being created (added to) or if we're updating an
// already existing archive.
static BMessageFormat format(B_TRANSLATE("{0, plural, "
static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{# file added.} other{# files added.}}"));
BString output;
format.Format(output, fFileCount);

View File

@ -29,7 +29,6 @@
#include <Font.h>
#include <fs_attr.h>
#include <LayoutBuilder.h>
#include <MessageFormat.h>
#include <MessageRunner.h>
#include <Messenger.h>
#include <ObjectList.h>
@ -40,6 +39,7 @@
#include <Screen.h>
#include <ScrollView.h>
#include <String.h>
#include <StringFormat.h>
#include <StringList.h>
#include <StringView.h>
#include <TranslationUtils.h>
@ -471,7 +471,7 @@ AboutView::AboutView()
B_ALIGN_VERTICAL_UNSET));
// CPU count, type and clock speed
static BMessageFormat format(B_TRANSLATE_COMMENT(
static BStringFormat format(B_TRANSLATE_COMMENT(
"{0, plural, one{Processor:} other{# Processors:}}",
"\"Processor:\" or \"2 Processors:\""));

View File

@ -17,7 +17,7 @@
#include <vector>
#include <Catalog.h>
#include <MessageFormat.h>
#include <StringFormat.h>
#include <StringForSize.h>
#include <StringView.h>
#include <Bitmap.h>
@ -81,7 +81,7 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
BString name;
if (f->count > 0) {
// This is a directory, include file count information
static BMessageFormat format(B_TRANSLATE(
static BStringFormat format(B_TRANSLATE(
"%size% in {0, plural, one{# file} other{# files}}"));
format.Format(name, f->count);

View File

@ -17,9 +17,9 @@
#include <Catalog.h>
#include <Box.h>
#include <Button.h>
#include <MessageFormat.h>
#include <Node.h>
#include <String.h>
#include <StringFormat.h>
#include <StringForSize.h>
#include <StringView.h>
@ -152,7 +152,7 @@ StatusView::ShowInfo(const FileInfo* info)
fSizeView->SetText(label);
if (info->count > 0) {
static BMessageFormat format(B_TRANSLATE("{0, plural, "
static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{# file} other{# files}}"));
BString label;
format.Format(label, info->count);

View File

@ -11,13 +11,13 @@
#include <Autolock.h>
#include <Catalog.h>
#include <FindDirectory.h>
#include <MessageFormat.h>
#include <LayoutBuilder.h>
#include <LayoutUtils.h>
#include <OutlineListView.h>
#include <Path.h>
#include <ScrollBar.h>
#include <ScrollView.h>
#include <StringFormat.h>
#include <StringItem.h>
#include <package/PackageDefs.h>

View File

@ -14,8 +14,8 @@
#include <Autolock.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <MessageFormat.h>
#include <ScrollBar.h>
#include <StringFormat.h>
#include <StringForSize.h>
#include <package/hpkg/Strings.h>
#include <Window.h>
@ -716,7 +716,7 @@ public:
private:
BString _GetLabel() const
{
static BMessageFormat format(B_TRANSLATE("{0, plural, "
static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{# item} other{# items}}"));
BString label;

View File

@ -22,13 +22,13 @@
#include <Locale.h>
#include <MenuItem.h>
#include <MenuField.h>
#include <MessageFormat.h>
#include <NodeInfo.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <PropertyInfo.h>
#include <Screen.h>
#include <ScrollView.h>
#include <StringFormat.h>
#include <TextView.h>
#include <TranslationUtils.h>
#include <TranslatorRoster.h>
@ -1062,7 +1062,7 @@ TInfoView::Draw(BRect updateRect)
MovePenTo(15 + fPopUp->Bounds().Width(), fFontHeight + 5);
static BMessageFormat format(B_TRANSLATE("%width x %height @ {0, plural, "
static BStringFormat format(B_TRANSLATE("%width x %height @ {0, plural, "
"one{# pixel/pixel} other{# pixels/pixel}}"));
BString dimensionsInfo;

View File

@ -15,10 +15,10 @@
#include <Locale.h>
#include <MediaFile.h>
#include <MediaTrack.h>
#include <MessageFormat.h>
#include <Mime.h>
#include <Path.h>
#include <String.h>
#include <StringFormat.h>
#include <View.h>
#include "MediaConverterWindow.h"
@ -131,7 +131,7 @@ MediaConverterApp::RefsReceived(BMessage* msg)
if (errors) {
BString alertText;
static BMessageFormat format(B_TRANSLATE("{0, plural, "
static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{The file was not recognized as a supported media file:} "
"other{# files were not recognized as supported media files:}}"));
format.Format(alertText, errors);

View File

@ -9,7 +9,7 @@
#include <Catalog.h>
#include <MediaTrack.h>
#include <MessageFormat.h>
#include <StringFormat.h>
#include <stdio.h>
#undef B_TRANSLATION_CONTEXT
@ -53,7 +53,7 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
if (ret != B_OK)
return ret;
static BMessageFormat frameFormat(B_TRANSLATE(
static BStringFormat frameFormat(B_TRANSLATE(
"{0, plural, one{# frame} other{# frames}}"));
if (format.IsVideo()) {
@ -97,12 +97,12 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
BString details;
if (bytesPerSample == 1 || bytesPerSample == 2) {
static BMessageFormat bitFormat(
static BStringFormat bitFormat(
B_TRANSLATE("{0, plural, one{# bit} other{# bits}}"));
bitFormat.Format(details, bytesPerSample * 8);
details.SetToFormat(B_TRANSLATE("%d bit "), bytesPerSample * 8);
} else {
static BMessageFormat bitFormat(
static BStringFormat bitFormat(
B_TRANSLATE("{0, plural, one{# byte} other{# bytes}}"));
bitFormat.Format(details, bytesPerSample);
}

View File

@ -20,11 +20,11 @@
#include <Debug.h>
#include <LayoutBuilder.h>
#include <MediaDefs.h>
#include <MessageFormat.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <Screen.h>
#include <String.h>
#include <StringFormat.h>
#include <StringForRate.h>
#include <StringView.h>
#include <TextView.h>
@ -486,7 +486,7 @@ InfoWin::_UpdateAudio()
info << bitString << " ";
}
static BMessageFormat channelFormat(B_TRANSLATE(
static BStringFormat channelFormat(B_TRANSLATE(
"{0, plural, =1{Mono} =2{Stereo} other{# Channels}}"));
channelFormat.Format(info, channelCount);

View File

@ -22,9 +22,9 @@
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <MessageFormat.h>
#include <MessageRunner.h>
#include <String.h>
#include <StringFormat.h>
#include <TextView.h>
#include "Pairs.h"
@ -305,7 +305,7 @@ PairsWindow::MessageReceived(BMessage* message)
// Note: in english the singular form is never used, but other
// languages behave differently.
static BMessageFormat format(B_TRANSLATE(
static BStringFormat format(B_TRANSLATE(
"You completed the game in "
"{0, plural, one{# click} other{# clicks}}.\n"));
format.Format(strAbout, fButtonClicks);

View File

@ -4,11 +4,11 @@
* Started: 5/14/2004
* Version: 0.1
*/
#include "StatusSlider.h"
#include <MessageFormat.h>
#include <StringFormat.h>
StatusSlider::StatusSlider(const char* name, const char* label,

View File

@ -4,15 +4,15 @@
* Started: 5/14/2004
* Version: 0.1
*/
#ifndef STATUS_SLIDER
#define STATUS_SLIDER
//#define BEOS_R5_COMPATIBLE
#include <MessageFormat.h>
#include <Slider.h>
#include <String.h>
#include <StringFormat.h>
class StatusSlider: public BSlider {
@ -28,7 +28,7 @@ public:
private:
mutable char fPattern[256];
BMessageFormat fFormat;
BStringFormat fFormat;
mutable BString fStr;
};

View File

@ -28,8 +28,8 @@ local sources =
DateFormat.cpp
DateTimeFormat.cpp
DurationFormat.cpp
MessageFormat.cpp
NumberFormat.cpp
StringFormat.cpp
TimeFormat.cpp
TimeUnitFormat.cpp
Format.cpp # Used by some of the above.

View File

@ -8,7 +8,7 @@
*/
#include <unicode/uversion.h>
#include <MessageFormat.h>
#include <StringFormat.h>
#include <Autolock.h>
#include <FormattingConventionsPrivate.h>
@ -19,35 +19,35 @@
#include <unicode/msgfmt.h>
BMessageFormat::BMessageFormat(const BLanguage& language, const BString pattern)
BStringFormat::BStringFormat(const BLanguage& language, const BString pattern)
: BFormat(language, BFormattingConventions())
{
_Initialize(UnicodeString::fromUTF8(pattern.String()));
}
BMessageFormat::BMessageFormat(const BString pattern)
BStringFormat::BStringFormat(const BString pattern)
: BFormat()
{
_Initialize(UnicodeString::fromUTF8(pattern.String()));
}
BMessageFormat::~BMessageFormat()
BStringFormat::~BStringFormat()
{
delete fFormatter;
}
status_t
BMessageFormat::InitCheck()
BStringFormat::InitCheck()
{
return fInitStatus;
}
status_t
BMessageFormat::Format(BString& output, const int64 arg) const
BStringFormat::Format(BString& output, const int64 arg) const
{
if (fInitStatus != B_OK)
return fInitStatus;
@ -72,7 +72,7 @@ BMessageFormat::Format(BString& output, const int64 arg) const
status_t
BMessageFormat::_Initialize(const UnicodeString& pattern)
BStringFormat::_Initialize(const UnicodeString& pattern)
{
fInitStatus = B_OK;
UErrorCode error = U_ZERO_ERROR;

View File

@ -7,7 +7,7 @@
#include <stdio.h>
#include <MessageFormat.h>
#include <StringFormat.h>
#include <SystemCatalog.h>
using BPrivate::gSystemCatalog;
@ -29,7 +29,7 @@ string_for_size(double size, char* string, size_t stringSize)
"{0, plural, one{# byte} other{# bytes}}");
BString tmp;
BMessageFormat format(
BStringFormat format(
gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT));
format.Format(tmp, (int)size);

View File

@ -41,7 +41,7 @@ All rights reserved.
#include <Catalog.h>
#include <ControlLook.h>
#include <Locale.h>
#include <MessageFormat.h>
#include <StringFormat.h>
#include "AutoLock.h"
#include "Bitmaps.h"
@ -217,7 +217,7 @@ BCountView::Draw(BRect updateRect)
if (fLastCount == 0)
itemString << B_TRANSLATE("no items");
else {
static BMessageFormat format(B_TRANSLATE_COMMENT(
static BStringFormat format(B_TRANSLATE_COMMENT(
"{0, plural, one{# item} other{# items}}",
"Number of selected items: \"1 item\" or \"2 items\""));
format.Format(itemString, fLastCount);

View File

@ -58,12 +58,12 @@ respective holders. All rights reserved.
#include <Entry.h>
#include <FindDirectory.h>
#include <Locale.h>
#include <MessageFormat.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Roster.h>
#include <Screen.h>
#include <String.h>
#include <StringFormat.h>
#include <SymLink.h>
#include <Volume.h>
#include <VolumeRoster.h>
@ -2092,7 +2092,7 @@ FileStatToString(StatStruct* stat, char* buffer, int32 length)
localtime_r(&stat->st_mtime, &timeData);
BString size;
static BMessageFormat format(
static BStringFormat format(
B_TRANSLATE("{0, plural, one{# byte} other{# bytes}}"));
format.Format(size, stat->st_size);
uint32 pos = snprintf(buffer, length, "\n\t(%s ", size.String());

View File

@ -47,7 +47,6 @@ All rights reserved.
#include <Font.h>
#include <Locale.h>
#include <MenuField.h>
#include <MessageFormat.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <NodeMonitor.h>
@ -57,6 +56,7 @@ All rights reserved.
#include <Roster.h>
#include <Screen.h>
#include <ScrollView.h>
#include <StringFormat.h>
#include <SymLink.h>
#include <TextView.h>
#include <Volume.h>
@ -674,9 +674,9 @@ BInfoWindow::MessageReceived(BMessage* message)
void
BInfoWindow::GetSizeString(BString& result, off_t size, int32 fileCount)
{
static BMessageFormat sizeFormat(B_TRANSLATE(
static BStringFormat sizeFormat(B_TRANSLATE(
"{0, plural, one{(# byte)} other{(# bytes)}}"));
static BMessageFormat countFormat(B_TRANSLATE(
static BStringFormat countFormat(B_TRANSLATE(
"{0, plural, one{for # file} other{for # files}}"));
char sizeBuffer[128];

View File

@ -49,9 +49,9 @@ All rights reserved.
#include <DateTimeFormat.h>
#include <Debug.h>
#include <Locale.h>
#include <MessageFormat.h>
#include <NodeInfo.h>
#include <Path.h>
#include <StringFormat.h>
#include <SupportDefs.h>
#include <TextView.h>
#include <Volume.h>
@ -107,7 +107,7 @@ TruncFileSizeBase(BString* outString, int64 value, const View* view,
*outString = "-";
return view->StringWidth("-");
} else if (value < kKBSize) {
static BMessageFormat format(B_TRANSLATE(
static BStringFormat format(B_TRANSLATE(
"{0, plural, one{# byte} other{# bytes}}"));
format.Format(buffer, value);
if (view->StringWidth(buffer.String()) > width)

View File

@ -21,7 +21,6 @@
#include <Locale.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <MessageFormat.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <Path.h>
@ -31,6 +30,7 @@
#include <Screen.h>
#include <ScrollView.h>
#include <StatusBar.h>
#include <StringFormat.h>
#include <StringView.h>
#include <TextView.h>
#include <Volume.h>
@ -346,7 +346,7 @@ ApplicationTypesWindow::_RemoveUninstalled()
progressWindow->PostMessage(B_QUIT_REQUESTED);
static BMessageFormat format(B_TRANSLATE("{0, plural, "
static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{# Application type could be removed} "
"other{# Application types could be removed}}"));
BString message;

View File

@ -24,7 +24,6 @@
#include <kernel/fs_info.h>
#include <kernel/fs_index.h>
#include <MenuItem.h>
#include <MessageFormat.h>
#include <Messenger.h>
#include <NodeInfo.h>
#include <NodeMonitor.h>
@ -36,6 +35,7 @@
#include <Resources.h>
#include <Roster.h>
#include <String.h>
#include <StringFormat.h>
#include <SymLink.h>
#include <VolumeRoster.h>
#include <Window.h>
@ -546,7 +546,7 @@ DeskbarView::_BuildMenu()
// The New E-mail query
if (fNewMessages > 0) {
static BMessageFormat format(B_TRANSLATE(
static BStringFormat format(B_TRANSLATE(
"{0, plural, one{# new message} other{# new messages}}"));
BString string;
format.Format(string, fNewMessages);

View File

@ -20,12 +20,12 @@
#include <FindDirectory.h>
#include <fs_index.h>
#include <IconUtils.h>
#include <MessageFormat.h>
#include <NodeMonitor.h>
#include <Notification.h>
#include <Path.h>
#include <Roster.h>
#include <StringList.h>
#include <StringFormat.h>
#include <VolumeRoster.h>
#include <E-mail.h>
@ -350,7 +350,7 @@ MailDaemonApplication::MessageReceived(BMessage* msg)
case 'numg':
{
static BMessageFormat format(B_TRANSLATE("{0, plural, "
static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{# new message} other{# new messages}} for %name\n"));
int32 numMessages = msg->FindInt32("num_messages");
@ -797,7 +797,7 @@ MailDaemonApplication::_UpdateNewMessagesNotification()
{
BString title;
if (fNewMessages > 0) {
BMessageFormat format(B_TRANSLATE(
BStringFormat format(B_TRANSLATE(
"{0, plural, one{One new message} other{# new messages}}"));
format.Format(title, fNewMessages);

View File

@ -50,8 +50,8 @@ UnitTestLib localekittest.so :
DateFormatTest.cpp
DurationFormatTest.cpp
LanguageTest.cpp
MessageFormatTest.cpp
RelativeDateTimeFormatTest.cpp
StringFormatTest.cpp
UnicodeCharTest.cpp
: be [ TargetLibstdc++ ]

View File

@ -11,8 +11,8 @@
#include "DateFormatTest.h"
#include "DurationFormatTest.h"
#include "LanguageTest.h"
#include "MessageFormatTest.h"
#include "RelativeDateTimeFormatTest.h"
#include "StringFormatTest.h"
#include "UnicodeCharTest.h"
@ -25,7 +25,7 @@ getTestSuite()
DateFormatTest::AddTests(*suite);
DurationFormatTest::AddTests(*suite);
LanguageTest::AddTests(*suite);
MessageFormatTest::AddTests(*suite);
StringFormatTest::AddTests(*suite);
RelativeDateTimeFormatTest::AddTests(*suite);
UnicodeCharTest::AddTests(*suite);

View File

@ -4,27 +4,27 @@
*/
#include "MessageFormatTest.h"
#include "StringFormatTest.h"
#include <Locale.h>
#include <MessageFormat.h>
#include <StringFormat.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
MessageFormatTest::MessageFormatTest()
StringFormatTest::StringFormatTest()
{
}
MessageFormatTest::~MessageFormatTest()
StringFormatTest::~StringFormatTest()
{
}
void
MessageFormatTest::TestFormat()
StringFormatTest::TestFormat()
{
BString output;
@ -82,7 +82,7 @@ MessageFormatTest::TestFormat()
NextSubTest();
output.Truncate(0);
BLanguage language(tests[i].locale);
BMessageFormat formatter(language, tests[i].pattern);
BStringFormat formatter(language, tests[i].pattern);
result = formatter.Format(output, tests[i].number);
CPPUNIT_ASSERT_EQUAL(B_OK, result);
@ -92,7 +92,7 @@ MessageFormatTest::TestFormat()
void
MessageFormatTest::TestBogus()
StringFormatTest::TestBogus()
{
struct Test {
const char* pattern;
@ -113,7 +113,7 @@ MessageFormatTest::TestBogus()
status_t result;
BString output;
BMessageFormat formatter(tests[i].pattern);
BStringFormat formatter(tests[i].pattern);
CPPUNIT_ASSERT(formatter.InitCheck() != B_OK);
result = formatter.Format(output, 1);
@ -126,14 +126,14 @@ MessageFormatTest::TestBogus()
/*static*/ void
MessageFormatTest::AddTests(BTestSuite& parent)
StringFormatTest::AddTests(BTestSuite& parent)
{
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("MessageFormatTest");
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("StringFormatTest");
suite.addTest(new CppUnit::TestCaller<MessageFormatTest>(
"MessageFormatTest::TestFormat", &MessageFormatTest::TestFormat));
suite.addTest(new CppUnit::TestCaller<MessageFormatTest>(
"MessageFormatTest::TestBogus", &MessageFormatTest::TestBogus));
suite.addTest(new CppUnit::TestCaller<StringFormatTest>(
"StringFormatTest::TestFormat", &StringFormatTest::TestFormat));
suite.addTest(new CppUnit::TestCaller<StringFormatTest>(
"StringFormatTest::TestBogus", &StringFormatTest::TestBogus));
parent.addTest("MessageFormatTest", &suite);
parent.addTest("StringFormatTest", &suite);
}

View File

@ -2,18 +2,18 @@
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef MESSAGE_FORMAT_TEST_H
#define MESSAGE_FORMAT_TEST_H
#ifndef STRING_FORMAT_TEST
#define STRING_FORMAT_TEST
#include <TestCase.h>
#include <TestSuite.h>
class MessageFormatTest: public BTestCase {
class StringFormatTest: public BTestCase {
public:
MessageFormatTest();
virtual ~MessageFormatTest();
StringFormatTest();
virtual ~StringFormatTest();
void TestFormat();
void TestBogus();