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<<;
47constexpr int expected_max_vector_size{1 << 29};
50CLI11_INLINE std::vector<std::string> split(
const std::string &s,
char delim);
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];
99CLI11_INLINE std::string <rim(std::string &str);
102CLI11_INLINE std::string <rim(std::string &str,
const std::string &filter);
105CLI11_INLINE std::string &rtrim(std::string &str);
108CLI11_INLINE std::string &rtrim(std::string &str,
const std::string &filter);
111inline std::string &trim(std::string &str) {
return ltrim(rtrim(str)); }
114inline std::string &trim(std::string &str,
const std::string filter) {
return ltrim(rtrim(str, filter), filter); }
117inline std::string trim_copy(
const std::string &str) {
123CLI11_INLINE std::string &remove_quotes(std::string &str);
126CLI11_INLINE
void remove_quotes(std::vector<std::string> &args);
132CLI11_INLINE std::string fix_newlines(
const std::string &leader, std::string input);
135inline std::string trim_copy(
const std::string &str,
const std::string &filter) {
137 return trim(s, filter);
140CLI11_INLINE std::ostream &
141format_help(std::ostream &out, std::string name,
const std::string &description, std::size_t wid);
144CLI11_INLINE std::ostream &format_aliases(std::ostream &out,
const std::vector<std::string> &aliases, std::size_t wid);
148template <
typename T>
bool valid_first_char(T c) {
149 return ((c !=
'-') && (
static_cast<unsigned char>(c) > 33));
153template <
typename T>
bool valid_later_char(T c) {
157 return ((c !=
'=') && (c !=
':') && (c !=
'{') && ((
static_cast<unsigned char>(c) > 32) || c ==
'\t'));
161CLI11_INLINE
bool valid_name_string(
const std::string &str);
164inline bool valid_alias_name_string(
const std::string &str) {
165 static const std::string badChars(std::string(
"\n") +
'\0');
166 return (str.find_first_of(badChars) == std::string::npos);
170inline bool is_separator(
const std::string &str) {
171 static const std::string sep(
"%%");
172 return (str.empty() || str == sep);
176inline bool isalpha(
const std::string &str) {
177 return std::all_of(str.begin(), str.end(), [](
char c) { return std::isalpha(c, std::locale()); });
181inline std::string to_lower(std::string str) {
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());
189inline std::string remove_underscore(std::string str) {
190 str.erase(std::remove(std::begin(str), std::end(str),
'_'), std::end(str));
195CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std::string to);
198inline bool has_default_flag_values(
const std::string &flags) {
199 return (flags.find_first_of(
"{!") != std::string::npos);
202CLI11_INLINE
void remove_default_flag_values(std::string &flags);
205CLI11_INLINE std::ptrdiff_t find_member(std::string name,
206 const std::vector<std::string> names,
207 bool ignore_case =
false,
208 bool ignore_underscore =
false);
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);
222CLI11_INLINE std::size_t close_sequence(
const std::string &str, std::size_t start,
char closure_char);
226CLI11_INLINE std::vector<std::string> split_up(std::string str,
char delimiter =
'\0');
229CLI11_INLINE std::string get_environment_value(
const std::string &env_name);
235CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset);
240CLI11_INLINE
bool has_escapable_character(
const std::string &str);
245CLI11_INLINE std::string add_escaped_characters(
const std::string &str);
248CLI11_INLINE std::string remove_escaped_characters(
const std::string &str);
251CLI11_INLINE std::string binary_escape_string(
const std::string &string_to_escape);
253CLI11_INLINE
bool is_binary_escaped_string(
const std::string &escaped_string);
256CLI11_INLINE std::string extract_binary_string(
const std::string &escaped_string);
259CLI11_INLINE
bool process_quoted_string(std::string &str,
char string_char =
'\"',
char literal_char =
'\'');
268#include "impl/StringTools_inl.hpp"