Skip to content

Commit

Permalink
[PARSE] Add another 'parse_file_extension_argument' which deals with …
Browse files Browse the repository at this point in the history
…several extensions.
  • Loading branch information
frozar committed Jun 21, 2018
1 parent b81431b commit 621d110
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
10 changes: 10 additions & 0 deletions common/include/pcl/console/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ namespace pcl
std::vector<double> &values_s,
std::vector<double> &values_t);

/** \brief Parse command line arguments for file names with given extension vector
* \param[in] argc the number of command line arguments
* \param[in] argv the command line arguments
* \param[in] extensions the extensions to search for
* \return a vector with file names indices
*/
PCL_EXPORTS std::vector<int>
parse_file_extension_argument (int argc, const char * const * argv,
const std::vector<std::string> &extensions);

/** \brief Parse command line arguments for file names with given extension
* \param[in] argc the number of command line arguments
* \param[in] argv the command line arguments
Expand Down
47 changes: 32 additions & 15 deletions common/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,51 @@ pcl::console::parse_argument (int argc, const char * const * argv, const char *

////////////////////////////////////////////////////////////////////////////////
std::vector<int>
pcl::console::parse_file_extension_argument (int argc, const char * const * argv, const std::string &extension)
pcl::console::parse_file_extension_argument (int argc, const char * const * argv,
const std::vector<std::string> &extension)
{
std::vector<int> indices;
for (int i = 1; i < argc; ++i)
{
std::string fname = std::string (argv[i]);
std::string ext = extension;
for (size_t j = 0; j < extension.size (); ++j)
{
std::string ext = extension[j];

// Needs to be at least 4: .ext
if (fname.size () <= 4)
continue;
// Needs to be at least 4: .ext
if (fname.size () <= 4)
continue;

// For being case insensitive
std::transform (fname.begin (), fname.end (), fname.begin (), tolower);
std::transform (ext.begin (), ext.end (), ext.begin (), tolower);
// For being case insensitive
std::transform (fname.begin (), fname.end (), fname.begin (), tolower);
std::transform (ext.begin (), ext.end (), ext.begin (), tolower);

// Check if found
std::string::size_type it;
if ((it = fname.rfind (ext)) != std::string::npos)
{
// Additional check: we want to be able to differentiate between .p and .png
if ((ext.size () - (fname.size () - it)) == 0)
indices.push_back (i);
// Check if found
std::string::size_type it;
if ((it = fname.rfind (ext)) != std::string::npos)
{
// Additional check: we want to be able to differentiate between .p and .png
if ((ext.size () - (fname.size () - it)) == 0)
{
indices.push_back (i);
break;
}
}
}
}
return (indices);
}

////////////////////////////////////////////////////////////////////////////////
std::vector<int>
pcl::console::parse_file_extension_argument (int argc, const char * const * argv,
const std::string &ext)
{
std::vector<std::string> extensions;
extensions.push_back (ext);
return parse_file_extension_argument (argc, argv, extensions);
}

////////////////////////////////////////////////////////////////////////////////
int
pcl::console::parse_2x_arguments (int argc, const char * const * argv, const char * str, float &f, float &s, bool debug)
Expand Down

0 comments on commit 621d110

Please sign in to comment.