1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00

Include missing inlines to allow linking

This commit is contained in:
Henry Schreiner 2017-03-31 15:26:30 -04:00
parent e772c0e43b
commit 1e627bfcf2
4 changed files with 18 additions and 18 deletions

View File

@ -63,7 +63,7 @@ struct ini_ret_t {
}; };
/// Internal parsing function /// Internal parsing function
std::vector<ini_ret_t> parse_ini(std::istream &input) { inline std::vector<ini_ret_t> parse_ini(std::istream &input) {
std::string name, line; std::string name, line;
std::string section = "default"; std::string section = "default";
@ -103,7 +103,7 @@ std::vector<ini_ret_t> parse_ini(std::istream &input) {
} }
/// Parse an INI file, throw an error (ParseError:INIParseError or FileError) on failure /// Parse an INI file, throw an error (ParseError:INIParseError or FileError) on failure
std::vector<ini_ret_t> parse_ini(const std::string &name) { inline std::vector<ini_ret_t> parse_ini(const std::string &name) {
std::ifstream input{name}; std::ifstream input{name};
if(!input.good()) if(!input.good())

View File

@ -16,7 +16,7 @@ namespace detail {
// Based on http://stackoverflow.com/questions/236129/split-a-string-in-c // Based on http://stackoverflow.com/questions/236129/split-a-string-in-c
///Split a string by a delim ///Split a string by a delim
std::vector<std::string> split(const std::string &s, char delim) { inline std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems; std::vector<std::string> elems;
// Check to see if emtpy string, give consistent result // Check to see if emtpy string, give consistent result
if(s=="") if(s=="")
@ -61,14 +61,14 @@ std::string rjoin(const T& v, std::string delim = ",") {
// Based roughly on http://stackoverflow.com/questions/25829143/c-trim-whitespace-from-a-string // Based roughly on http://stackoverflow.com/questions/25829143/c-trim-whitespace-from-a-string
/// Trim whitespace from left of string /// Trim whitespace from left of string
std::string& ltrim(std::string &str) { inline std::string& ltrim(std::string &str) {
auto it = std::find_if(str.begin(), str.end(), [](char ch){ return !std::isspace<char>(ch , std::locale());}); auto it = std::find_if(str.begin(), str.end(), [](char ch){ return !std::isspace<char>(ch , std::locale());});
str.erase(str.begin(), it); str.erase(str.begin(), it);
return str; return str;
} }
/// Trim anything from left of string /// Trim anything from left of string
std::string& ltrim(std::string &str, const std::string &filter) { inline std::string& ltrim(std::string &str, const std::string &filter) {
auto it = std::find_if(str.begin(), str.end(), [&filter](char ch){return filter.find(ch) == std::string::npos;}); auto it = std::find_if(str.begin(), str.end(), [&filter](char ch){return filter.find(ch) == std::string::npos;});
str.erase(str.begin(), it); str.erase(str.begin(), it);
return str; return str;
@ -76,42 +76,42 @@ std::string& ltrim(std::string &str, const std::string &filter) {
/// Trim whitespace from right of string /// Trim whitespace from right of string
std::string& rtrim(std::string &str) { inline std::string& rtrim(std::string &str) {
auto it = std::find_if(str.rbegin(), str.rend(), [](char ch){ return !std::isspace<char>(ch, std::locale());}); auto it = std::find_if(str.rbegin(), str.rend(), [](char ch){ return !std::isspace<char>(ch, std::locale());});
str.erase(it.base() , str.end() ); str.erase(it.base() , str.end() );
return str; return str;
} }
/// Trim anything from right of string /// Trim anything from right of string
std::string& rtrim(std::string &str, const std::string &filter) { inline std::string& rtrim(std::string &str, const std::string &filter) {
auto it = std::find_if(str.rbegin(), str.rend(), [&filter](char ch){return filter.find(ch) == std::string::npos;}); auto it = std::find_if(str.rbegin(), str.rend(), [&filter](char ch){return filter.find(ch) == std::string::npos;});
str.erase(it.base(), str.end()); str.erase(it.base(), str.end());
return str; return str;
} }
/// Trim whitespace from string /// Trim whitespace from string
std::string& trim(std::string &str) { inline std::string& trim(std::string &str) {
return ltrim(rtrim(str)); return ltrim(rtrim(str));
} }
/// Trim anything from string /// Trim anything from string
std::string& trim(std::string &str, const std::string filter) { inline std::string& trim(std::string &str, const std::string filter) {
return ltrim(rtrim(str, filter), filter); return ltrim(rtrim(str, filter), filter);
} }
/// Make a copy of the string and then trim it /// Make a copy of the string and then trim it
std::string trim_copy(const std::string &str) { inline std::string trim_copy(const std::string &str) {
std::string s = str; std::string s = str;
return trim(s); return trim(s);
} }
/// Make a copy of the string and then trim it, any filter string can be used (any char in string is filtered) /// Make a copy of the string and then trim it, any filter string can be used (any char in string is filtered)
std::string trim_copy(const std::string &str, const std::string &filter) { inline std::string trim_copy(const std::string &str, const std::string &filter) {
std::string s = str; std::string s = str;
return trim(s, filter); return trim(s, filter);
} }
/// Print a two part "help" string /// Print a two part "help" string
void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) { inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) {
name = " " + name; name = " " + name;
out << std::setw(wid) << std::left << name; out << std::setw(wid) << std::left << name;
if(description != "") { if(description != "") {
@ -145,14 +145,14 @@ inline bool valid_name_string(const std::string &str) {
} }
/// Return a lower case version of a string /// Return a lower case version of a string
std::string inline to_lower(std::string str) { inline std::string to_lower(std::string str) {
std::transform(std::begin(str), std::end(str), std::begin(str), std::transform(std::begin(str), std::end(str), std::begin(str),
[](const std::string::value_type &x){return std::tolower(x,std::locale());}); [](const std::string::value_type &x){return std::tolower(x,std::locale());});
return str; return str;
} }
/// Split a string '"one two" "three"' into 'one two', 'three' /// Split a string '"one two" "three"' into 'one two', 'three'
std::vector<std::string> inline split_up(std::string str) { inline std::vector<std::string> split_up(std::string str) {
std::vector<char> delims = {'\'', '\"'}; std::vector<char> delims = {'\'', '\"'};
auto find_ws = [](char ch){ return std::isspace<char>(ch , std::locale());}; auto find_ws = [](char ch){ return std::isspace<char>(ch , std::locale());};

View File

@ -119,6 +119,6 @@ public:
} }
/// This prints out the time if shifted into a std::cout like stream. /// This prints out the time if shifted into a std::cout like stream.
std::ostream & operator<< (std::ostream& in, const CLI::Timer& timer) { inline std::ostream & operator<< (std::ostream& in, const CLI::Timer& timer) {
return in << timer.to_string(); return in << timer.to_string();
} }

View File

@ -24,7 +24,7 @@ namespace CLI {
/// @{ /// @{
/// Check for an existing file /// Check for an existing file
bool ExistingFile(std::string filename) { inline bool ExistingFile(std::string filename) {
struct stat buffer; struct stat buffer;
bool exist = stat(filename.c_str(), &buffer) == 0; bool exist = stat(filename.c_str(), &buffer) == 0;
bool is_dir = (buffer.st_mode & S_IFDIR) != 0; bool is_dir = (buffer.st_mode & S_IFDIR) != 0;
@ -40,7 +40,7 @@ bool ExistingFile(std::string filename) {
} }
/// Check for an existing directory /// Check for an existing directory
bool ExistingDirectory(std::string filename) { inline bool ExistingDirectory(std::string filename) {
struct stat buffer; struct stat buffer;
bool exist = stat(filename.c_str(), &buffer) == 0; bool exist = stat(filename.c_str(), &buffer) == 0;
bool is_dir = (buffer.st_mode & S_IFDIR) != 0; bool is_dir = (buffer.st_mode & S_IFDIR) != 0;
@ -57,7 +57,7 @@ bool ExistingDirectory(std::string filename) {
/// Check for a non-existing path /// Check for a non-existing path
bool NonexistentPath(std::string filename) { inline bool NonexistentPath(std::string filename) {
struct stat buffer; struct stat buffer;
bool exist = stat(filename.c_str(), &buffer) == 0; bool exist = stat(filename.c_str(), &buffer) == 0;
if(!exist) { if(!exist) {