Moving comment filtering to Utils class. Adding comment filtering to collection basic lists (include.txt, exclude.txt, etc).

This commit is contained in:
Don Honerbrink 2015-06-15 11:17:49 -05:00
parent f91fc16c6e
commit b95c7c44f0
4 changed files with 21 additions and 9 deletions

View File

@ -203,12 +203,13 @@ bool CollectionInfoBuilder::ImportBasicList(CollectionInfo * /*info*/, std::stri
return false;
}
std::string line;
std::string line;
while(std::getline(includeStream, line))
{
if(list.find(line) == list.end())
line = Utils::FilterComments(line);
if(!line.empty() && list.find(line) == list.end())
{
Item *i = new Item();

View File

@ -117,12 +117,8 @@ bool Configuration::ParseLine(std::string keyPrefix, std::string line, int lineC
std::string delimiter = "=";
// strip out any comments
if((position = line.find("#")) != std::string::npos)
{
line = line.substr(0, position);
}
// unix only wants \n. Windows uses \r\n. Strip off the \r for unix.
line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() );
line = Utils::FilterComments(line);
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
{
retVal = true;

View File

@ -54,6 +54,20 @@ std::string Utils::UppercaseFirst(std::string str)
return str;
}
std::string Utils::FilterComments(std:;string line)
{
size_t position;
// strip out any comments
if((position = line.find("#")) != std::string::npos)
{
line = line.substr(0, position);
}
// unix only wants \n. Windows uses \r\n. Strip off the \r for unix.
line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() );
return line;
}
std::string Utils::CombinePath(std::list<std::string> &paths)
{

View File

@ -33,6 +33,7 @@ public:
static bool FindMatchingFile(std::string prefix, std::vector<std::string> &extensions, std::string &file);
static std::string ToLower(std::string str);
static std::string UppercaseFirst(std::string str);
static std::string FilterComments(std::string line);
//todo: there has to be a better way to do this
static std::string CombinePath(std::list<std::string> &paths);