C++ Utilities 5.24.7
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
buffersearch.cpp
Go to the documentation of this file.
1#include "./buffersearch.h"
2
3using namespace std;
4
5namespace CppUtilities {
6
27void BufferSearch::operator()(const std::string_view::value_type *buffer, std::size_t bufferSize)
28{
29 if (m_hasResult || (!m_giveUpTerm.empty() && m_giveUpTermIterator == m_giveUpTerm.end())) {
30 return;
31 }
32 for (auto i = buffer, end = buffer + bufferSize; i != end; ++i) {
33 const auto currentChar = *i;
34 if (m_searchTermIterator == m_searchTerm.end()) {
35 if (m_terminationChars.empty()) {
36 m_hasResult = true;
37 } else {
38 for (const auto &terminationChar : m_terminationChars) {
40 m_hasResult = true;
41 break;
42 }
43 }
44 }
45 if (m_hasResult) {
46 m_callback(*this, std::move(m_result));
47 return;
48 }
49 m_result += currentChar;
50 continue;
51 }
52 if (currentChar == *m_searchTermIterator) {
53 ++m_searchTermIterator;
54 } else {
55 m_searchTermIterator = m_searchTerm.begin();
56 }
57 if (m_giveUpTerm.empty()) {
58 continue;
59 }
60 if (currentChar == *m_giveUpTermIterator) {
61 ++m_giveUpTermIterator;
62 } else {
63 m_giveUpTermIterator = m_giveUpTerm.begin();
64 }
65 }
66}
67
72{
73 m_searchTermIterator = m_searchTerm.begin();
74 m_giveUpTermIterator = m_giveUpTerm.begin();
75 m_terminationTermIterator = m_terminationTerm.begin();
76 m_hasResult = false;
77 m_result.clear();
78}
79
80} // namespace CppUtilities
void operator()(std::string_view buffer)
Processes the specified buffer.
void reset()
Resets the search to its initial state (assuming no characters of the search term or give-up term hav...
Contains all utilities provides by the c++utilities library.
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
STL namespace.
constexpr int i