Allow using `BufferSearch` without callback

* Allow callback to be an empty `std::function`
* Add function to access result
This commit is contained in:
Martchus 2024-06-21 22:53:49 +02:00
parent 262a3d25a7
commit 1a968a1b5f
2 changed files with 21 additions and 1 deletions

View File

@ -48,7 +48,9 @@ const std::string_view::value_type *BufferSearch::process(const std::string_view
}
}
if (m_hasResult) {
m_callback(*this, std::move(m_result));
if (m_callback) {
m_callback(*this, std::move(m_result));
}
return i;
}
m_result += currentChar;

View File

@ -23,6 +23,8 @@ public:
const std::string_view::value_type *process(std::string_view buffer);
const std::string_view::value_type *process(const std::string_view::value_type *buffer, std::size_t bufferSize);
void reset();
std::string &result();
const std::string &result() const;
private:
const std::string_view m_searchTerm;
@ -79,6 +81,22 @@ inline const std::string_view::value_type *BufferSearch::process(std::string_vie
return process(buffer.data(), buffer.size());
}
/*!
* \brief Returns the search result at this point.
*/
inline std::string &BufferSearch::result()
{
return m_result;
}
/*!
* \brief Returns the search result at this point.
*/
inline const std::string &BufferSearch::result() const
{
return m_result;
}
} // namespace CppUtilities
#endif // IOUTILITIES_BUFFER_SEARCH_H