当前位置: 首页>>代码示例>>C++>>正文


C++ BString::UnlockBuffer方法代码示例

本文整理汇总了C++中BString::UnlockBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::UnlockBuffer方法的具体用法?C++ BString::UnlockBuffer怎么用?C++ BString::UnlockBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BString的用法示例。


在下文中一共展示了BString::UnlockBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: name

void
SyslogDaemon::AboutRequested()
{
	BPath path;
	find_directory(B_SYSTEM_LOG_DIRECTORY, &path);
	path.Append("syslog");

	BString name(B_TRANSLATE("Syslog Daemon"));
	BString message;
	snprintf(message.LockBuffer(512), 512,
		B_TRANSLATE("%s\n\nThis daemon is responsible for collecting "
			"all system messages and write them to the system-wide log "
			"at \"%s\".\n\n"), name.String(), path.Path());
	message.UnlockBuffer();

	BAlert *alert = new BAlert(name.String(), message.String(), B_TRANSLATE("OK"));
	BTextView *view = alert->TextView();
	BFont font;

	view->SetStylable(true);

	view->GetFont(&font);
	font.SetSize(21);
	font.SetFace(B_BOLD_FACE); 			
	view->SetFontAndColor(0, name.Length(), &font);

	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go(NULL);
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:29,代码来源:SyslogDaemon.cpp

示例2: strlen

void
PDFWriter::ToUnicode(const char *string, BString &unicode)
{
	int32 len = strlen(string);
	int32 srcLen = len, destLen = 255;
	int32 state = 0;
	char buffer[256];
	int32 srcStart = 0;
	int i = 0;

	unicode = "";
	if (len == 0) return;

	do {
		convert_from_utf8(B_UNICODE_CONVERSION, &string[srcStart], &srcLen,
			buffer, &destLen, &state);
		srcStart += srcLen;
		len -= srcLen;
		srcLen = len;

		char *b = unicode.LockBuffer(i + destLen);
		memcpy(&b[i], buffer, destLen);
		unicode.UnlockBuffer(i + destLen);
		i += destLen;
		destLen = 255;
	} while (len > 0);
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:27,代码来源:PDFText.cpp

示例3: BMessage

void
PriorityMenu::BuildMenu()
{
	BMenuItem* item;
	BMessage* message;
	long found = false;

	for (long index = 0; ; index++) {
		PriorityRec	*priority = &priorities[index];
		if (priority->priority < 0)
			break;
		if (!found && fPriority < priority->priority && fPriority >= 0) {
			priority = &customPriority;
			priority->priority = fPriority;
			index--;
		}
		message = new BMessage(SET_PRIORITY);
		message->AddInt32("priority", priority->priority);
		BString name;
		const size_t size = B_OS_NAME_LENGTH * 4;
		snprintf(name.LockBuffer(size), size,
			"%s [%d]", priority->name, (int)priority->priority);
		name.UnlockBuffer();
		item = new BMenuItem(name.String(), message);
		item->SetTarget(slayer->mainWindow);
		item->SetEnabled(fEnabled);
		if (fPriority == priority->priority)
			found = true, item->SetMarked(true);
		AddItem(item);
	}
}
开发者ID:HaikuArchives,项目名称:Slayer,代码行数:31,代码来源:PriorityMenu.cpp

示例4: switch

static void
CoerceFormatToAbbreviatedTimezone(BString& format)
{
    char* s = format.LockBuffer(format.Length());
    if (s == NULL)
        return;

    // replace a single 'z' with 'V'
    bool inQuote = false;
    bool lastWasZ = false;
    for (; *s != '\0'; ++s) {
        switch (*s) {
        case '\'':
            inQuote = !inQuote;
            break;
        case 'z':
            if (!inQuote && !lastWasZ && *(s+1) != 'z')
                *s = 'V';
            lastWasZ = true;
            continue;
        }
        lastWasZ = false;
    }
    format.UnlockBuffer(format.Length());
}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例5: 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;
}
开发者ID:HaikuArchives,项目名称:Fortuna,代码行数:56,代码来源:FortuneFunctions.cpp

示例6: Read

status_t
LinkReceiver::ReadString(BString &string, size_t* _length)
{
	int32 length = 0;
	status_t status = Read<int32>(&length);

	if (status < B_OK)
		return status;

	if (length < 0) {
		status = B_ERROR;
		goto err;
	}

	if (length > 0) {
		char* buffer = string.LockBuffer(length + 1);
		if (buffer == NULL) {
			status = B_NO_MEMORY;
			goto err;
		}

		status = Read(buffer, length);
		if (status < B_OK) {
			string.UnlockBuffer();
			goto err;
		}

		// make sure the string is null terminated
		buffer[length] = '\0';
		string.UnlockBuffer(length);
	} else
		string = "";

	if (_length)
		*_length = length;

	return B_OK;

err:
	fRecvPosition -= sizeof(int32);
		// rewind the transaction
	return status;
}
开发者ID:DonCN,项目名称:haiku,代码行数:43,代码来源:LinkReceiver.cpp

示例7:

static BString
size_string(double size)
{
	BString string;
	char* buffer = string.LockBuffer(256);
	string_for_size(size, buffer, 256);

	string.UnlockBuffer();
	return string;
}
开发者ID:nielx,项目名称:haiku-serviceskit,代码行数:10,代码来源:BFSAddOn.cpp

示例8: mime

BString
BUrl::PreferredApplication() const
{
	BString appSignature;
	BMimeType mime(_UrlMimeType().String());
	mime.GetPreferredApp(appSignature.LockBuffer(B_MIME_TYPE_LENGTH));
	appSignature.UnlockBuffer();

	return BString(appSignature);
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例9: strerror

void
DataTranslationsApplication::_InstallError(const char* name, status_t status)
{
	BString text;
	snprintf(text.LockBuffer(512), 512,
			B_TRANSLATE("Could not install %s:\n%s"), name, strerror(status));
	text.UnlockBuffer();
	BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Error"),
		text.String(), B_TRANSLATE("OK"));
	alert->Go();
}
开发者ID:veer77,项目名称:Haiku-services-branch,代码行数:11,代码来源:DataTranslations.cpp

示例10:

static void
refresh_rate_to_string(float refresh, BString &string,
	bool appendUnit = true, bool alwaysWithFraction = false)
{
	snprintf(string.LockBuffer(32), 32, "%.*g", refresh >= 100.0 ? 4 : 3,
		refresh);
	string.UnlockBuffer();

	if (appendUnit)
		string << " " << B_TRANSLATE("Hz");
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:11,代码来源:ScreenWindow.cpp

示例11:

void
PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
{
	// PDFlib requires BOM at begin and two 0 at end of string
	BString s;
	ToUnicode(string, s);
	unicode << "\xfe\xff";
	int32 len = s.Length()+2;
	char* buf = unicode.LockBuffer(len + 2);
		// reserve space for two additional '\0'
	memcpy(&buf[2], s.String(), s.Length());
	buf[len] = buf[len+1] = 0;
	unicode.UnlockBuffer(len + 2);
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:14,代码来源:PDFText.cpp

示例12: _NormalizePath

	void _NormalizePath(const BString& path, BString& _normalizedPath)
	{
		BString normalizedPath;
		char* buffer = normalizedPath.LockBuffer(path.Length());
		int32 outIndex = 0;
		const char* remaining = path.String();

		while (*remaining != '\0') {
			// collapse repeated slashes
			if (*remaining == '/') {
				buffer[outIndex++] = '/';
				remaining++;
				while (*remaining == '/')
					remaining++;
			}

			if (*remaining == '\0') {
				// remove trailing slash (unless it's "/" only)
				if (outIndex > 1)
					outIndex--;
				break;
			}

			// skip "." components
			if (*remaining == '.') {
				if (remaining[1] == '\0')
					break;

				if (remaining[1] == '/') {
					remaining += 2;
					while (*remaining == '/')
						remaining++;
					continue;
				}
			}

			// copy path component
			while (*remaining != '\0' && *remaining != '/')
				buffer[outIndex++] = *(remaining++);
		}

		// If the path didn't change, use the original path (BString's copy on
		// write mechanism) rather than the new string.
		if (outIndex == path.Length()) {
			_normalizedPath = path;
		} else {
			normalizedPath.UnlockBuffer(outIndex);
			_normalizedPath = normalizedPath;
		}
	}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:50,代码来源:FileManager.cpp

示例13: fwrite

status_t 
PoorManWindow::SaveConsole(BMessage* message, bool selection)
{
	entry_ref	ref;
	const char* name;
	BPath		path;
	BEntry		entry;
	status_t	err = B_OK;
	FILE*		f;
	
	err = message->FindRef("directory", &ref);
	if (err != B_OK)
		return err;
	
	err = message->FindString("name", &name);
	if (err != B_OK)
		return err;
	
	err = entry.SetTo(&ref);
	if (err != B_OK)
		return err;
	
	entry.GetPath(&path);
	path.Append(name);
	
	if (!(f = fopen(path.Path(), "w")))
		return B_ERROR;
	
	if (!selection) {
		// write the data to the file
		err = fwrite(fLoggingView->Text(), 1, fLoggingView->TextLength(), f);
	} else {
		// find the selected text and write it to a file
		int32 start = 0, end = 0;
		fLoggingView->GetSelection(&start, &end);

		BString buffer;
		char * buffData = buffer.LockBuffer(end - start + 1);
		// copy the selected text from the TextView to the buffer
		fLoggingView->GetText(start, end - start, buffData);
		buffer.UnlockBuffer(end - start + 1);

		err = fwrite(buffer.String(), 1, end - start + 1, f);
	}

	fclose(f);

	return err;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:49,代码来源:PoorManWindow.cpp

示例14:

_EXPORT status_t
extract_from_header(const BString& header, const BString& field,
	BString& target)
{
	int32 headerLength = header.Length();
	int32 fieldEndPos = 0;
	while (true) {
		int32 pos = header.IFindFirst(field, fieldEndPos);
		if (pos < 0)
			return B_BAD_VALUE;
		fieldEndPos = pos + field.Length();
		
		if (pos != 0 && header.ByteAt(pos - 1) != '\n')
			continue;
		if (header.ByteAt(fieldEndPos) == ':')
			break;
	}
	fieldEndPos++;

	int32 crPos = fieldEndPos;
	while (true) {
		fieldEndPos = crPos;
		crPos = header.FindFirst('\n', crPos);
		if (crPos < 0)
			crPos = headerLength;
		BString temp;
		header.CopyInto(temp, fieldEndPos, crPos - fieldEndPos);
		if (header.ByteAt(crPos - 1) == '\r') {
			temp.Truncate(temp.Length() - 1);
			temp += " ";
		}
		target += temp;
		crPos++;
		if (crPos >= headerLength)
			break;
		char nextByte = header.ByteAt(crPos);
		if (nextByte != ' ' && nextByte != '\t')
			break;
		crPos++;
	}

	size_t bufferSize = target.Length();
	char* buffer = target.LockBuffer(bufferSize);
	size_t length = rfc2047_to_utf8(&buffer, &bufferSize, bufferSize);
	target.UnlockBuffer(length);

	return B_OK;
}
开发者ID:,项目名称:,代码行数:48,代码来源:

示例15: ConvertWordToCharset

		// Convert the word from UTF-8 to the desired character set.  The
		// converted version also includes the escape codes to return to ASCII
		// mode, if relevant.  Also note if it uses unprintable characters,
		// which means it will need that special encoding treatment later.
		void ConvertWordToCharset (uint32 charset) {
			int32 state = 0;
			int32 originalLength = originalWord.Length();
			int32 convertedLength = originalLength * 5 + 1;
			char *convertedBuffer = convertedWord.LockBuffer (convertedLength);
			mail_convert_from_utf8 (charset, originalWord.String(),
				&originalLength, convertedBuffer, &convertedLength, &state);
			for (int i = 0; i < convertedLength; i++) {
				if ((convertedBuffer[i] & (1 << 7)) ||
					(convertedBuffer[i] >= 0 && convertedBuffer[i] < 32)) {
					needsEncoding = true;
					break;
				}
			}
			convertedWord.UnlockBuffer (convertedLength);
		};
开发者ID:HaikuArchives,项目名称:BeMailDaemon,代码行数:20,代码来源:mail_util.cpp


注:本文中的BString::UnlockBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。