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<<;
48constexpr int expected_max_vector_size{1 << 29};
51CLI11_INLINE std::vector<std::string> split(
const std::string &s,
char delim);
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];
105CLI11_INLINE std::string <rim(std::string &str);
108CLI11_INLINE std::string <rim(std::string &str,
const std::string &filter);
111CLI11_INLINE std::string &rtrim(std::string &str);
114CLI11_INLINE std::string &rtrim(std::string &str,
const std::string &filter);
117inline std::string &trim(std::string &str) {
return ltrim(rtrim(str)); }
120inline std::string &trim(std::string &str,
const std::string filter) {
return ltrim(rtrim(str, filter), filter); }
123inline std::string trim_copy(
const std::string &str) {
129CLI11_INLINE std::string &remove_quotes(std::string &str);
132CLI11_INLINE
void remove_quotes(std::vector<std::string> &args);
138CLI11_INLINE std::string fix_newlines(
const std::string &leader, std::string input);
141inline std::string trim_copy(
const std::string &str,
const std::string &filter) {
143 return trim(s, filter);
147CLI11_INLINE std::ostream &format_aliases(std::ostream &out,
const std::vector<std::string> &aliases, std::size_t wid);
151template <
typename T>
bool valid_first_char(T c) {
152 return ((c !=
'-') && (
static_cast<unsigned char>(c) > 33));
156template <
typename T>
bool valid_later_char(T c) {
160 return ((c !=
'=') && (c !=
':') && (c !=
'{') && ((
static_cast<unsigned char>(c) > 32) || c ==
'\t'));
164CLI11_INLINE
bool valid_name_string(
const std::string &str);
167inline bool valid_alias_name_string(
const std::string &str) {
168 static const std::string badChars(std::string(
"\n") +
'\0');
169 return (str.find_first_of(badChars) == std::string::npos);
173inline bool is_separator(
const std::string &str) {
174 static const std::string sep(
"%%");
175 return (str.empty() || str == sep);
179inline bool isalpha(
const std::string &str) {
180 return std::all_of(str.begin(), str.end(), [](
char c) { return std::isalpha(c, std::locale()); });
184inline std::string to_lower(std::string str) {
185 std::transform(std::begin(str), std::end(str), std::begin(str), [](
const std::string::value_type &x) {
186 return std::tolower(x, std::locale());
192inline std::string remove_underscore(std::string str) {
193 str.erase(std::remove(std::begin(str), std::end(str),
'_'), std::end(str));
198CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std::string to);
201inline bool has_default_flag_values(
const std::string &flags) {
202 return (flags.find_first_of(
"{!") != std::string::npos);
205CLI11_INLINE
void remove_default_flag_values(std::string &flags);
208CLI11_INLINE std::ptrdiff_t find_member(std::string name,
209 const std::vector<std::string> names,
210 bool ignore_case =
false,
211 bool ignore_underscore =
false);
215template <
typename Callable>
inline std::string find_and_modify(std::string str, std::string trigger, Callable modify) {
216 std::size_t start_pos = 0;
217 while((start_pos = str.find(trigger, start_pos)) != std::string::npos) {
218 start_pos = modify(str, start_pos);
225CLI11_INLINE std::size_t close_sequence(
const std::string &str, std::size_t start,
char closure_char);
229CLI11_INLINE std::vector<std::string> split_up(std::string str,
char delimiter =
'\0');
232CLI11_INLINE std::string get_environment_value(
const std::string &env_name);
238CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset);
243CLI11_INLINE
bool has_escapable_character(
const std::string &str);
248CLI11_INLINE std::string add_escaped_characters(
const std::string &str);
251CLI11_INLINE std::string remove_escaped_characters(
const std::string &str);
254CLI11_INLINE std::string binary_escape_string(
const std::string &string_to_escape);
256CLI11_INLINE
bool is_binary_escaped_string(
const std::string &escaped_string);
259CLI11_INLINE std::string extract_binary_string(
const std::string &escaped_string);
262CLI11_INLINE
bool process_quoted_string(std::string &str,
char string_char =
'\"',
char literal_char =
'\'');
266CLI11_INLINE std::ostream &streamOutAsParagraph(std::ostream &out,
267 const std::string &text,
268 std::size_t paragraphWidth,
269 const std::string &linePrefix =
"",
270 bool skipPrefixOnFirstLine =
false);
279#include "impl/StringTools_inl.hpp"
std::ostream & operator<<(std::ostream &in, const T &item)
output streaming for enumerations
Definition StringTools.hpp:34