A convenient vector of strings container with support functions for program argument handling.
More...
#include <string_list.hpp>
|
|
typedef std::vector< std::string >::iterator | iterator |
| |
|
typedef std::vector< std::string >::const_iterator | const_iterator |
| |
|
|
| string_list_t () |
| | Construct an empty list.
|
| |
| | string_list_t (std::initializer_list< std::string > list) |
| | Construct a list from an initializer list. More...
|
| |
| | string_list_t (const std::vector< std::string > &vec) |
| | Construct a list from a vector of strings. More...
|
| |
| | string_list_t (const int argc, const char **argv) |
| | Construct a list from command line arguments. More...
|
| |
| | string_list_t (const std::string &str, const std::string &delimiter) |
| | Construct a list from a delimited string. More...
|
| |
| std::string | join (const std::string &separator, const bool escape=false) const |
| | Join all elements into a single string. More...
|
| |
|
void | clear () |
| | Remove all the elements.
|
| |
|
void | pop_back () |
| | Remove the last element.
|
| |
|
std::string & | operator[] (const size_t idx) |
| |
|
const std::string & | operator[] (const size_t idx) const |
| |
|
string_list_t & | operator+= (const std::string &str) |
| |
|
string_list_t & | operator+= (const string_list_t &list) |
| |
|
string_list_t | operator+ (const std::string &str) const |
| |
|
string_list_t | operator+ (const string_list_t &list) const |
| |
|
size_t | size () const |
| |
|
iterator | begin () |
| |
|
const_iterator | begin () const |
| |
|
const_iterator | cbegin () const |
| |
|
iterator | end () |
| |
|
const_iterator | end () const |
| |
|
const_iterator | cend () const |
| |
|
|
static std::string | escape_arg (const std::string &arg) |
| |
|
static std::string | unescape_arg (const std::string &arg) |
| |
|
|
std::vector< std::string > | m_strings |
| |
A convenient vector of strings container with support functions for program argument handling.
◆ string_list_t() [1/4]
| bcache::string_list_t::string_list_t |
( |
std::initializer_list< std::string > |
list | ) |
|
|
inline |
Construct a list from an initializer list.
- Parameters
-
| list | The strings to add to the string list object. |
◆ string_list_t() [2/4]
| bcache::string_list_t::string_list_t |
( |
const std::vector< std::string > & |
vec | ) |
|
|
inline |
Construct a list from a vector of strings.
- Parameters
-
| vec | The strings to add to the string list object. |
◆ string_list_t() [3/4]
| bcache::string_list_t::string_list_t |
( |
const int |
argc, |
|
|
const char ** |
argv |
|
) |
| |
|
inline |
Construct a list from command line arguments.
- Parameters
-
| argc | Argument count. |
| argv | Argument array. |
- Note
- This is useful for handling command line arguments from a program main() function.
◆ string_list_t() [4/4]
| bcache::string_list_t::string_list_t |
( |
const std::string & |
str, |
|
|
const std::string & |
delimiter |
|
) |
| |
Construct a list from a delimited string.
- Parameters
-
| str | The string. |
| delimiter | The delimiter. |
- Note
- This is useful for splitting a string into a list of strings (e.g. the PATH environment variable).
◆ join()
| std::string bcache::string_list_t::join |
( |
const std::string & |
separator, |
|
|
const bool |
escape = false |
|
) |
| const |
Join all elements into a single string.
- Parameters
-
| separator | The separator to use between strings (e.g. " "). |
| escape | Set this to true to escape each string. |
- Returns
- a string containing all the strings of the list.
- Note
- When string escaping is enabled, the strings are escaped in a way that preserves command line argument information. E.g. strings that contain spaces are surrounded by quotes.
◆ split_args()
| string_list_t bcache::string_list_t::split_args |
( |
const std::string & |
cmd | ) |
|
|
static |
Construct a list of arguments from a string with a shell-like format.
- Parameters
-
- Note
- As far as possible this routine mimics the standard shell behaviour, e.g. w.r.t. escaping and quotation.
The documentation for this class was generated from the following files: