33template <typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
34std::ostream &
operator<<(std::ostream &in,
const T &item) {
37 return in << +static_cast<typename std::underlying_type<T>::type>(item);
43using enums::operator<<;
54template <
typename T> std::string
join(
const T &v, std::string delim =
",") {
56 auto beg = std::begin(v);
57 auto end = std::end(v);
64 if(!rval.empty() && delim.size() == 1 && rval.back() == delim[0]) {
74 typename =
typename std::enable_if<!std::is_constructible<std::string, Callable>::value>::type>
75std::string
join(
const T &v, Callable func, std::string delim =
",") {
77 auto beg = std::begin(v);
78 auto end = std::end(v);
81 auto nloc = s.tellp();
92template <
typename T> std::string
rjoin(
const T &v, std::string delim =
",") {
94 for(std::size_t start = 0; start < v.size(); start++) {
97 s << v[v.size() - start - 1];
120inline std::string &
trim(std::string &str,
const std::string filter) {
return ltrim(
rtrim(str, filter), filter); }
141inline std::string
trim_copy(
const std::string &str,
const std::string &filter) {
143 return trim(s, filter);
152 return ((c !=
'-') && (
static_cast<unsigned char>(c) > 33));
160 return ((c !=
'=') && (c !=
':') && (c !=
'{') && ((
static_cast<unsigned char>(c) > 32) || c ==
'\t'));
168 return ((str.find_first_of(
'\n') == std::string::npos) && (str.find_first_of(
'\0') == std::string::npos));
173 return (str.empty() || (str.size() == 2 && str[0] ==
'%' && str[1] ==
'%'));
178 return std::all_of(str.begin(), str.end(), [](
char c) { return std::isalpha(c, std::locale()); });
183 std::transform(std::begin(str), std::end(str), std::begin(str), [](
const std::string::value_type &x) {
184 return std::tolower(x, std::locale());
191 str.erase(std::remove(std::begin(str), std::end(str),
'_'), std::end(str));
204 return (flags.find_first_of(
"{!") != std::string::npos);
211 const std::vector<std::string> names,
217template <
typename Callable>
inline std::string
find_and_modify(std::string str, std::string trigger, Callable modify) {
218 std::size_t start_pos = 0;
219 while((start_pos = str.find(trigger, start_pos)) != std::string::npos) {
220 start_pos = modify(str, start_pos);
227CLI11_INLINE std::size_t close_sequence(
const std::string &str, std::size_t start,
char closure_char);
265 char string_char =
'\"',
266 char literal_char =
'\'',
267 bool disable_secondary_array_processing =
false);
272 const std::string &text,
273 std::size_t paragraphWidth,
274 const std::string &linePrefix =
"",
275 bool skipPrefixOnFirstLine =
false);
284#include "impl/StringTools_inl.hpp"
#define CLI11_INLINE
Definition Macros.hpp:176
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:151
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 bool process_quoted_string(std::string &str, char string_char='\"', char literal_char = '\'', bool disable_secondary_array_processing = false)
process a quoted string, remove the quotes and if appropriate handle escaped characters
CLI11_INLINE std::string get_group_separators()
get valid group separators _' + local separator if different
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:190
bool is_separator(const std::string &str)
check if a string is a container segment separator (empty or "%%")
Definition StringTools.hpp:172
std::string find_and_modify(std::string str, std::string trigger, Callable modify)
Definition StringTools.hpp:217
std::string trim_copy(const std::string &str)
Make a copy of the string and then trim it.
Definition StringTools.hpp:123
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:117
bool valid_later_char(T c)
Verify following characters of an option.
Definition StringTools.hpp:156
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:48
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition StringTools.hpp:54
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 & streamOutAsParagraph(std::ostream &out, const std::string &text, std::size_t paragraphWidth, const std::string &linePrefix="", bool skipPrefixOnFirstLine=false)
CLI11_INLINE std::ostream & format_aliases(std::ostream &out, const std::vector< std::string > &aliases, std::size_t wid)
Print subcommand aliases.
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition StringTools.hpp:167
bool isalpha(const std::string &str)
Verify that str consists of letters only.
Definition StringTools.hpp:177
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 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:182
bool has_default_flag_values(const std::string &flags)
check if the flag definitions has possible false flags
Definition StringTools.hpp:203
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:92
CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string)
extract an escaped binary_string
CLI11_INLINE std::string binary_escape_string(const std::string &string_to_escape, bool force=false)
generate a string with all non printable characters escaped to hex codes
Definition StringTools.hpp:30
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 ExtraValidators.hpp:404
std::string ignore_underscore(std::string item)
Helper function to allow ignore_underscore to be passed to IsMember or Transform.
Definition ExtraValidators.hpp:407