本文整理汇总了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;
}
示例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;
}