本文整理汇总了C++中BString::Truncate方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::Truncate方法的具体用法?C++ BString::Truncate怎么用?C++ BString::Truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::Truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isspace
void
KeyboardLayout::_Trim(BString& string, bool stripComments)
{
// Strip leading spaces
int32 i = 0;
while (isspace(string[i])) {
i++;
}
if (i > 0)
string.Remove(0, i);
// Remove comments
if (stripComments) {
i = string.FindFirst('#');
if (i >= 0)
string.Truncate(i);
}
// Strip trailing spaces
i = string.Length() - 1;
while (i > 0 && isspace(string[i])) {
i--;
}
string.Truncate(i + 1);
}
示例2: MapPlaceholder
bool
WindowTitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
bool numberGiven, BString& _string)
{
switch (placeholder) {
case 'T':
// The Terminal application name for the current locale
_string = B_TRANSLATE_SYSTEM_NAME("Terminal");
return true;
case 'i':
// window index
_string.Truncate(0);
if (fWindowIndex != 0)
_string << fWindowIndex;
return true;
case 't':
// the tab title
_string = fTabTitle;
return true;
}
return TitlePlaceholderMapper::MapPlaceholder(placeholder, number,
numberGiven, _string);
}
示例3: 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;
}
示例4: OpenTorrentDownloadFolder
void MainWindow::OpenTorrentDownloadFolder()
{
entry_ref ref;
if( const DownloadItem* item = fDownloadView->ItemSelected() )
{
//
// Get the torrent object.
//
const TorrentObject* torrent = item->GetTorrentObject();
//
// Build the download path.
//
BString DownloadPath = torrent->DownloadFolder();
//
//
//
if( torrent->IsFolder() )
{
BString FolderName = torrent->Info()->files[ 0 ].name;
FolderName.Truncate(FolderName.FindFirst('/'));
DownloadPath << "/" << FolderName;
}
status_t status = get_ref_for_path(DownloadPath.String(), &ref);
if (status == B_OK)
status = be_roster->Launch(&ref);
}
/*const char* kTrackerSignature = "application/x-vnd.Be-TRAK";
if( const DownloadItem* item = fDownloadView->ItemSelected() )
{
const TorrentObject* torrent = item->GetTorrentObject();
entry_ref ref;
status_t status = get_ref_for_path(torrent->GetDownloadDir(), &ref);
if( status == B_OK )
{
BMessage message(B_REFS_RECEIVED);
message.AddRef("refs", &ref);
BMessenger messenger(kTrackerSignature);
messenger.SendMessage(&message);
}
}
*/
}
示例5: lstat
bool
TermView::HyperLinkState::_EntryExists(const BString& path,
BString& _actualPath) const
{
if (path.IsEmpty())
return false;
if (path[0] == '/' || fCurrentDirectory.IsEmpty()) {
_actualPath = path;
} else if (path == "~" || path.StartsWith("~/")) {
// Replace '~' with the user's home directory. We don't handle "~user"
// here yet.
BPath homeDirectory;
if (find_directory(B_USER_DIRECTORY, &homeDirectory) != B_OK)
return false;
_actualPath = homeDirectory.Path();
_actualPath << path.String() + 1;
} else {
_actualPath.Truncate(0);
_actualPath << fCurrentDirectory << '/' << path;
}
struct stat st;
return lstat(_actualPath, &st) == 0;
}
示例6: converter
status_t
BLanguage::GetName(BString& name, const BLanguage* displayLanguage) const
{
status_t status = B_OK;
BString appLanguage;
if (displayLanguage == NULL) {
BMessage preferredLanguage;
status = BLocaleRoster::Default()->GetPreferredLanguages(
&preferredLanguage);
if (status == B_OK)
status = preferredLanguage.FindString("language", 0, &appLanguage);
} else {
appLanguage = displayLanguage->Code();
}
if (status == B_OK) {
UnicodeString string;
fICULocale->getDisplayName(Locale(appLanguage), string);
name.Truncate(0);
BStringByteSink converter(&name);
string.toUTF8(converter);
}
return status;
}
示例7: Encode
void Permissions::Encode(BString& permissions)
{
permissions.Truncate(0);
for (int32 i = 0; i < fNofPermissions; i++) {
if (!At(i)->IsAllowed())
permissions.Append(At(i)->GetPDFName()).Append(" ");
}
}
示例8: AddHeaderField
status_t BMailMessage::AddHeaderField(const char *field_name, const char *str,
bool /*clobber*/)
{
//printf("Second AddHeaderField. Args are %s%s\n",field_name,str);
BString string = field_name;
string.Truncate(string.Length() - 2); //----BMailMessage includes the ": "
((BEmailMessage *)(fFields))->SetHeaderField(string.String(),str);
return B_OK;
}
示例9: BTextView
/***********************************************************
* HardWrap
***********************************************************/
void
HWrapTextView::GetHardWrapedText(BString &out)
{
MakeEditable(false);
BTextView *offview = new BTextView(Bounds(),NULL,TextRect(),B_FOLLOW_ALL);
offview->SetText(Text());
BFont font;
uint32 propa;
GetFontAndColor(&font,&propa);
out = "";
offview->SetFontAndColor(&font,B_FONT_ALL);
BString line;
int32 length = offview->TextLength();
float view_width = offview->TextRect().Width();
char c=0;
bool inserted;
for(int32 i=0;i < length;i++)
{
c = offview->ByteAt(i);
if(c == '\n')
{
line = "";
continue;
}
line += c;
if(font.StringWidth(line.String())>=view_width)
{
// Back 1 charactor.
i--;
line.Truncate(line.Length()-1);
// Insert line break.
inserted = false;
int32 len = line.Length();
for(int32 k = 0;k<len;k++)
{
if(offview->CanEndLine(i-k))
{
offview->Insert(i-k,"\n",1);
inserted=true;
i = i-k;
break;
}
}
// If could not find proper position, add line break to end.
if(!inserted)
offview->Insert(i,"\n",1);
line = "";
}
}
out = offview->Text();
delete offview;
MakeEditable(true);
}
示例10: gui_empty_clipboard
bool gui_empty_clipboard(void)
{
current_selection.Truncate(0);
while (current_selection_textruns.ItemAt(0)) {
text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L);
delete run;
}
return true;
}
示例11: GetFortune
status_t FortuneAccess::GetFortune(BString *target)
{
if(!target)
return B_BAD_VALUE;
if(fRefList.CountItems()<1)
return B_ERROR;
int32 index = int32(float(rand()) / RAND_MAX * fRefList.CountItems());
entry_ref *ref = (entry_ref*)fRefList.ItemAt(index);
BFile file(ref,B_READ_ONLY);
if(file.InitCheck()!=B_OK)
return file.InitCheck();
fLastFile = ref->name;
off_t size;
file.GetSize(&size);
if(size<1)
return B_ERROR;
BString data;
char *buffer = data.LockBuffer(size + 10);
file.Read(buffer,size);
data.UnlockBuffer();
buffer = NULL;
// We can't depend on a .dat file, so calculate the number of entries manually
int32 entrycount = 0;
int32 entrystart = 0;
do
{
entrystart = data.FindFirst("%\n",entrystart + 1);
entrycount++;
} while(entrystart>0);
int32 entry = int32(float(rand()) / RAND_MAX * (entrycount-1));
entrystart = 0;
for(int32 i=0; i<entry; i++)
entrystart = data.FindFirst("%\n",entrystart + 1);
BString entrydata;
entrydata = data.String() + entrystart + 2;
int32 entrylength = entrydata.FindFirst("%\n");
if(entrylength>0)
entrydata.Truncate(entrylength);
*target = entrydata;
return B_OK;
}
示例12: relative
BUrl::BUrl(const BUrl& base, const BString& location)
:
fUrlString(),
fProtocol(),
fUser(),
fPassword(),
fHost(),
fPort(0),
fPath(),
fRequest(),
fHasAuthority(false)
{
// This implements the algorithm in RFC3986, Section 5.2.
BUrl relative(location);
if (relative.HasProtocol()) {
SetProtocol(relative.Protocol());
SetAuthority(relative.Authority());
SetPath(relative.Path()); // TODO _RemoveDotSegments()
SetRequest(relative.Request());
} else {
if (relative.HasAuthority()) {
SetAuthority(relative.Authority());
SetPath(relative.Path()); // TODO _RemoveDotSegments()
SetRequest(relative.Request());
} else {
if (relative.Path().IsEmpty()) {
SetPath(base.Path());
if (relative.HasRequest())
SetRequest(relative.Request());
else
SetRequest(Request());
} else {
if (relative.Path()[0] == '/')
SetPath(relative.Path());
else {
BString path = base.Path();
// Remove last part of path (the file, if any) so we get the
// "current directory"
path.Truncate(path.FindLast('/') + 1);
path += relative.Path();
// TODO _RemoveDotSegments()
SetPath(path);
}
SetRequest(relative.Request());
}
SetAuthority(base.Authority());
}
SetProtocol(base.Protocol());
}
SetFragment(relative.Fragment());
}
示例13: gui_start_selection
void gui_start_selection(struct gui_window *g)
{
current_selection.Truncate(0);
while (current_selection_textruns.ItemAt(0)) {
text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L);
delete run;
}
if (!g->view->LockLooper())
return;
g->view->MakeFocus();
g->view->UnlockLooper();
}
示例14: atoi
void
ID3Tags::SetTrack(const char* value)
{
PRINT(("ID3Tags::SetTrack(const char*)\n"));
int trk = 0;
if(value)
{
trk = atoi(value);
BString string;
string.Truncate(0);
string << trk;
m_track->SetValue(string.String());
}
}
示例15: entry
status_t
BLocaleRoster::_PrepareCatalogEntry(const entry_ref& ref, BString& signature,
BString& context, BString& string, bool traverse)
{
BEntry entry(&ref, traverse);
if (!entry.Exists())
return B_ENTRY_NOT_FOUND;
BNode node(&entry);
status_t status = node.InitCheck();
if (status != B_OK)
return status;
status = node.ReadAttrString("SYS:NAME", &signature);
if (status != B_OK)
return status;
int32 first = signature.FindFirst(':');
int32 last = signature.FindLast(':');
if (first == last)
return B_ENTRY_NOT_FOUND;
context = signature;
string = signature;
signature.Truncate(first);
context.Truncate(last);
context.Remove(0, first + 1);
string.Remove(0, last + 1);
if (signature.Length() == 0 || context.Length() == 0
|| string.Length() == 0)
return B_ENTRY_NOT_FOUND;
return B_OK;
}