C++ Utilities: CppUtilities::BufferSearch Class Reference

C++ Utilities 5.34.0 Useful C++ classes and routines such as argument parser, IO and conversion utilities

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
CppUtilities::BufferSearch Class Reference

The BufferSearch struct invokes a callback if an initially given search term occurs in consecutively provided buffers. More...

`#include <buffersearch.h>`

## Public Types
using | CallbackType = std::function<void(BufferSearch &, std::string &&)>

## Public Member Functions
| BufferSearch (std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm, CallbackType &&callback)
| Constructs a new BufferSearch.
void | operator() (std::string_view buffer)
| Processes the specified buffer.
void | operator() (const std::string_view::value_type *buffer, std::size_t bufferSize)
| Processes the specified buffer.
template<std::size_t bufferCapacity>
void | operator() (std::shared_ptr< std::array< std::string_view::value_type, bufferCapacity > > buffer, std::size_t bufferSize)
| Processes the specified buffer which is a shared array with fixed.
const std::string_view::value_type * | process (std::string_view buffer)
| Processes the specified buffer.
const std::string_view::value_type * | process (const std::string_view::value_type *buffer, std::size_t bufferSize)
| Processes the specified buffer.
void | reset ()
| Resets the search to its initial state (assuming no characters of the search term or give-up term have been found yet).
std::string & | result ()
| Returns the search result at this point.
const std::string & | result () const
| Returns the search result at this point.

## Detailed Description

The BufferSearch struct invokes a callback if an initially given search term occurs in consecutively provided buffers.

Remarks
  - The class works without making internal copies of the specified buffers, except for the search result.
  - The callback is invoked after the search term has been found and one of the specified termination characters occurred. The search result is passed to the callback.
  - The "search result" is the data after the last character of the search term and before any of the specified termination characters.
  - If no termination characters are specified, the callback is invoked directly after the search term occurred (with an empty search result).
  - If the specified give-up term has occurred, operator() will exit early and the specified callback will not be invoked anymore.
  - If the callback has been invoked, operator() will exit early and the callback will not be invoked anymore (even if the search term occurs again). Call reset() after consuming the result within the callback to continue the search.

Definition at line 14 of file buffersearch.h.

## Member Typedef Documentation

## ◆ CallbackType

using CppUtilities::BufferSearch::CallbackType = std::function<void(BufferSearch &, std::string &&)>

Definition at line 16 of file buffersearch.h.

## Constructor & Destructor Documentation

## ◆ BufferSearch()

CppUtilities::BufferSearch::BufferSearch | ( | std::string_view | searchTerm,
|  | std::string_view | terminationChars,
|  | std::string_view | giveUpTerm,
|  | CallbackType && | callback )
| inline

Constructs a new BufferSearch.

Might be overloaded in the future.

Definition at line 44 of file buffersearch.h.

## Member Function Documentation

## ◆ operator()() [1/3]

void CppUtilities::BufferSearch::operator() | ( | const std::string_view::value_type * | buffer,
|  | std::size_t | bufferSize )

Processes the specified buffer.

Invokes the callback according to the remarks mentioned in the class documentation.

Todo
  Make inline in v6.

Definition at line 80 of file buffersearch.cpp.

## ◆ operator()() [2/3]

template<std::size_t bufferCapacity>

void CppUtilities::BufferSearch::operator() | ( | std::shared_ptr< std::array< std::string_view::value_type, bufferCapacity > > | buffer,
|  | std::size_t | bufferSize )
| inline

Processes the specified buffer which is a shared array with fixed.

Template Parameters

  bufferCapacity. | Invokes the callback according to the remarks mentioned in the class documentation.

Definition at line 69 of file buffersearch.h.

## ◆ operator()() [3/3]

void CppUtilities::BufferSearch::operator() | ( | std::string_view | buffer | ) |
| inline

Processes the specified buffer.

Invokes the callback according to the remarks mentioned in the class documentation.

Definition at line 60 of file buffersearch.h.

## ◆ process() [1/2]

const std::string_view::value_type * CppUtilities::BufferSearch::process | ( | const std::string_view::value_type * | buffer,
|  | std::size_t | bufferSize )

Processes the specified buffer.

Invokes the callback according to the remarks mentioned in the class documentation.

Returns
  - Returns the offset in buffer after the search term and search result. This is the first character after the search term if no termination characters have been specified; otherwiese it is the offset of the termination character.
  - Returns nullptr if the search term could not be found.

Definition at line 32 of file buffersearch.cpp.

## ◆ process() [2/2]

const std::string_view::value_type * CppUtilities::BufferSearch::process | ( | std::string_view | buffer | ) |
| inline

Processes the specified buffer.

Invokes the callback according to the remarks mentioned in the class documentation.

Returns
  See other overload for details.

Definition at line 78 of file buffersearch.h.

## ◆ reset()

void CppUtilities::BufferSearch::reset | ( |  | ) |

Resets the search to its initial state (assuming no characters of the search term or give-up term have been found yet).

Definition at line 88 of file buffersearch.cpp.

## ◆ result() [1/2]

std::string & CppUtilities::BufferSearch::result | ( |  | ) |
| inline

Returns the search result at this point.

Definition at line 86 of file buffersearch.h.

## ◆ result() [2/2]

const std::string & CppUtilities::BufferSearch::result | ( |  | ) | const
| inline

Returns the search result at this point.

Definition at line 94 of file buffersearch.h.

The documentation for this class was generated from the following files:

- io/buffersearch.h
- io/buffersearch.cpp