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


C++ MemoryOutputStream::preallocate方法代码示例

本文整理汇总了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();
}
开发者ID:christophhart,项目名称:HISE,代码行数:44,代码来源:juce_CodeDocument.cpp

示例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();
}
开发者ID:SonicPotions,项目名称:editor,代码行数:42,代码来源:juce_CodeDocument.cpp


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