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.h
Go to the documentation of this file.
1
#ifndef IOUTILITIES_BUFFER_SEARCH_H
2
#define IOUTILITIES_BUFFER_SEARCH_H
3
4
#include "
../global.h
"
5
6
#include <array>
7
#include <functional>
8
#include <memory>
9
#include <string>
10
#include <string_view>
11
12
namespace
CppUtilities
{
13
14
class
CPP_UTILITIES_EXPORT
BufferSearch
{
15
public
:
16
using
CallbackType
= std::function<void(
BufferSearch
&, std::string &&)>;
17
BufferSearch
(std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm,
CallbackType
&&callback);
18
void
operator()
(std::string_view buffer);
19
void
operator()
(
const
std::string_view::value_type *buffer, std::size_t bufferSize);
20
template
<std::
size_t
bufferCapacity>
21
void
operator()
(std::shared_ptr<std::array<std::string_view::value_type, bufferCapacity>> buffer, std::size_t bufferSize);
22
const
std::string_view::value_type *
process
(std::string_view buffer);
23
const
std::string_view::value_type *
process
(
const
std::string_view::value_type *buffer, std::size_t bufferSize);
24
void
reset
();
25
std::string &
result
();
26
const
std::string &
result
()
const
;
27
28
private
:
29
const
std::string_view m_searchTerm;
30
const
std::string_view m_terminationChars;
31
const
std::string_view m_terminationTerm;
32
const
std::string_view m_giveUpTerm;
33
const
CallbackType
m_callback;
34
std::string_view::const_iterator m_searchTermIterator;
35
std::string_view::const_iterator m_giveUpTermIterator;
36
std::string_view::const_iterator m_terminationTermIterator;
37
std::string m_result;
38
bool
m_hasResult;
39
};
40
44
inline
BufferSearch::BufferSearch
(
45
std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm,
CallbackType
&&callback)
46
: m_searchTerm(searchTerm)
47
, m_terminationChars(terminationChars)
48
, m_giveUpTerm(giveUpTerm)
49
, m_callback(
std
::move(callback))
50
, m_searchTermIterator(m_searchTerm.begin())
51
, m_giveUpTermIterator(m_giveUpTerm.begin())
52
, m_terminationTermIterator(m_terminationTerm.begin())
53
, m_hasResult(false)
54
{
55
}
56
60
inline
void
BufferSearch::operator()
(std::string_view buffer)
61
{
62
(*this)(buffer.data(), buffer.size());
63
}
64
68
template
<std::
size_t
bufferCapacity>
69
inline
void
BufferSearch::operator()
(std::shared_ptr<std::array<std::string_view::value_type, bufferCapacity>> buffer, std::size_t bufferSize)
70
{
71
(*this)(buffer->data(), bufferSize);
72
}
73
78
inline
const
std::string_view::value_type *
BufferSearch::process
(std::string_view buffer)
79
{
80
return
process
(buffer.data(), buffer.size());
81
}
82
86
inline
std::string &
BufferSearch::result
()
87
{
88
return
m_result;
89
}
90
94
inline
const
std::string &
BufferSearch::result
()
const
95
{
96
return
m_result;
97
}
98
99
}
// namespace CppUtilities
100
101
#endif
// IOUTILITIES_BUFFER_SEARCH_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::CallbackType
std::function< void(BufferSearch &, std::string &&)> CallbackType
Definition
buffersearch.h:16
CppUtilities::BufferSearch::BufferSearch
BufferSearch(std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm, CallbackType &&callback)
Constructs a new BufferSearch.
Definition
buffersearch.h:44
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::BufferSearch::result
std::string & result()
Returns the search result at this point.
Definition
buffersearch.h:86
global.h
CPP_UTILITIES_EXPORT
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Definition
global.h:14
CppUtilities
Contains all utilities provided by the c++utilities library.
Definition
argumentparser.h:18
std
STL namespace.
Generated on
for C++ Utilities by
1.18.0