Option++  2.0
C++ library for reading command-line options
Functions
optionpp::utility Namespace Reference

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 &quotes="\"\'", 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...
 

Detailed Description

Namespace for utility functions.

Function Documentation

◆ is_space()

bool optionpp::utility::is_space ( char  c)

Determine if a character is whitespace.

Parameters
cCharacter to check.
Returns
True if c is a whitespace character and false otherwise.

◆ is_substr_at_pos()

bool optionpp::utility::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.

This simple function checks str to see if substr is at the specified position. For example, the call

is_substr_at_pos("Hello world", "wor", 6)

should return true because the string "wor" does occur within "Hello world" at index 6.

Parameters
strString in which substring is to be found.
substrSubstring to match.
posThe position in str at which substr should be found.
Returns
True if substr occurs at index pos in str, and false otherwise.

◆ split()

template<typename OutputIt >
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.

Template Parameters
OutputItType of output iterator (typically deduced).
Parameters
strThe string to split.
destAn output iterator specifying where the tokens should be written.
delimsString containing the characters to be used as delimiters.
quotesString containing the allowed quote characters.
escape_charCharacter to use as escape character.
allow_emptyIf true, consecutive delimiters will produce empty substrings.

◆ wrap_line()

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.

Parameters
strText to wrap.
line_lenMaximum desired line length, if any.
indentNumber of spaces to indent each line.
first_line_indentNumber of spaces to indent the first line.
Returns
Resulting word-wrapped string.

◆ wrap_text() [1/2]

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.

Parameters
strText to wrap.
line_lenMaximum desired line length, if any.
indentNumber of spaces to indent each line after the first one.
first_line_indentNumber of spaces to indent the first line.
Returns
Resulting word-wrapped string.

◆ wrap_text() [2/2]

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.

Parameters
strText to wrap.
line_lenMaximum desired line length, if any.
indentNumber of spaces to indent each line.
Returns
Resulting word-wrapped string.
optionpp::utility::is_substr_at_pos
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.
Definition: utility.cpp:148