Repository: microsoft/terminal
File: src/buffer/out/textBuffer.cpp (C++)

Code before:

    results = std::decay_t<decltype(results)>{};

    // All whitespace strings would match the not-yet-written parts of the TextBuffer which would be weird.
    if (allWhitespace(needle) || rowBeg >= rowEnd)
    {
        return true;
    }

    auto text = ICU::UTextFromTextBuffer(*this, rowBeg, rowEnd);

    uint32_t icuFlags{ 0 };
    WI_SetFlagIf(icuFlags, UREGEX_CASE_INSENSITIVE, WI_IsFlagSet(flags, SearchFlag::CaseInsensitive));

    if (WI_IsFlagSet(flags, SearchFlag::RegularExpression))
    {
        WI_SetFlag(icuFlags, UREGEX_MULTILINE);
    }
    else
    {
        WI_SetFlag(icuFlags, UREGEX_LITERAL);
    }

    UErrorCode status = U_ZERO_ERROR;
    const auto re = ICU::CreateRegex(needle, icuFlags, &status);
    if (status != U_ZERO_ERROR)
    {
        return false;
    }

    uregex_setUText(re.get(), &text, &status);

    if (uregex_find(re.get(), -1, &status))
    {
        do
        {
            results.emplace_back(ICU::BufferRangeFromMatch(&text, re.get()));
        } while (uregex_findNext(re.get(), &status));
    }

    return true;
}

// Collect up all the rows that were marked, and the data marked on that row.
// This is what should be used for hot paths, like updating the scrollbar.
std::vector<ScrollMark> TextBuffer::GetMarkRows() const
{
    std::vector<ScrollMark> marks;
    const auto bottom = _estimateOffsetOfLastCommittedRow();
    for (auto y = 0; y <= bottom; y++)
    {

Review comment (suggestion):
Negative statuses denote warnings or infos. You should use `status > U_ZERO_ERROR` here.

Code after:
    rowEnd = std::min(rowEnd, _estimateOffsetOfLastCommittedRow() + 1);

    std::vector<til::point_span> results;

    // All whitespace strings would match the not-yet-written parts of the TextBuffer which would be weird.
    if (allWhitespace(needle) || rowBeg >= rowEnd)
    {
        return results;
    }

    auto text = ICU::UTextFromTextBuffer(*this, rowBeg, rowEnd);

    uint32_t icuFlags{ 0 };
    WI_SetFlagIf(icuFlags, UREGEX_CASE_INSENSITIVE, WI_IsFlagSet(flags, SearchFlag::CaseInsensitive));

    if (WI_IsFlagSet(flags, SearchFlag::RegularExpression))
    {
        WI_SetFlag(icuFlags, UREGEX_MULTILINE);
    }
    else
    {
        WI_SetFlag(icuFlags, UREGEX_LITERAL);
    }

    UErrorCode status = U_ZERO_ERROR;
    const auto re = ICU::CreateRegex(needle, icuFlags, &status);
    if (status > U_ZERO_ERROR)
    {
        return std::nullopt;
    }

    uregex_setUText(re.get(), &text, &status);

    if (uregex_find(re.get(), -1, &status))
    {
        do
        {
            results.emplace_back(ICU::BufferRangeFromMatch(&text, re.get()));
        } while (uregex_findNext(re.get(), &status));
    }

    return results;
}

// Collect up all the rows that were marked, and the data marked on that row.
// This is what should be used for hot paths, like updating the scrollbar.
std::vector<ScrollMark> TextBuffer::GetMarkRows() const
{
    std::vector<ScrollMark> marks;
    const auto bottom = _estimateOffsetOfLastCommittedRow();
    for (auto y = 0; y <= bottom; y++)