本文整理汇总了C++中BString::SetToFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::SetToFormat方法的具体用法?C++ BString::SetToFormat怎么用?C++ BString::SetToFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::SetToFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: url
void
CookieTest::MaxNumberTest()
{
BNetworkCookieJar jar;
status_t result;
BUrl url("http://testsuites.opera.com/cookies/007.php");
BString cookieString;
for (int i = 1; i <= 20; i++)
{
cookieString.SetToFormat("007-%d=1", i);
result = jar.AddCookie(cookieString, url);
CPPUNIT_ASSERT(result == B_OK);
}
url.SetUrlString("http://testsuites.opera.com/cookies/007-1.php");
for (int i = 1; i <= 20; i++)
{
cookieString.SetToFormat("007-%d", i);
const BNetworkCookie* cookie = _GetCookie(jar, url, cookieString.String());
CPPUNIT_ASSERT(cookie != NULL);
CPPUNIT_ASSERT(cookie->Value() == "1");
}
}
示例2: semaphores
status_t
DebugReportGenerator::_DumpSemaphores(BFile& _output)
{
BObjectList<SemaphoreInfo> semaphores(20, true);
status_t error = fDebuggerInterface->GetSemaphoreInfos(semaphores);
if (error != B_OK)
return error;
semaphores.SortItems(&_CompareSemaphores);
BString data = "\nSemaphores:\n";
WRITE_AND_CHECK(_output, data);
data.SetToFormat("\tID\t\tCount\tLast Holder\tName\n\t");
WRITE_AND_CHECK(_output, data);
data.Truncate(0L);
data.Append('-', 60);
data.Append("\n");
WRITE_AND_CHECK(_output, data);
SemaphoreInfo* info;
for (int32 i = 0; (info = semaphores.ItemAt(i)) != NULL; i++) {
try {
data.SetToFormat("\t%" B_PRId32 "\t%5" B_PRId32 "\t%11" B_PRId32
"\t%s\n", info->SemID(), info->Count(),
info->LatestHolder(), info->Name().String());
WRITE_AND_CHECK(_output, data);
} catch (...) {
return B_NO_MEMORY;
}
}
return B_OK;
}
示例3: BStringView
bool
ResultWindow::_AddPackages(BGroupLayout* packagesGroup,
const PackageList& packages, const PackageSet& ignorePackages, bool install)
{
bool packagesAdded = false;
for (int32 i = 0; BSolverPackage* package = packages.ItemAt(i);
i++) {
if (ignorePackages.find(package) != ignorePackages.end())
continue;
BString text;
if (install) {
text.SetToFormat("install package %s from repository %s\n",
package->Info().FileName().String(),
package->Repository()->Name().String());
} else {
text.SetToFormat("uninstall package %s\n",
package->VersionedName().String());
}
BStringView* packageView = new BStringView(NULL, text);
packagesGroup->AddView(packageView);
packageView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
packagesAdded = true;
}
return packagesAdded;
}
示例4: _GetBreakpointValueAt
bool _GetBreakpointValueAt(UserBreakpoint* breakpoint, int32 rowIndex,
int32 columnIndex, BVariant &value)
{
const UserBreakpointLocation& location = breakpoint->Location();
switch (columnIndex) {
case 0:
value.SetTo((int32)breakpoint->IsEnabled());
return true;
case 1:
value.SetTo(location.GetFunctionID()->FunctionName(),
B_VARIANT_DONT_COPY_DATA);
return true;
case 2:
{
LocatableFile* sourceFile = location.SourceFile();
BString data;
if (sourceFile != NULL) {
data.SetToFormat("%s:%" B_PRId32, sourceFile->Name(),
location.GetSourceLocation().Line() + 1);
} else {
AutoLocker<Team> teamLocker(fTeam);
if (UserBreakpointInstance* instance
= breakpoint->InstanceAt(0)) {
data.SetToFormat("%#" B_PRIx64, instance->Address());
}
}
value.SetTo(data);
return true;
}
default:
return false;
}
}
示例5: BAlert
void
DataTranslationsWindow::_ShowInfoAlert(int32 id)
{
const char* name = NULL;
const char* info = NULL;
BPath path;
int32 version = 0;
_GetTranslatorInfo(id, name, info, version, path);
const char* labels[] = { B_TRANSLATE("Name:"), B_TRANSLATE("Version:"),
B_TRANSLATE("Info:"), B_TRANSLATE("Path:"), NULL };
int offsets[4];
BString message;
BString temp;
offsets[0] = 0;
temp.SetToFormat("%s %s\n", labels[0], name);
message.Append(temp);
offsets[1] = message.Length();
// Convert the version number into a readable format
temp.SetToFormat("%s %" B_PRId32 ".%" B_PRId32 ".%" B_PRId32 "\n\n", labels[1],
B_TRANSLATION_MAJOR_VERSION(version),
B_TRANSLATION_MINOR_VERSION(version),
B_TRANSLATION_REVISION_VERSION(version));
message.Append(temp);
offsets[2] = message.Length();
temp.SetToFormat("%s\n%s\n\n", labels[2], info);
message.Append(temp);
offsets[3] = message.Length();
temp.SetToFormat("%s %s\n", labels[3], path.Path());
message.Append(temp);
BAlert* alert = new BAlert(B_TRANSLATE("Info"), message.String(),
B_TRANSLATE("OK"));
BTextView* view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetFace(B_BOLD_FACE);
for (int32 i = 0; labels[i]; i++) {
view->SetFontAndColor(offsets[i], offsets[i] + strlen(labels[i]), &font);
}
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
}
示例6: sizeof
status_t
DebugReportGenerator::_DumpDebuggedThreadInfo(BString& _output,
::Thread* thread)
{
AutoLocker< ::Team> locker;
if (thread->State() != THREAD_STATE_STOPPED)
return B_OK;
StackTrace* trace = NULL;
for (;;) {
trace = thread->GetStackTrace();
if (trace != NULL)
break;
locker.Unlock();
status_t result = acquire_sem(fTeamDataSem);
if (result != B_OK)
return result;
locker.Lock();
}
_output << "\t\tFrame\t\tIP\t\t\tFunction Name\n";
_output << "\t\t-----------------------------------------------\n";
BString data;
for (int32 i = 0; StackFrame* frame = trace->FrameAt(i); i++) {
char functionName[512];
data.SetToFormat("\t\t%#08" B_PRIx64 "\t%#08" B_PRIx64 "\t%s\n",
frame->FrameAddress(), frame->InstructionPointer(),
UiUtils::FunctionNameForFrame(frame, functionName,
sizeof(functionName)));
_output << data;
}
_output << "\n\t\tRegisters:\n";
CpuState* state = thread->GetCpuState();
BVariant value;
const Register* reg = NULL;
for (int32 i = 0; i < fArchitecture->CountRegisters(); i++) {
reg = fArchitecture->Registers() + i;
state->GetRegisterValue(reg, value);
char buffer[64];
data.SetToFormat("\t\t\t%5s:\t%s\n", reg->Name(),
UiUtils::VariantToString(value, buffer, sizeof(buffer)));
_output << data;
}
return B_OK;
}
示例7: objectlist
BObjectList<PootleProject>
PootleProjectsEndpoint::Get(int limit, int offset)
{
BObjectList<PootleProject> objectlist(20, true);
BString url;
int32 count = -1;
if (limit == -1)
limit = 100;
url.SetToFormat("?limit=%d&offset=%d", limit, offset);
BMessage data = _GetAll(url, limit < 0 ? 0 : limit);
data.GetInfo("data", NULL, &count);
if (count < 0)
return objectlist;
for (int32 i = 0; i < count; i++) {
BMessage msg;
data.FindMessage("data", i, &msg);
PootleProject *lang = new PootleProject(this, msg);
objectlist.AddItem(lang);
}
return objectlist;
}
示例8: BMessage
void
MainWin::SetupChannelMenu()
{
fChannelMenu->RemoveItems(0, fChannelMenu->CountItems(), true);
int interface = fController->CurrentInterface();
printf("MainWin::SetupChannelMenu: interface %d\n", interface);
int channels = fController->ChannelCount();
if (channels == 0) {
fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("None"),
new BMessage(M_DUMMY)));
} else {
fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Next channel"),
new BMessage(M_CHANNEL_NEXT), '+', B_COMMAND_KEY));
fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Previous channel"),
new BMessage(M_CHANNEL_PREV), '-', B_COMMAND_KEY));
fChannelMenu->AddSeparatorItem();
}
for (int i = 0; i < channels; i++) {
BString string;
string.SetToFormat("%s%d %s", (i < 9) ? " " : "", i + 1,
fController->ChannelName(i));
fChannelMenu->AddItem(new BMenuItem(string,
new BMessage(M_SELECT_CHANNEL + i)));
}
}
示例9: msg
status_t
ConfigWindow::_SetToGeneralSettings(BMailSettings* settings)
{
if (settings == NULL)
return B_BAD_VALUE;
status_t status = settings->InitCheck();
if (status != B_OK)
return status;
// retrieval frequency
uint32 interval = uint32(settings->AutoCheckInterval() / 60000000L);
fCheckMailCheckBox->SetValue(interval != 0 ? B_CONTROL_ON : B_CONTROL_OFF);
if (interval == 0)
interval = 5;
BString intervalText;
intervalText.SetToFormat("%" B_PRIu32, interval);
fIntervalControl->SetText(intervalText.String());
int32 showStatusIndex = settings->ShowStatusWindow();
BMenuItem* item = fStatusModeField->Menu()->ItemAt(showStatusIndex);
if (item != NULL) {
item->SetMarked(true);
// send live update to the server by simulating a menu click
BMessage msg(kMsgShowStatusWindowChanged);
msg.AddInt32("ShowStatusWindow", showStatusIndex);
PostMessage(&msg);
}
return B_OK;
}
示例10: CookieRow
void
CookieWindow::_ShowCookiesForDomain(BString domain)
{
BString label;
label.SetToFormat(B_TRANSLATE("Cookies for %s"), domain.String());
fHeaderView->SetText(label);
// Empty the cookie list
fCookies->Clear();
// Populate the domain list
BNetworkCookieJar::Iterator it = fCookieJar.GetIterator();
const BNetworkCookie* cookie;
/* FIXME A direct access to a domain would be needed in BNetworkCookieJar. */
while ((cookie = it.Next()) != NULL) {
if (cookie->Domain() == domain)
break;
}
if (cookie == NULL)
return;
do {
new CookieRow(fCookies, *cookie); // Attaches itself to the list
cookie = it.Next();
} while (cookie != NULL && cookie->Domain() == domain);
}
示例11: locker
status_t
DebugReportGenerator::_DumpLoadedImages(BString& _output)
{
AutoLocker< ::Team> locker(fTeam);
_output << "\nLoaded Images:\n";
BString data;
for (ImageList::ConstIterator it = fTeam->Images().GetIterator();
Image* image = it.Next();) {
const ImageInfo& info = image->Info();
char buffer[32];
try {
target_addr_t textBase = info.TextBase();
target_addr_t dataBase = info.DataBase();
data.SetToFormat("\t%s (%" B_PRId32 ", %s) "
"Text: %#08" B_PRIx64 " - %#08" B_PRIx64 ", Data: %#08"
B_PRIx64 " - %#08" B_PRIx64 "\n", info.Name().String(),
info.ImageID(), UiUtils::ImageTypeToString(info.Type(),
buffer, sizeof(buffer)), textBase,
textBase + info.TextSize(), dataBase,
dataBase + info.DataSize());
_output << data;
} catch (...) {
return B_NO_MEMORY;
}
}
return B_OK;
}
示例12: BMessage
void
VariableEditWindow::_Init()
{
BString label;
BString initialValue;
fInitialValue->ToString(initialValue);
label.SetToFormat("Initial value for '%s': %s\n",
fNode->Name().String(), initialValue.String());
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(new BStringView("initialLabel", label))
.End()
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(new BStringView("newLabel", "New value:"))
.Add(fEditor->GetView())
.End()
.AddGroup(B_HORIZONTAL, 4.0f)
.AddGlue()
.Add((fCancelButton = new BButton("Cancel",
new BMessage(B_QUIT_REQUESTED))))
.Add((fSaveButton = new BButton("Save",
new BMessage(MSG_WRITE_VARIABLE_VALUE))))
.End();
fCancelButton->SetTarget(this);
fSaveButton->SetTarget(this);
fSaveButton->MakeDefault(true);
fEditor->GetView()->MakeFocus(true);
}
示例13: catch
status_t
CLanguageFamily::EvaluateExpression(const BString& expression,
ValueNodeManager* manager, TeamTypeInformation* info,
ExpressionResult*& _output, ValueNode*& _neededNode)
{
_output = NULL;
_neededNode = NULL;
CLanguageExpressionEvaluator evaluator;
try {
_output = evaluator.Evaluate(expression, manager, info);
return B_OK;
} catch (ParseException ex) {
BString error;
error.SetToFormat("Parse error at position %" B_PRId32 ": %s",
ex.position, ex.message.String());
StringValue* value = new(std::nothrow) StringValue(error.String());
if (value == NULL)
return B_NO_MEMORY;
BReference<Value> valueReference(value, true);
_output = new(std::nothrow) ExpressionResult();
if (_output == NULL)
return B_NO_MEMORY;
_output->SetToPrimitive(value);
return B_BAD_DATA;
} catch (ValueNeededException ex) {
_neededNode = ex.value;
}
return B_OK;
}
示例14: _Setup
status_t
BProxySecureSocket::Connect(const BNetworkAddress& peer, bigtime_t timeout)
{
status_t status = InitCheck();
if (status != B_OK)
return status;
BSocket::Connect(fProxyAddress, timeout);
if (status != B_OK)
return status;
BString connectRequest;
connectRequest.SetToFormat("CONNECT %s:%d HTTP/1.0\r\n\r\n",
peer.HostName().String(), peer.Port());
BSocket::Write(connectRequest.String(), connectRequest.Length());
char buffer[256];
ssize_t length = BSocket::Read(buffer, sizeof(buffer) - 1);
if (length <= 0)
return length;
buffer[length] = '\0';
int httpStatus = 0;
int matches = scanf(buffer, "HTTP/1.0 %d %*[^\r\n]\r\n\r\n", httpStatus);
if (matches != 2)
return B_BAD_DATA;
if (httpStatus < 200 || httpStatus > 299)
return B_BAD_VALUE;
return _Setup();
}
示例15:
void
PackageManager::_PrintResult(InstalledRepository& installationRepository)
{
if (!installationRepository.HasChanges())
return;
printf(" in %s:\n", installationRepository.Name().String());
PackageList& packagesToActivate
= installationRepository.PackagesToActivate();
PackageList& packagesToDeactivate
= installationRepository.PackagesToDeactivate();
BStringList upgradedPackages;
for (int32 i = 0;
BSolverPackage* installPackage = packagesToActivate.ItemAt(i);
i++) {
for (int32 j = 0;
BSolverPackage* uninstallPackage = packagesToDeactivate.ItemAt(j);
j++) {
if (installPackage->Info().Name() == uninstallPackage->Info().Name()) {
upgradedPackages.Add(installPackage->Info().Name());
break;
}
}
}
for (int32 i = 0; BSolverPackage* package = packagesToActivate.ItemAt(i);
i++) {
BString repository;
if (dynamic_cast<MiscLocalRepository*>(package->Repository()) != NULL)
repository = "local file";
else
repository.SetToFormat("repository %s", package->Repository()->Name().String());
if (upgradedPackages.HasString(package->Info().Name())) {
printf(" upgrade package %s to %s from %s\n",
package->Info().Name().String(),
package->Info().Version().ToString().String(),
repository.String());
} else {
printf(" install package %s-%s from %s\n",
package->Info().Name().String(),
package->Info().Version().ToString().String(),
repository.String());
}
}
for (int32 i = 0; BSolverPackage* package = packagesToDeactivate.ItemAt(i);
i++) {
if (upgradedPackages.HasString(package->Info().Name()))
continue;
printf(" uninstall package %s\n", package->VersionedName().String());
}
// TODO: Print file/download sizes. Unfortunately our package infos don't
// contain the file size. Which is probably correct. The file size (and possibly
// other information) should, however, be provided by the repository cache in
// some way. Extend BPackageInfo? Create a BPackageFileInfo?
}