本文整理汇总了C++中BString::ReplaceAll方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::ReplaceAll方法的具体用法?C++ BString::ReplaceAll怎么用?C++ BString::ReplaceAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::ReplaceAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseAlias
BString VisionApp::ParseAlias(const char* cmd, const BString& channel)
{
BString command(GetWord(cmd, 1).ToUpper());
BString newcmd = fAliases[command];
const char* parse = newcmd.String();
int32 replidx(0);
int32 varidx(0);
newcmd.ReplaceAll("$C", channel.String());
while (*parse != '\0') {
if (*parse != '$') {
++parse;
continue;
} else {
replidx = parse - newcmd.String();
++parse;
if (isdigit(*parse)) {
varidx = atoi(parse);
BString replString = "$";
replString << varidx;
if (*(parse + replString.Length() - 1) != '-') {
newcmd.ReplaceAll(replString.String(), GetWord(cmd, varidx + 1).String());
} else {
replString += "-";
newcmd.ReplaceAll(replString.String(), RestOfString(cmd, varidx + 1).String());
}
}
}
}
return newcmd;
}
示例2:
// Note: \xNN is not replaced back, so you get the unescaped value in the catkey
// file. This is fine for regular unicode chars (B_UTF8_ELLIPSIS) but may be
// dangerous if you use \x10 as a newline...
void
escapeQuotedChars(BString& stringToEscape)
{
stringToEscape.ReplaceAll("\\","\\\\");
stringToEscape.ReplaceAll("\n","\\n");
stringToEscape.ReplaceAll("\t","\\t");
stringToEscape.ReplaceAll("\"","\\\"");
}
示例3:
static
void
EscapeWord(BString& word)
{
word.ReplaceAll("\\", "\\\\");
word.ReplaceAll("#", "\\#");
word.ReplaceAll("\"", "\\\"");
word.ReplaceAll("\'", "\\\'");
}
示例4:
void
THeaderView::InitEmailCompletion()
{
// get boot volume
BVolume volume;
BVolumeRoster().GetBootVolume(&volume);
BQuery query;
query.SetVolume(&volume);
query.SetPredicate("META:email=**");
// Due to R5 BFS bugs, you need two stars, META:email=** for the query.
// META:email="*" will just return one entry and stop, same with
// META:email=* and a few other variations. Grumble.
query.Fetch();
entry_ref ref;
while (query.GetNextRef (&ref) == B_OK) {
BNode file;
if (file.SetTo(&ref) == B_OK) {
// Add the e-mail address as an auto-complete string.
BString email;
if (file.ReadAttrString("META:email", &email) >= B_OK)
fEmailList.AddChoice(email.String());
// Also add the quoted full name as an auto-complete string. Can't
// do unquoted since auto-complete isn't that smart, so the user
// will have to type a quote mark if he wants to select someone by
// name.
BString fullName;
if (file.ReadAttrString("META:name", &fullName) >= B_OK) {
if (email.FindFirst('<') < 0) {
email.ReplaceAll('>', '_');
email.Prepend("<");
email.Append(">");
}
fullName.ReplaceAll('\"', '_');
fullName.Prepend("\"");
fullName << "\" " << email;
fEmailList.AddChoice(fullName.String());
}
// support for 3rd-party People apps. Looks like a job for
// multiple keyword (so you can have several e-mail addresses in
// one attribute, perhaps comma separated) indices! Which aren't
// yet in BFS.
for (int16 i = 2; i < 6; i++) {
char attr[16];
sprintf(attr, "META:email%d", i);
if (file.ReadAttrString(attr, &email) >= B_OK)
fEmailList.AddChoice(email.String());
}
}
}
}
示例5: ReceiveWarning
void AIMNetManager::ReceiveWarning( SNAC_Object& snac ) {
BString warnMessage;
char strNewWLevel[15];
unsigned short wLevel, i=0;
DataContainer screenName;
bool anon = false;
char snLength;
wLevel = (unsigned short)( rint( (double)GetWord(snac.data,i) / 10.0 ) );
i += 2;
printf( "New warning level: %u%%\n", wLevel );
printf( "... came from " );
// 'twas an anonymous warning
if( i >= snac.data.length() ) {
anon = true;
printf( "Anonymous\n" );
}
// grab the length, and then the screen name
if( !anon ) {
snLength = snac.data[i++];
screenName = DataContainer( snac.data.getrange(i,snLength) );
i += snLength;
screenName << char(0);
printf( "%s\n", screenName.c_ptr() );
}
// is our warning level going DOWN? if so, don't annoy the user by telling them about it
if( wLevel < client->WarningLevel() ) {
client->SetWarningLevel( wLevel );
return;
}
// make the "warned" message
client->SetWarningLevel( wLevel );
sprintf( strNewWLevel, "%u%%", wLevel );
warnMessage = BString( Language.get("ERR_GOT_WARNED") );
warnMessage.ReplaceAll( "%WLEVEL", strNewWLevel );
if( anon ) {
BString anonLabel = "[";
anonLabel.Append( Language.get("ANONYMOUS_LABEL") );
anonLabel.Append( "]" );
warnMessage.ReplaceAll( "%USER", anonLabel.String() );
} else
warnMessage.ReplaceAll( "%USER", screenName.c_ptr() );
// now display it
windows->ShowMessage( warnMessage, B_STOP_ALERT, Language.get("BEHAVE_LABEL"), WS_WARNED );
}
示例6: sizeof
void
MainWindow::_DisplayPartitionError(BString _message,
const BPartition* partition, status_t error) const
{
char message[1024];
if (partition && _message.FindFirst("%s") >= 0) {
BString name;
name << "\"" << partition->ContentName() << "\"";
snprintf(message, sizeof(message), _message.String(), name.String());
} else {
_message.ReplaceAll("%s", "");
snprintf(message, sizeof(message), _message.String());
}
if (error < B_OK) {
BString helper = message;
const char* errorString
= B_TRANSLATE_COMMENT("Error: ", "in any error alert");
snprintf(message, sizeof(message), "%s\n\n%s%s", helper.String(),
errorString, strerror(error));
}
BAlert* alert = new BAlert("error", message, B_TRANSLATE("OK"), NULL, NULL,
B_WIDTH_FROM_WIDEST, error < B_OK ? B_STOP_ALERT : B_INFO_ALERT);
alert->Go(NULL);
}
示例7:
status_t
CDDBServer::_SendCommand(const BString& command, BString& output)
{
if (!fConnected)
return B_ERROR;
// Assemble full command string.
BString fullCommand;
fullCommand << command << "&hello=" << fLocalUserName << " " <<
fLocalHostName << " cddb_lookup 1.0&proto=6";
// Replace spaces by + signs.
fullCommand.ReplaceAll(" ", "+");
// And now add command header and footer.
fullCommand.Prepend("GET /~cddb/cddb.cgi?cmd=");
fullCommand << " HTTP 1.0\n\n";
int32 result = fConnection.Send((void*)fullCommand.String(),
fullCommand.Length());
if (result == fullCommand.Length()) {
BNetBuffer netBuffer;
while (fConnection.Receive(netBuffer, 1024) != 0) {
// Do nothing. Data is automatically appended to the NetBuffer.
}
// AppendString automatically adds the terminating \0.
netBuffer.AppendString("");
output.SetTo((char*)netBuffer.Data(), netBuffer.Size());
return B_OK;
}
return B_ERROR;
}
示例8: username
void
MainWindow::_UpdateAuthorization()
{
BString username(fModel.Username());
bool hasUser = !username.IsEmpty();
if (fLogOutItem != NULL)
fLogOutItem->SetEnabled(hasUser);
if (fLogInItem != NULL) {
if (hasUser)
fLogInItem->SetLabel(B_TRANSLATE("Switch account" B_UTF8_ELLIPSIS));
else
fLogInItem->SetLabel(B_TRANSLATE("Log in" B_UTF8_ELLIPSIS));
}
if (fUserMenu != NULL) {
BString label;
if (username.Length() == 0) {
label = B_TRANSLATE("Not logged in");
} else {
label = B_TRANSLATE("Logged in as %User%");
label.ReplaceAll("%User%", username);
}
fUserMenu->Superitem()->SetLabel(label);
}
}
示例9: path
status_t
ExpanderThread::ThreadStartup()
{
status_t status = B_OK;
entry_ref srcRef;
entry_ref destRef;
BString cmd;
if ((status = GetDataStore()->FindRef("srcRef", &srcRef)) != B_OK)
return status;
if ((status = GetDataStore()->FindRef("destRef", &destRef)) == B_OK) {
BPath path(&destRef);
chdir(path.Path());
}
if ((status = GetDataStore()->FindString("cmd", &cmd)) != B_OK)
return status;
BPath path(&srcRef);
BString pathString(path.Path());
pathString.CharacterEscape("\\\"$`", '\\');
pathString.Prepend("\"");
pathString.Append("\"");
cmd.ReplaceAll("%s", pathString.String());
int32 argc = 3;
const char** argv = new const char * [argc + 1];
argv[0] = strdup("/bin/sh");
argv[1] = strdup("-c");
argv[2] = strdup(cmd.String());
argv[argc] = NULL;
fThreadId = PipeCommand(argc, argv, fStdIn, fStdOut, fStdErr);
delete [] argv;
if (fThreadId < 0)
return fThreadId;
// lower the command priority since it is a background task.
set_thread_priority(fThreadId, B_LOW_PRIORITY);
resume_thread(fThreadId);
int flags = fcntl(fStdOut, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(fStdOut, F_SETFL, flags);
flags = fcntl(fStdErr, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(fStdErr, F_SETFL, flags);
fExpanderOutput = fdopen(fStdOut, "r");
fExpanderError = fdopen(fStdErr, "r");
return B_OK;
}
示例10:
void
PackageManager::JobFailed(BJob* job)
{
BString error = job->ErrorString();
if (error.Length() > 0) {
error.ReplaceAll("\n", "\n*** ");
fprintf(stderr, "%s", error.String());
}
}
示例11: UploadFromUser
bool UploadFromUser(LogWindow* logWindow, const char* filename, uint32 iFileLength)
{
uint32 iBytesReceived;
BString fileString;
BFile* bfMp3;
DownloadWindow* myDownloadWindow;
unsigned char* pBuffer;
BString status;
BString tmp;
DownloadView* dlView;
pBuffer = (unsigned char *) malloc(4096);
fileString = filename;
fileString.ReplaceAll("\\", "/");
tmp << logWindow->myPreferences->GetDownloadPath() << "/";
fileString.Prepend(tmp);
bfMp3 = new BFile(fileString.String(), B_WRITE_ONLY|B_CREATE_FILE|B_OPEN_AT_END);
if (bfMp3->InitCheck() == B_OK)
{
logWindow->netEndpoint->Send("0",1); // I think this is the start position, other values may be resumes
myDownloadWindow = new DownloadWindow(BRect(100,100, 400, 200), "Upload From User",
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_RESIZABLE,
B_CURRENT_WORKSPACE);
myDownloadWindow->Show();
dlView = myDownloadWindow->AddTransfer(filename, (float)iFileLength);
uint32 iDataLength = 0;
while(iDataLength < iFileLength)
{
iBytesReceived = logWindow->netEndpoint->Receive((unsigned char*)pBuffer, 4096);
if (iBytesReceived < 0)
{
break;
}
bfMp3->Write(pBuffer, iBytesReceived);
iDataLength += iBytesReceived;
myDownloadWindow->Lock();
dlView->AddBytesReceived(iBytesReceived);
myDownloadWindow->Unlock();
}
dlView->SetFinished(true);
bfMp3->Unset();
myDownloadWindow->Refresh();
} else {
//logWindow->LogMessage("Could Not Open The File", BN_ERROR);
}
return true;
}
示例12:
status_t
SVNSourceControl::GetCheckinHeader(BString &out)
{
GetChangeStatus(out);
out.Prepend("SVN: \nAll lines starting with 'SVN:' will be ignored.\n"
"----------------------------------------------------\n");
out.ReplaceAll("\n", "\nSVN: ");
return B_OK;
}
示例13: GetFormattedMessage
// Format the message into HTML, and return it
char* HTMLView::GetFormattedMessage() {
BString theText = Text();
// replace all linebreaks with <br>'s
theText.ReplaceAll( "\n", "<br>" );
message = (char*)malloc( theText.Length() + 1 );
theText.CopyInto( message, 0, theText.Length() );
message[theText.Length()] = '\0';
return message;
}
示例14: VisionVersion
void VisionApp::VisionVersion(int typebit, BString& result)
{
switch (typebit) {
case VERSION_VERSION:
result = VERSION_STRING;
break;
case VERSION_DATE:
result = __DATE__ " " __TIME__;
result.ReplaceAll("_", " ");
break;
}
}
示例15: new
void
MediaConverterApp::RefsReceived(BMessage* msg)
{
entry_ref ref;
int32 i = 0;
BString errorFiles;
int32 errors = 0;
// from Open dialog or drag & drop
while (msg->FindRef("refs", i++, &ref) == B_OK) {
uint32 flags = 0; // B_MEDIA_FILE_NO_READ_AHEAD
BMediaFile* file = new(std::nothrow) BMediaFile(&ref, flags);
if (file == NULL || file->InitCheck() != B_OK) {
errorFiles << ref.name << "\n";
errors++;
delete file;
continue;
}
if (fWin->Lock()) {
if (!fWin->AddSourceFile(file, ref))
delete file;
fWin->Unlock();
}
}
if (errors) {
BString alertText;
if (errors > 1) {
alertText = B_TRANSLATE(
"%amountOfFiles files were not recognized"
" as supported media files:");
BString amount;
amount << errors;
alertText.ReplaceAll("%amountOfFiles", amount);
} else {
alertText = B_TRANSLATE(
"The file was not recognized as a supported media file:");
}
alertText << "\n" << errorFiles;
BAlert* alert = new BAlert((errors > 1) ?
B_TRANSLATE("Error loading files") :
B_TRANSLATE("Error loading a file"),
alertText.String(), B_TRANSLATE("Continue"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go();
}
}