33template <typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
34std::ostream &
operator<<(std::ostream &in,
const T &item) {
36 return in << static_cast<typename std::underlying_type<T>::type>(item);
42using enums::operator<<;
53template <
typename T> std::string
join(
const T &v, std::string delim =
",") {
55 auto beg = std::begin(v);
56 auto end = std::end(v);
68 typename =
typename std::enable_if<!std::is_constructible<std::string, Callable>::value>::type>
69std::string
join(
const T &v, Callable func, std::string delim =
",") {
71 auto beg = std::begin(v);
72 auto end = std::end(v);
75 auto nloc = s.tellp();
86template <
typename T> std::string
rjoin(
const T &v, std::string delim =
",") {
88 for(std::size_t start = 0; start < v.size(); start++) {
91 s << v[v.size() - start - 1];
114inline std::string &
trim(std::string &str,
const std::string filter) {
return ltrim(
rtrim(str, filter), filter); }
135inline std::string
trim_copy(
const std::string &str,
const std::string &filter) {
137 return trim(s, filter);
141format_help(std::ostream &out, std::string name,
const std::string &description, std::size_t wid);
149 return ((c !=
'-') && (
static_cast<unsigned char>(c) > 33));
157 return ((c !=
'=') && (c !=
':') && (c !=
'{') && ((
static_cast<unsigned char>(c) > 32) || c ==
'\t'));
165 static const std::string badChars(std::string(
"\n") +
'\0');
166 return (str.find_first_of(badChars) == std::string::npos);
171 static const std::string sep(
"%%");
172 return (str.empty() || str == sep);
177 return std::all_of(str.begin(), str.end(), [](
char c) { return std::isalpha(c, std::locale()); });
182 std::transform(std::begin(str), std::end(str), std::begin(str), [](
const std::string::value_type &x) {
183 return std::tolower(x, std::locale());
190 str.erase(std::remove(std::begin(str), std::end(str),
'_'), std::end(str));
199 return (flags.find_first_of(
"{!") != std::string::npos);
206 const std::vector<std::string> names,
212template <
typename Callable>
inline std::string
find_and_modify(std::string str, std::string trigger, Callable modify) {
213 std::size_t start_pos = 0;
214 while((start_pos = str.find(trigger, start_pos)) != std::string::npos) {
215 start_pos = modify(str, start_pos);
268#include "impl/StringTools_inl.hpp"
#define CLI11_INLINE
Definition: Macros.hpp:131
CLI11_INLINE std::string fix_newlines(const std::string &leader, std::string input)
CLI11_INLINE bool is_binary_escaped_string(const std::string &escaped_string)
CLI11_INLINE void remove_default_flag_values(std::string &flags)
bool valid_first_char(T c)
Definition: StringTools.hpp:148
CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std::string to)
Find and replace a substring with another substring.
CLI11_INLINE std::string add_escaped_characters(const std::string &str)
escape all escapable characters
CLI11_INLINE std::vector< std::string > split(const std::string &s, char delim)
Split a string by a delim.
std::string remove_underscore(std::string str)
remove underscores from a string
Definition: StringTools.hpp:189
bool is_separator(const std::string &str)
check if a string is a container segment separator (empty or "%%")
Definition: StringTools.hpp:170
std::string find_and_modify(std::string str, std::string trigger, Callable modify)
Definition: StringTools.hpp:212
std::string trim_copy(const std::string &str)
Make a copy of the string and then trim it.
Definition: StringTools.hpp:117
CLI11_INLINE std::string & ltrim(std::string &str)
Trim whitespace from left of string.
std::string & trim(std::string &str)
Trim whitespace from string.
Definition: StringTools.hpp:111
CLI11_INLINE std::size_t close_sequence(const std::string &str, std::size_t start, char closure_char)
bool valid_later_char(T c)
Verify following characters of an option.
Definition: StringTools.hpp:153
CLI11_INLINE std::string binary_escape_string(const std::string &string_to_escape)
generate a string with all non printable characters escaped to hex codes
CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset)
CLI11_INLINE std::vector< std::string > split_up(std::string str, char delimiter='\0')
constexpr int expected_max_vector_size
Definition: StringTools.hpp:47
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:53
CLI11_INLINE std::string & remove_quotes(std::string &str)
remove quotes at the front and back of a string either '"' or '\''
CLI11_INLINE std::ostream & format_aliases(std::ostream &out, const std::vector< std::string > &aliases, std::size_t wid)
Print subcommand aliases.
CLI11_INLINE std::ostream & format_help(std::ostream &out, std::string name, const std::string &description, std::size_t wid)
Print a two part "help" string.
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition: StringTools.hpp:164
bool isalpha(const std::string &str)
Verify that str consists of letters only.
Definition: StringTools.hpp:176
CLI11_INLINE std::ptrdiff_t find_member(std::string name, const std::vector< std::string > names, bool ignore_case=false, bool ignore_underscore=false)
Check if a string is a member of a list of strings and optionally ignore case or ignore underscores.
CLI11_INLINE bool has_escapable_character(const std::string &str)
detect if a string has escapable characters
CLI11_INLINE std::string get_environment_value(const std::string &env_name)
get the value of an environmental variable or empty string if empty
CLI11_INLINE bool process_quoted_string(std::string &str, char string_char='\"', char literal_char = '\'')
process a quoted string, remove the quotes and if appropriate handle escaped characters
CLI11_INLINE bool valid_name_string(const std::string &str)
Verify an option/subcommand name.
CLI11_INLINE std::string remove_escaped_characters(const std::string &str)
replace the escaped characters with their equivalent
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition: StringTools.hpp:181
bool has_default_flag_values(const std::string &flags)
check if the flag definitions has possible false flags
Definition: StringTools.hpp:198
CLI11_INLINE std::string & rtrim(std::string &str)
Trim whitespace from right of string.
std::string rjoin(const T &v, std::string delim=",")
Join a string in reverse order.
Definition: StringTools.hpp:86
CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string)
extract an escaped binary_string
std::ostream & operator<<(std::ostream &in, const T &item)
output streaming for enumerations
Definition: StringTools.hpp:34
std::string ignore_case(std::string item)
Helper function to allow ignore_case to be passed to IsMember or Transform.
Definition: Validators.hpp:695
std::string ignore_underscore(std::string item)
Helper function to allow ignore_underscore to be passed to IsMember or Transform.
Definition: Validators.hpp:698