Allow using `BufferSearch` without callback
* Allow callback to be an empty `std::function` * Add function to access result
This commit is contained in:
parent
262a3d25a7
commit
1a968a1b5f
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue