C++ Utilities  5.11.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
buffersearch.cpp
Go to the documentation of this file.
1 #include "./buffersearch.h"
2 
3 using namespace std;
4 
5 namespace CppUtilities {
6 
27 void 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) {
39  if (currentChar == terminationChar) {
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 
71 void BufferSearch::reset()
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
Contains all utilities provides by the c++utilities library.
constexpr int i