1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:07:35 +00:00

LibMarkdown: Add LineIterator

LineIterator wraps a vector's ConstIterator, to provide an iterator that
can work on indented container blocks (like lists and blockquotes).
This commit is contained in:
Peter Elliott 2021-09-19 11:14:18 -06:00 committed by Ali Mohammad Pur
parent cd560d3ae3
commit 10f6f6a723
16 changed files with 139 additions and 21 deletions

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibMarkdown/LineIterator.h>
namespace Markdown {
bool LineIterator::is_indented(StringView const& line) const
{
if (line.is_whitespace())
return true;
if (line.length() < m_indent)
return false;
for (size_t i = 0; i < m_indent; ++i) {
if (line[i] != ' ')
return false;
}
return true;
}
bool LineIterator::is_end() const
{
return m_iterator.is_end() || (!m_ignore_prefix_mode && !is_indented(*m_iterator));
}
StringView LineIterator::operator*() const
{
VERIFY(m_ignore_prefix_mode || is_indented(*m_iterator));
if (m_iterator->is_whitespace())
return *m_iterator;
return m_iterator->substring_view(m_indent);
}
}