OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::SplitLinesType< STRING > Class Template Reference

#include <splitlines.hpp>

Public Types

enum  Status { S_OKAY , S_EOF , S_ERROR }
 

Public Member Functions

 OPENVPN_EXCEPTION (overflow_error)
 
 OPENVPN_EXCEPTION (moved_error)
 
 SplitLinesType (const STRING &str, const size_t max_line_len_arg=0)
 
bool operator() (const bool trim=true)
 
bool line_overflow () const
 
std::string & line_ref ()
 
const std::string & line_ref () const
 
std::string line_move ()
 
Status next (std::string &ln, const bool trim=true)
 

Private Member Functions

void validate ()
 

Private Attributes

const char * data
 
size_t size
 
const size_t max_line_len
 
size_t index = 0
 
std::string line
 
bool line_valid = false
 
bool overflow = false
 

Detailed Description

template<typename STRING>
class openvpn::SplitLinesType< STRING >

Definition at line 23 of file splitlines.hpp.

Member Enumeration Documentation

◆ Status

template<typename STRING >
enum openvpn::SplitLinesType::Status
Enumerator
S_OKAY 

next line was successfully read

S_EOF 

no further characters are available

S_ERROR 

line was longer than allowed

Definition at line 129 of file splitlines.hpp.

Constructor & Destructor Documentation

◆ SplitLinesType()

template<typename STRING >
openvpn::SplitLinesType< STRING >::SplitLinesType ( const STRING &  str,
const size_t  max_line_len_arg = 0 
)
inline

Initialises SplitLinesType object with pointer to str

Remarks
Note: string/buffer passed to constructor is not locally stored, so it must remain in scope and not be modified during the lifetime of the SplitLines object.
Parameters
strInput string.
max_line_len_argIf not 0, specifies line length that will trigger overflow error.

Definition at line 40 of file splitlines.hpp.

Member Function Documentation

◆ line_move()

template<typename STRING >
std::string openvpn::SplitLinesType< STRING >::line_move ( )
inline

Returns the moved current line.

Throws an exception if there is no line available currently. Throws an exception if line_overflow() returns true. Further calls to line_ref() or line_moved() will throw an exception until operator() is called again.

Definition at line 122 of file splitlines.hpp.

Here is the caller graph for this function:

◆ line_overflow()

template<typename STRING >
bool openvpn::SplitLinesType< STRING >::line_overflow ( ) const
inline

Returns true if max_line_len is greater zero and the current line was longer than max_line_len characters.

Definition at line 85 of file splitlines.hpp.

Here is the caller graph for this function:

◆ line_ref() [1/2]

template<typename STRING >
std::string & openvpn::SplitLinesType< STRING >::line_ref ( )
inline

Returns reference to current line.

Throws an exception if there is no line available currently. Throws an exception if line_overflow() returns true.

Definition at line 96 of file splitlines.hpp.

Here is the caller graph for this function:

◆ line_ref() [2/2]

template<typename STRING >
const std::string & openvpn::SplitLinesType< STRING >::line_ref ( ) const
inline

Returns const reference to current line.

Throws an exception if there is no line available currently. Throws an exception if line_overflow() returns true.

Definition at line 108 of file splitlines.hpp.

◆ next()

template<typename STRING >
Status openvpn::SplitLinesType< STRING >::next ( std::string &  ln,
const bool  trim = true 
)
inline

Read the next line and move it into ln.

Does not throw an exception on overflow but instead returns S_ERROR. If nothing could be read, returns S_EOF. Since the line is moved into the argument, you can't use line_ref() or line_moved() on the object afterwards. In general calls to operator()+line_ref() and next() are not intended to be mixed.

Parameters
lnstring to move the line into.
trimIf true, remove trailing \n or \r\n
Returns
Returns S_OKAY if a line was moved into ln.

Definition at line 151 of file splitlines.hpp.

Here is the caller graph for this function:

◆ OPENVPN_EXCEPTION() [1/2]

template<typename STRING >
openvpn::SplitLinesType< STRING >::OPENVPN_EXCEPTION ( moved_error  )

◆ OPENVPN_EXCEPTION() [2/2]

template<typename STRING >
openvpn::SplitLinesType< STRING >::OPENVPN_EXCEPTION ( overflow_error  )

◆ operator()()

template<typename STRING >
bool openvpn::SplitLinesType< STRING >::operator() ( const bool  trim = true)
inline

Read next line so that it can be accessed with line_ref or line_move.

If max_line_len is greater zero, read at most max_line_len characters.

Parameters
trimIf true, remove trailing \n or \r\n
Returns
Returns true if any characters were read.

Definition at line 55 of file splitlines.hpp.

◆ validate()

template<typename STRING >
void openvpn::SplitLinesType< STRING >::validate ( )
inlineprivate

Definition at line 164 of file splitlines.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ data

template<typename STRING >
const char* openvpn::SplitLinesType< STRING >::data
private

Definition at line 172 of file splitlines.hpp.

◆ index

template<typename STRING >
size_t openvpn::SplitLinesType< STRING >::index = 0
private

Definition at line 175 of file splitlines.hpp.

◆ line

template<typename STRING >
std::string openvpn::SplitLinesType< STRING >::line
private

Definition at line 176 of file splitlines.hpp.

◆ line_valid

template<typename STRING >
bool openvpn::SplitLinesType< STRING >::line_valid = false
private

Definition at line 177 of file splitlines.hpp.

◆ max_line_len

template<typename STRING >
const size_t openvpn::SplitLinesType< STRING >::max_line_len
private

Definition at line 174 of file splitlines.hpp.

◆ overflow

template<typename STRING >
bool openvpn::SplitLinesType< STRING >::overflow = false
private

Definition at line 178 of file splitlines.hpp.

◆ size

template<typename STRING >
size_t openvpn::SplitLinesType< STRING >::size
private

Definition at line 173 of file splitlines.hpp.


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