本文整理汇总了C++中MemoryOutputStream::preallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryOutputStream::preallocate方法的具体用法?C++ MemoryOutputStream::preallocate怎么用?C++ MemoryOutputStream::preallocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryOutputStream
的用法示例。
在下文中一共展示了MemoryOutputStream::preallocate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTextBetween
String CodeDocument::getTextBetween (const Position& start, const Position& end) const
{
if (end.getPosition() <= start.getPosition())
return {};
auto startLine = start.getLineNumber();
auto endLine = end.getLineNumber();
if (startLine == endLine)
{
if (auto* line = lines [startLine])
return line->line.substring (start.getIndexInLine(), end.getIndexInLine());
return {};
}
MemoryOutputStream mo;
mo.preallocate ((size_t) (end.getPosition() - start.getPosition() + 4));
auto maxLine = jmin (lines.size() - 1, endLine);
for (int i = jmax (0, startLine); i <= maxLine; ++i)
{
auto& line = *lines.getUnchecked(i);
auto len = line.lineLength;
if (i == startLine)
{
auto index = start.getIndexInLine();
mo << line.line.substring (index, len);
}
else if (i == endLine)
{
len = end.getIndexInLine();
mo << line.line.substring (0, len);
}
else
{
mo << line.line;
}
}
return mo.toUTF8();
}
示例2: getTextBetween
String CodeDocument::getTextBetween (const Position& start, const Position& end) const
{
if (end.getPosition() <= start.getPosition())
return String::empty;
const int startLine = start.getLineNumber();
const int endLine = end.getLineNumber();
if (startLine == endLine)
{
CodeDocumentLine* const line = lines [startLine];
return (line == nullptr) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
}
MemoryOutputStream mo;
mo.preallocate (end.getPosition() - start.getPosition() + 4);
const int maxLine = jmin (lines.size() - 1, endLine);
for (int i = jmax (0, startLine); i <= maxLine; ++i)
{
const CodeDocumentLine* line = lines.getUnchecked(i);
int len = line->lineLength;
if (i == startLine)
{
const int index = start.getIndexInLine();
mo << line->line.substring (index, len);
}
else if (i == endLine)
{
len = end.getIndexInLine();
mo << line->line.substring (0, len);
}
else
{
mo << line->line;
}
}
return mo.toString();
}