本文整理汇总了C++中BString::ReplaceSet方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::ReplaceSet方法的具体用法?C++ BString::ReplaceSet怎么用?C++ BString::ReplaceSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::ReplaceSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: screen
void
Message::Draw(BView *view, int32 frame)
{
if (view == NULL || view->Window() == NULL || !view->Window()->IsLocked())
return;
BScreen screen(view->Window());
if (!screen.IsValid())
return;
// Double-buffered drawing
BBitmap buffer(view->Bounds(), screen.ColorSpace(), true);
if (buffer.InitCheck() != B_OK)
return;
BView offscreen(view->Bounds(), NULL, 0, 0);
buffer.AddChild(&offscreen);
buffer.Lock();
// Set up the colors
rgb_color base_color = {(uint8)(rand() % 25), (uint8)(rand() % 25),
(uint8)(rand() % 25)};
offscreen.SetHighColor(base_color);
offscreen.SetLowColor(tint_color(base_color, 0.815F));
offscreen.FillRect(offscreen.Bounds(), kCheckered);
rgb_color colors[8] = {
tint_color(base_color, B_LIGHTEN_1_TINT),
tint_color(base_color, 0.795F),
tint_color(base_color, 0.851F),
tint_color(base_color, 0.926F),
tint_color(base_color, 1.05F),
tint_color(base_color, B_DARKEN_1_TINT),
tint_color(base_color, B_DARKEN_2_TINT),
tint_color(base_color, B_DARKEN_3_TINT),
};
offscreen.SetDrawingMode(B_OP_OVER);
// Set the basic font parameters, including random font family
BFont font;
offscreen.GetFont(&font);
font.SetFace(B_BOLD_FACE);
font.SetFamilyAndStyle(*(fFontFamilies.ItemAt(rand() % fFontFamilies.CountItems())), NULL);
offscreen.SetFont(&font);
// Get the message
BString *message = get_message();
BString *origMessage = new BString();
message->CopyInto(*origMessage, 0, message->Length());
// Replace newlines and tabs with spaces
message->ReplaceSet("\n\t", ' ');
int height = (int) offscreen.Bounds().Height();
int width = (int) offscreen.Bounds().Width();
// From 14 to 22 iterations
int32 iterations = (rand() % 8) + 14;
for (int32 i = 0; i < iterations; i++) {
// Randomly set font size and shear
BFont font;
offscreen.GetFont(&font);
float fontSize = ((rand() % 320) + 42) * fScaleFactor;
font.SetSize(fontSize);
// Set the shear off 90 about 1/2 of the time
if (rand() % 2 == 1)
font.SetShear((float) ((rand() % 135) + (rand() % 45)));
else
font.SetShear(90.0);
offscreen.SetFont(&font);
// Randomly set drawing location
int x = (rand() % width) - (rand() % width/((rand() % 8)+1));
int y = rand() % height;
// Draw new text
offscreen.SetHighColor(colors[rand() % 8]);
int strLength = message->Length();
// See how wide this string is with the current font
float strWidth = offscreen.StringWidth(message->String());
int drawingLength = (int) (strLength * (width / strWidth));
int start = 0;
if (drawingLength >= strLength)
drawingLength = strLength;
else
start = rand() % (strLength - drawingLength);
char *toDraw = new char[drawingLength+1];
strncpy(toDraw, message->String()+start, drawingLength);
toDraw[drawingLength] = 0;
offscreen.DrawString(toDraw, BPoint(x, y));
delete[] toDraw;
}
// Now draw the full message in a nice translucent box, but only
// if this isn't preview mode
if (!fPreview) {
BFont font(be_fixed_font);
font.SetSize(14.0);
offscreen.SetFont(&font);
font_height fontHeight;
font.GetHeight(&fontHeight);
//.........这里部分代码省略.........
示例2: volume
status_t
CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
ReadResponseData* readResponse)
{
// Rename volume.
BVolume volume(device);
status_t result;
status_t error = B_OK;
BString name = diskData->artist << " - " << diskData->title;
name.ReplaceSet("/", " ");
if ((result = volume.SetName(name.String())) != B_OK) {
printf("Can't set volume name.\n");
return result;
}
// Rename tracks and add relevant Audio attributes.
BDirectory cddaRoot;
volume.GetRootDirectory(&cddaRoot);
BEntry entry;
int index = 0;
while (cddaRoot.GetNextEntry(&entry) == B_OK) {
TrackData* data = (TrackData*)((readResponse->tracks).ItemAt(index));
// Update name.
name = data->title;
name.ReplaceSet("/", " ");
if ((result = entry.Rename(name.String())) != B_OK) {
printf("Failed renaming entry at index %d to \"%s\".\n", index,
name.String());
error = result;
// User can benefit from continuing through all tracks.
// Report error later.
}
// Add relevant attributes. We consider an error here as non-fatal.
BNode node(&entry);
node.WriteAttr("Audio:Title", B_STRING_TYPE, 0, (data->title).String(),
(data->title).Length());
node.WriteAttr("Audio:Album", B_STRING_TYPE, 0,
(readResponse->title).String(),
(readResponse->title).Length());
node.WriteAttr("Audio:Genre", B_STRING_TYPE, 0,
(readResponse->genre).String(),
(readResponse->genre).Length());
node.WriteAttr("Audio:Year", B_INT32_TYPE, 0, &(readResponse->year),
sizeof(int32));
if (data->artist == "") {
node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0,
(readResponse->artist).String(),
(readResponse->artist).Length());
} else {
node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0,
(data->artist).String(), (data->artist).Length());
}
index++;
}
return error;
}
示例3: volume
status_t
CDDBLookup::_WriteCDData(dev_t device, const QueryResponseData& diskData,
const ReadResponseData& readResponse)
{
// Rename volume.
BVolume volume(device);
status_t error = B_OK;
BString name = diskData.artist;
name += " - ";
name += diskData.title;
name.ReplaceSet("/", " ");
status_t result = volume.SetName(name.String());
if (result != B_OK) {
printf("Can't set volume name.\n");
return result;
}
// Rename tracks and add relevant Audio attributes.
BDirectory cddaRoot;
volume.GetRootDirectory(&cddaRoot);
BEntry entry;
int index = 0;
while (cddaRoot.GetNextEntry(&entry) == B_OK) {
TrackData* track = readResponse.tracks.ItemAt(index);
// Update name.
int trackNum = index + 1; // index=0 is actually Track 1
name.SetToFormat("%02d %s.wav", trackNum, track->title.String());
name.ReplaceSet("/", " ");
result = entry.Rename(name.String());
if (result != B_OK) {
fprintf(stderr, "%s: Failed renaming entry at index %d to "
"\"%s\".\n", kProgramName, index, name.String());
error = result;
// User can benefit from continuing through all tracks.
// Report error later.
}
// Add relevant attributes. We consider an error here as non-fatal.
BNode node(&entry);
node.WriteAttrString("Media:Title", &track->title);
node.WriteAttrString("Audio:Album", &readResponse.title);
if (readResponse.genre.Length() != 0)
node.WriteAttrString("Media:Genre", &readResponse.genre);
if (readResponse.year != 0) {
node.WriteAttr("Media:Year", B_INT32_TYPE, 0,
&readResponse.year, sizeof(int32));
}
if (track->artist == "")
node.WriteAttrString("Audio:Artist", &readResponse.artist);
else
node.WriteAttrString("Audio:Artist", &track->artist);
index++;
}
return error;
}