C++ Utilities
5.36.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Toggle main menu visibility
Loading...
Searching...
No Matches
io
buffersearch.cpp
Go to the documentation of this file.
1
#include "
./buffersearch.h
"
2
3
using namespace
std
;
4
5
namespace
CppUtilities
{
6
24
32
const
std::string_view::value_type *
BufferSearch::process
(
const
std::string_view::value_type *buffer, std::size_t bufferSize)
33
{
34
if
(m_hasResult || (!m_giveUpTerm.empty() && m_giveUpTermIterator == m_giveUpTerm.end())) {
35
return
nullptr
;
36
}
37
for
(
auto
i
= buffer, end = buffer + bufferSize;
i
!= end; ++
i
) {
38
const
auto
currentChar = *
i
;
39
if
(m_searchTermIterator == m_searchTerm.end()) {
40
if
(m_terminationChars.empty()) {
41
m_hasResult =
true
;
42
}
else
{
43
for
(
const
auto
&terminationChar : m_terminationChars) {
44
if
(currentChar == terminationChar) {
45
m_hasResult =
true
;
46
break
;
47
}
48
}
49
}
50
if
(m_hasResult) {
51
if
(m_callback) {
52
m_callback(*
this
, std::move(m_result));
53
}
54
return
i
;
55
}
56
m_result += currentChar;
57
continue
;
58
}
59
if
(currentChar == *m_searchTermIterator) {
60
++m_searchTermIterator;
61
}
else
{
62
m_searchTermIterator = m_searchTerm.begin();
63
}
64
if
(m_giveUpTerm.empty()) {
65
continue
;
66
}
67
if
(currentChar == *m_giveUpTermIterator) {
68
++m_giveUpTermIterator;
69
}
else
{
70
m_giveUpTermIterator = m_giveUpTerm.begin();
71
}
72
}
73
return
nullptr
;
74
}
75
80
void
BufferSearch::operator()
(
const
std::string_view::value_type *buffer, std::size_t bufferSize)
81
{
82
process
(buffer, bufferSize);
83
}
84
88
void
BufferSearch::reset
()
89
{
90
m_searchTermIterator = m_searchTerm.begin();
91
m_giveUpTermIterator = m_giveUpTerm.begin();
92
m_terminationTermIterator = m_terminationTerm.begin();
93
m_hasResult =
false
;
94
m_result.clear();
95
}
96
97
}
// namespace CppUtilities
buffersearch.h
CppUtilities::BufferSearch::operator()
void operator()(std::string_view buffer)
Processes the specified buffer.
Definition
buffersearch.h:60
CppUtilities::BufferSearch::process
const std::string_view::value_type * process(std::string_view buffer)
Processes the specified buffer.
Definition
buffersearch.h:78
CppUtilities::BufferSearch::reset
void reset()
Resets the search to its initial state (assuming no characters of the search term or give-up term hav...
Definition
buffersearch.cpp:88
CppUtilities
Contains all utilities provided by the c++utilities library.
Definition
argumentparser.h:18
std
STL namespace.
i
constexpr int i
Definition
traitstests.cpp:106
Generated on
for C++ Utilities by
1.18.0