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


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

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


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

示例1:

void
MarkupParser::_CopySpan(const BString& text, int32& start, int32 end)
{
	if (start >= end)
		return;

	BString subString;
	text.CopyCharsInto(subString, start, end - start);
	fCurrentParagraph.Append(TextSpan(subString, *fCurrentCharacterStyle));

	start = end;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:12,代码来源:MarkupParser.cpp

示例2: span

status_t
TextDocument::Insert(int32 textOffset, const BString& text,
	const CharacterStyle& characterStyle, const ParagraphStyle& paragraphStyle)
{
	int32 paragraphOffset;
	int32 index = ParagraphIndexFor(textOffset, paragraphOffset);
	if (index < 0)
		return B_BAD_VALUE;

	textOffset -= paragraphOffset;

	bool hasLineBreaks = text.FindFirst('\n', 0) >= 0;

	if (hasLineBreaks) {
		// Split paragraph at textOffset
		Paragraph paragraph1(ParagraphAt(index).Style());
		Paragraph paragraph2(paragraphStyle);
		const TextSpanList& textSpans = ParagraphAt(index).TextSpans();
		int32 spanCount = textSpans.CountItems();
		for (int32 i = 0; i < spanCount; i++) {
			const TextSpan& span = textSpans.ItemAtFast(i);
			int32 spanLength = span.CountChars();
			if (textOffset >= spanLength) {
				paragraph1.Append(span);
				textOffset -= spanLength;
			} else if (textOffset > 0) {
				paragraph1.Append(
					span.SubSpan(0, textOffset));
				paragraph2.Append(
					span.SubSpan(textOffset, spanLength - textOffset));
				textOffset = 0;
			} else {
				paragraph2.Append(span);
			}
		}

		fParagraphs.Remove(index);

		// Insert TextSpans, splitting 'text' into Paragraphs at line breaks.
		int32 length = text.CountChars();
		int32 chunkStart = 0;
		while (chunkStart < length) {
			int32 chunkEnd = text.FindFirst('\n', chunkStart);
			bool foundLineBreak = chunkEnd >= chunkStart;
			if (foundLineBreak)
				chunkEnd++;
			else
				chunkEnd = length;

			BString chunk;
			text.CopyCharsInto(chunk, chunkStart, chunkEnd - chunkStart);
			TextSpan span(chunk, characterStyle);

			if (foundLineBreak) {
				if (!paragraph1.Append(span))
					return B_NO_MEMORY;
				if (paragraph1.Length() > 0) {
					if (!fParagraphs.Add(paragraph1, index))
						return B_NO_MEMORY;
					index++;
				}
				paragraph1 = Paragraph(paragraphStyle);
			} else {
				if (!paragraph2.Prepend(span))
					return B_NO_MEMORY;
			}

			chunkStart = chunkEnd + 1;
		}

		if (paragraph2.IsEmpty()) {
			// Make sure Paragraph has at least one TextSpan, even
			// if its empty.
			const TextSpanList& spans = paragraph1.TextSpans();
			const TextSpan& span = spans.LastItem();
			paragraph2.Append(TextSpan("", span.Style()));
		}

		if (!fParagraphs.Add(paragraph2, index))
			return B_NO_MEMORY;
	} else {
		Paragraph paragraph(ParagraphAt(index));
		paragraph.Insert(textOffset, TextSpan(text, characterStyle));
		if (!fParagraphs.Replace(index, paragraph))
			return B_NO_MEMORY;
	}

	return B_OK;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:89,代码来源:TextDocument.cpp


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