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);
63 if(!rval.empty() && delim.size() == 1 && rval.back() == delim[0]) {
73 typename =
typename std::enable_if<!std::is_constructible<std::string, Callable>::value>::type>
74std::string join(
const T &v, Callable func, std::string delim =
",") {
76 auto beg = std::begin(v);
77 auto end = std::end(v);
80 auto nloc = s.tellp();
91template <
typename T> std::string rjoin(
const T &v, std::string delim =
",") {
93 for(std::size_t start = 0; start < v.size(); start++) {
96 s << v[v.size() - start - 1];
104CLI11_INLINE std::string <rim(std::string &str);
107CLI11_INLINE std::string <rim(std::string &str,
const std::string &filter);
110CLI11_INLINE std::string &rtrim(std::string &str);
113CLI11_INLINE std::string &rtrim(std::string &str,
const std::string &filter);
116inline std::string &trim(std::string &str) {
return ltrim(rtrim(str)); }
119inline std::string &trim(std::string &str,
const std::string filter) {
return ltrim(rtrim(str, filter), filter); }
122inline std::string trim_copy(
const std::string &str) {
128CLI11_INLINE std::string &remove_quotes(std::string &str);
131CLI11_INLINE
void remove_quotes(std::vector<std::string> &args);
137CLI11_INLINE std::string fix_newlines(
const std::string &leader, std::string input);
140inline std::string trim_copy(
const std::string &str,
const std::string &filter) {
142 return trim(s, filter);
146CLI11_INLINE std::ostream &format_aliases(std::ostream &out,
const std::vector<std::string> &aliases, std::size_t wid);
150template <
typename T>
bool valid_first_char(T c) {
151 return ((c !=
'-') && (
static_cast<unsigned char>(c) > 33));
155template <
typename T>
bool valid_later_char(T c) {
159 return ((c !=
'=') && (c !=
':') && (c !=
'{') && ((
static_cast<unsigned char>(c) > 32) || c ==
'\t'));
163CLI11_INLINE
bool valid_name_string(
const std::string &str);
166inline bool valid_alias_name_string(
const std::string &str) {
167 static const std::string badChars(std::string(
"\n") +
'\0');
168 return (str.find_first_of(badChars) == std::string::npos);
172inline bool is_separator(
const std::string &str) {
173 static const std::string sep(
"%%");
174 return (str.empty() || str == sep);
178inline bool isalpha(
const std::string &str) {
179 return std::all_of(str.begin(), str.end(), [](
char c) { return std::isalpha(c, std::locale()); });
183inline std::string to_lower(std::string str) {
184 std::transform(std::begin(str), std::end(str), std::begin(str), [](
const std::string::value_type &x) {
185 return std::tolower(x, std::locale());
191inline std::string remove_underscore(std::string str) {
192 str.erase(std::remove(std::begin(str), std::end(str),
'_'), std::end(str));
197CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std::string to);
200inline bool has_default_flag_values(
const std::string &flags) {
201 return (flags.find_first_of(
"{!") != std::string::npos);
204CLI11_INLINE
void remove_default_flag_values(std::string &flags);
207CLI11_INLINE std::ptrdiff_t find_member(std::string name,
208 const std::vector<std::string> names,
209 bool ignore_case =
false,
210 bool ignore_underscore =
false);
214template <
typename Callable>
inline std::string find_and_modify(std::string str, std::string trigger, Callable modify) {
215 std::size_t start_pos = 0;
216 while((start_pos = str.find(trigger, start_pos)) != std::string::npos) {
217 start_pos = modify(str, start_pos);
224CLI11_INLINE std::size_t close_sequence(
const std::string &str, std::size_t start,
char closure_char);
228CLI11_INLINE std::vector<std::string> split_up(std::string str,
char delimiter =
'\0');
231CLI11_INLINE std::string get_environment_value(
const std::string &env_name);
237CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset);
242CLI11_INLINE
bool has_escapable_character(
const std::string &str);
247CLI11_INLINE std::string add_escaped_characters(
const std::string &str);
250CLI11_INLINE std::string remove_escaped_characters(
const std::string &str);
253CLI11_INLINE std::string binary_escape_string(
const std::string &string_to_escape);
255CLI11_INLINE
bool is_binary_escaped_string(
const std::string &escaped_string);
258CLI11_INLINE std::string extract_binary_string(
const std::string &escaped_string);
261CLI11_INLINE
bool process_quoted_string(std::string &str,
char string_char =
'\"',
char literal_char =
'\'');
265CLI11_INLINE std::ostream &streamOutAsParagraph(std::ostream &out,
266 const std::string &text,
267 std::size_t paragraphWidth,
268 const std::string &linePrefix =
"",
269 bool skipPrefixOnFirstLine =
false);
278#include "impl/StringTools_inl.hpp"