Option++
2.0
C++ library for reading command-line options
|
Namespace for utility functions. More...
Functions | |
template<typename OutputIt > | |
void | split (const std::string &str, OutputIt dest, const std::string &delims=" \t\n\r", const std::string "es="\"\'", char escape_char='\\', bool allow_empty=false) |
Split a string over delimiters into substrings. More... | |
std::string | wrap_text (const std::string &str, int line_len=79, int indent=0) |
Perform word-wrapping on a string. More... | |
std::string | wrap_text (const std::string &str, int line_len, int indent, int first_line_indent) |
Perform word-wrapping on a string. More... | |
bool | is_substr_at_pos (const std::string &str, const std::string &substr, std::string::size_type pos=0) noexcept |
Determine if a string occurs within another string at a particular position. More... | |
bool | is_space (char c) |
Determine if a character is whitespace. More... | |
std::string | wrap_line (const std::string &str, int line_len, int indent, int first_line_indent) |
Performs word-wrapping for a single line of text. More... | |
Namespace for utility functions.
bool optionpp::utility::is_space | ( | char | c | ) |
Determine if a character is whitespace.
c | Character to check. |
c
is a whitespace character and false otherwise.
|
noexcept |
Determine if a string occurs within another string at a particular position.
This simple function checks str
to see if substr
is at the specified position. For example, the call
should return true because the string "wor" does occur within "Hello world" at index 6.
str | String in which substring is to be found. |
substr | Substring to match. |
pos | The position in str at which substr should be found. |
substr
occurs at index pos
in str
, and false otherwise. void optionpp::utility::split | ( | const std::string & | str, |
OutputIt | dest, | ||
const std::string & | delims = " \t\n\r" , |
||
const std::string & | quotes = "\"\'" , |
||
char | escape_char = '\\' , |
||
bool | allow_empty = false |
||
) |
Split a string over delimiters into substrings.
Splits a string into substring components using delims
as token delimiters. If allow_empty
is false, then empty components are skipped, unless enclosed in quotes.
Delimiters appearing within quote characters (as specified by the quotes
parameter) are ignored. Within quotes, an escape character can be used to escape a quote symbol.
OutputIt | Type of output iterator (typically deduced). |
str | The string to split. |
dest | An output iterator specifying where the tokens should be written. |
delims | String containing the characters to be used as delimiters. |
quotes | String containing the allowed quote characters. |
escape_char | Character to use as escape character. |
allow_empty | If true, consecutive delimiters will produce empty substrings. |
std::string optionpp::utility::wrap_line | ( | const std::string & | str, |
int | line_len, | ||
int | indent, | ||
int | first_line_indent | ||
) |
Performs word-wrapping for a single line of text.
This is a helper function for wrap_text
.
str | Text to wrap. |
line_len | Maximum desired line length, if any. |
indent | Number of spaces to indent each line. |
first_line_indent | Number of spaces to indent the first line. |
std::string optionpp::utility::wrap_text | ( | const std::string & | str, |
int | line_len, | ||
int | indent, | ||
int | first_line_indent | ||
) |
Perform word-wrapping on a string.
This function will take each line in the string and insert additional newlines in order to limit the maximum line length. Lines are only split between words unless there is no other choice.
To get an unlimited line length, set line_len <= 0
.
The text can also be indented a certain number of spaces. The total line length includes the indentation.
str | Text to wrap. |
line_len | Maximum desired line length, if any. |
indent | Number of spaces to indent each line after the first one. |
first_line_indent | Number of spaces to indent the first line. |
std::string optionpp::utility::wrap_text | ( | const std::string & | str, |
int | line_len = 79 , |
||
int | indent = 0 |
||
) |
Perform word-wrapping on a string.
This function will take each line in the string and insert additional newlines in order to limit the maximum line length. Lines are only split between words unless there is no other choice.
To get an unlimited line length, set line_len <= 0
.
The text can also be indented a certain number of spaces. The total line length includes the indentation.
str | Text to wrap. |
line_len | Maximum desired line length, if any. |
indent | Number of spaces to indent each line. |