19inline std::string& rtrim(std::string& str)
 
   21    str.erase(str.find_last_not_of(
" \n\r\t")+1);
 
   25inline std::string& ltrim(std::string& str)
 
   27    str.erase(0, str.find_first_not_of(
" \n\r\t"));
 
   31inline std::string& lrtrim(std::string& str)
 
   33    return ltrim(rtrim(str));
 
   36inline std::string& lowercase(std::string& str)
 
   38    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
 
   42inline std::string lowercase_of(
const std::string& str)
 
   44    std::string strlc = str;
 
   49inline std::string& uppercase(std::string& str)
 
   51    std::transform(str.begin(), str.end(), str.begin(), ::toupper);
 
   55inline std::string uppercase_of(
const std::string& str)
 
   57    std::string strlc = str;
 
   63inline void lowercase(
char *s)
 
   65    while (*s) { *s = tolower(*s); s++; }
 
   74inline void uppercase(
char *s)
 
   76    while (*s) { *s = toupper(*s); s++; }
 
   79struct PathSeparator_WIN { 
bool operator()( 
char ch )
 const { 
return ch == 
'\\' || ch == 
'/'; } };
 
   81struct PathSeparator_ANY { 
bool operator()( 
char ch )
 const { 
return ch == 
'\\' || ch == 
'/'; } };
 
   82struct ExtSeparator { 
bool operator()( 
char ch )
 const { 
return ch == 
'.'; } };
 
   87inline std::string get_parentdir(
const std::string& path)
 
   89    return std::string( path.begin(), std::find_if(path.rbegin(), path.rend(), 
PathSeparator_ANY() ).base() );
 
   92inline std::string get_filename(
const std::string& path, std::function<
bool(
char)> PathSeparator = 
PathSeparator_ANY())
 
   94    return std::string( std::find_if( path.rbegin(), path.rend(), PathSeparator).base(), path.end() );
 
   97inline std::string get_fileext(
const std::string& path)
 
   99    return std::string( std::find_if( path.rbegin(), path.rend(), 
ExtSeparator() ).base(), path.end() );
 
  103inline void decompose_path(
const std::string& fullpath,
 
  105                           std::string& filename,
 
  108    auto pathsep = std::find_if( fullpath.rbegin(), fullpath.rend(), 
PathSeparator_ANY() );
 
  109    auto extsep = std::find_if( fullpath.rbegin(), pathsep, 
ExtSeparator() );
 
  111    path = std::string(fullpath.begin(), pathsep.base());
 
  113    if (std::distance(extsep, pathsep) > 0)
 
  115        filename = std::string(pathsep.base(), extsep.base()-1);
 
  116        ext = std::string(extsep.base(), fullpath.end());
 
  120        filename = std::string(extsep.base(), fullpath.end());
 
  126static std::string get_parentdir(std::string path)
 
  129    throw std::runtime_error(
"get_parentdir not defined for _WIN32\n");
 
  132    size_t pos = path.rfind(
"/");
 
  134    if (pos != std::string::npos)
 
  135        parent = path.substr(0, pos+1);
 
  161static bool find_option_args(
const std::vector<std::string>& tokens,
 
  162                              const std::string& option_name,
 
  167    auto opt_it = std::find(tokens.begin(), tokens.end(), option_name);
 
  168    if (opt_it > tokens.end() - nbr_args) 
return false;
 
  171    va_start(retargs, nbr_args);
 
  173    for (
int i=0; i<nbr_args; i++)
 
  176        double argvalue = stod( *(opt_it+1+i) );    
 
  177        double* retval = va_arg(retargs, 
double*);  
 
  188static bool find_option_args(
const std::vector<std::string>& tokens,
 
  189                        const std::string& option_name,
 
  193    auto opt_it = std::find(tokens.begin(), tokens.end(), option_name);
 
  196    if (opt_it > tokens.end() - nbr_values) 
return false;
 
  198    val1 = stof(*(opt_it+1));
 
  199    val2 = stof(*(opt_it+2));
 
  206static bool find_filename_from_suffix(
const std::string &str, 
const std::string &suffix, std::string& res)
 
  208    std::string dotsuffix = std::string(
".")+suffix;
 
  209    size_t end = str.find(dotsuffix);
 
  211    if (end == std::string::npos)
 
  214    size_t start = str.rfind(
" ", end);
 
  218    if (start == std::string::npos)
 
  221    res = str.substr(start+1, end-start-1 + dotsuffix.length());
 
  228static bool find_filename_from_suffixes(
const std::string &str, 
const std::vector<std::string>& suffixes, std::string& res)
 
  230    for (
auto& suffix : suffixes)
 
  231        if (find_filename_from_suffix(str, suffix, res))
 
  240static std::vector<std::string> tokenize(
const std::string& str, 
const char delim)
 
  242    std::vector<std::string> tokens;
 
  243    size_t str_len = str.length();
 
  245    size_t si = 0, sj = str.find(delim, 0);
 
  246    while (sj != std::string::npos)
 
  249            tokens.push_back(str.substr(si, sj-si));
 
  252        sj = str.find(delim, si);
 
  255        tokens.push_back(str.substr(si, str_len-si));
 
Definition parseutil.h:82
Definition parseutil.h:81
Definition parseutil.h:80
Definition parseutil.h:79