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


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

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


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

示例1:

BString
HaikuMailFormatFilter::_ExtractName(const BString& from)
{
	// extract name from something like "name" <[email protected]>
	// if name is empty return the mail address without "<>"

	BString name;
	int32 emailStart = from.FindFirst("<");
	if (emailStart < 0) {
		name = from;
		return name.Trim();
	}

	from.CopyInto(name, 0, emailStart);
	name.Trim();
	if (name.Length() >= 2) {
		if (name[name.Length() - 1] == '\"')
			name.Truncate(name.Length() - 1, true);
		if (name[0] == '\"')
			name.Remove(0, 1);
		name.Trim();
	}
	if (name != "")
		return name;

	// empty name extract email address
	name = from;
	name.Remove(0, emailStart + 1);
	name.Trim();
	if (name.Length() < 1)
		return from;
	if (name[name.Length() - 1] == '>')
		name.Truncate(name.Length() - 1, true);
	name.Trim();
	return name;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:36,代码来源:HaikuMailFormatFilter.cpp

示例2: textBufferLocker

bool
TermView::HyperLinkState::_GetHyperLinkAt(BPoint where, bool pathPrefixOnly,
	HyperLink& _link, TermPos& _start, TermPos& _end)
{
	TerminalBuffer* textBuffer = fView->fTextBuffer;
	BAutolock textBufferLocker(textBuffer);

	TermPos pos = fView->_ConvertToTerminal(where);

	// try to get a URL first
	BString text;
	if (!textBuffer->FindWord(pos, &fURLCharClassifier, false, _start, _end))
		return false;

	text.Truncate(0);
	textBuffer->GetStringFromRegion(text, _start, _end);
	text.Trim();

	// We're only happy, if it has a protocol part which we know.
	int32 colonIndex = text.FindFirst(':');
	if (colonIndex >= 0) {
		BString protocol(text, colonIndex);
		if (strstr(kKnownURLProtocols, protocol) != NULL) {
			_link = HyperLink(text, HyperLink::TYPE_URL);
			return true;
		}
	}

	// no obvious URL -- try file name
	if (!textBuffer->FindWord(pos, fView->fCharClassifier, false, _start, _end))
		return false;

	// In path-prefix-only mode we determine the end position anew by omitting
	// the '/' in the allowed word chars.
	if (pathPrefixOnly) {
		TermPos componentStart;
		TermPos componentEnd;
		if (textBuffer->FindWord(pos, &fPathComponentCharClassifier, false,
				componentStart, componentEnd)) {
			_end = componentEnd;
		} else {
			// That means pos points to a '/'. We simply use the previous
			// position.
			_end = pos;
			if (_start == _end) {
				// Well, must be just "/". Advance to the next position.
				if (!textBuffer->NextLinePos(_end, false))
					return false;
			}
		}
	}

	text.Truncate(0);
	textBuffer->GetStringFromRegion(text, _start, _end);
	text.Trim();
	if (text.IsEmpty())
		return false;

	// Collect a list of colons in the string and their respective positions in
	// the text buffer. We do this up-front so we can unlock the text buffer
	// while we're doing all the entry existence tests.
	typedef Array<CharPosition> ColonList;
	ColonList colonPositions;
	TermPos searchPos = _start;
	for (int32 index = 0; (index = text.FindFirst(':', index)) >= 0;) {
		TermPos foundStart;
		TermPos foundEnd;
		if (!textBuffer->Find(":", searchPos, true, true, false, foundStart,
				foundEnd)) {
			return false;
		}

		CharPosition colonPosition;
		colonPosition.index = index;
		colonPosition.position = foundStart;
		if (!colonPositions.Add(colonPosition))
			return false;

		index++;
		searchPos = foundEnd;
	}

	textBufferLocker.Unlock();

	// Since we also want to consider ':' a potential path delimiter, in two
	// nested loops we chop off components from the beginning respective the
	// end.
	BString originalText = text;
	TermPos originalStart = _start;
	TermPos originalEnd = _end;

	int32 colonCount = colonPositions.Count();
	for (int32 startColonIndex = -1; startColonIndex < colonCount;
			startColonIndex++) {
		int32 startIndex;
		if (startColonIndex < 0) {
			startIndex = 0;
			_start = originalStart;
		} else {
			startIndex = colonPositions[startColonIndex].index + 1;
//.........这里部分代码省略.........
开发者ID:AmirAbrams,项目名称:haiku,代码行数:101,代码来源:TermViewStates.cpp

示例3: cddbCommand

status_t
CDDBServer::Query(uint32 cddbID, const scsi_toc_toc* toc,
	QueryResponseList& queryResponses)
{
	if (_OpenConnection() != B_OK)
		return B_ERROR;

	// Convert CDDB id to hexadecimal format.
	char hexCddbId[9];
	sprintf(hexCddbId, "%08" B_PRIx32, cddbID);

	// Assemble the Query command.
	int32 numTracks = toc->last_track + 1 - toc->first_track;

	BString cddbCommand("cddb query ");
	cddbCommand << hexCddbId << " " << numTracks << " ";

	// Add track offsets in frames.
	for (int32 i = 0; i < numTracks; ++i) {
		const scsi_cd_msf& start = toc->tracks[i].start.time;

		uint32 startFrameOffset = start.minute * kFramesPerMinute +
			start.second * kFramesPerSecond + start.frame;

		cddbCommand << startFrameOffset << " ";
	}

	// Add total disc time in seconds. Last track is lead-out.
	const scsi_cd_msf& lastTrack = toc->tracks[numTracks].start.time;
	uint32 totalTimeInSeconds = lastTrack.minute * 60 + lastTrack.second;
	cddbCommand << totalTimeInSeconds;

	BString output;
	status_t result = _SendCommand(cddbCommand, output);
	if (result == B_OK) {
		// Remove the header from the reply.
		output.Remove(0, output.FindFirst("\r\n\r\n") + 4);

		// Check status code.
		BString statusCode;
		output.MoveInto(statusCode, 0, 3);
		if (statusCode == "210" || statusCode == "211") {
			// TODO(bga): We can get around with returning the first result
			// in case of multiple matches, but we most definitely need a
			// better handling of inexact matches.
			if (statusCode == "211")
				printf("Warning : Inexact match found.\n");

			// Multiple results, remove the first line and parse the others.
			output.Remove(0, output.FindFirst("\r\n") + 2);
		} else if (statusCode == "200") {
			// Remove the first char which is a left over space.
			output.Remove(0, 1);
		} else if (statusCode == "202") {
			// No match found.
			printf("Error : CDDB entry for id %s not found.\n", hexCddbId);

			return B_ENTRY_NOT_FOUND;
		} else {
			// Something bad happened.
			if (statusCode.Trim() != "") {
				printf("Error : CDDB server status code is %s.\n",
					statusCode.String());
			} else {
				printf("Error : Could not find any status code.\n");
			}

			return B_ERROR;
		}

		// Process all entries.
		bool done = false;
		while (!done) {
			QueryResponseData* responseData = new QueryResponseData;

			output.MoveInto(responseData->category, 0, output.FindFirst(" "));
			output.Remove(0, 1);

			output.MoveInto(responseData->cddbID, 0, output.FindFirst(" "));
			output.Remove(0, 1);

			output.MoveInto(responseData->artist, 0, output.FindFirst(" / "));
			output.Remove(0, 3);

			output.MoveInto(responseData->title, 0, output.FindFirst("\r\n"));
			output.Remove(0, 2);

			queryResponses.AddItem(responseData);

			if (output == "" || output == ".\r\n") {
				// All returned data was processed exit the loop.
				done = true;
			}
		}
	} else {
		printf("Error sending CDDB command : \"%s\".\n", cddbCommand.String());
	}

	_CloseConnection();
	return result;
//.........这里部分代码省略.........
开发者ID:koletzky,项目名称:haiku,代码行数:101,代码来源:cddb_server.cpp


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