|
@@ -40,23 +40,64 @@
|
|
|
|
|
|
namespace fv::util{
|
|
namespace fv::util{
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Splits input string into substrings based on provided sep char.
|
|
|
|
+ * For example, split("1,2,3", ',') -> {"1","2","3"}.
|
|
|
|
+ */
|
|
|
|
+std::vector<std::string> split(const std::string& to_split, char sep){
|
|
|
|
+ std::vector<std::string> substrings;
|
|
|
|
+ std::string substring;
|
|
|
|
+
|
|
|
|
+ for(const char &c : to_split){
|
|
|
|
+ if(c == sep){
|
|
|
|
+ substrings.push_back(substring);
|
|
|
|
+ substring.clear();
|
|
|
|
+ } else{
|
|
|
|
+ substring.push_back(c);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(substring.size() > 0){
|
|
|
|
+ substrings.push_back(substring);
|
|
|
|
+ }
|
|
|
|
+ return substrings;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Removes leading and trailing whitespace from s
|
|
|
|
+ */
|
|
|
|
+std::string& strip(std::string& s){
|
|
|
|
+ int idx;
|
|
|
|
+ //strip left side whitespace
|
|
|
|
+ for(idx=0; idx<s.size(); idx++){
|
|
|
|
+ char& c = s[idx];
|
|
|
|
+ if(c == ' ' || c == '\t') continue;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ s.erase(0,idx);
|
|
|
|
+ //strip right side whitespace
|
|
|
|
+ for(idx=s.size()-1; idx>=0; idx--){
|
|
|
|
+ char& c = s[idx];
|
|
|
|
+ if(c == ' ' || c == '\t') continue;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ s.erase(idx+1,s.size()-idx-1);
|
|
|
|
+ return s;
|
|
|
|
+}
|
|
|
|
+
|
|
struct DataFileDescriptor{
|
|
struct DataFileDescriptor{
|
|
std::string filename;
|
|
std::string filename;
|
|
std::string label;
|
|
std::string label;
|
|
- std::string category; //TODO: Populate this
|
|
|
|
|
|
+ std::string category;
|
|
|
|
|
|
- DataFileDescriptor(const std::string filename, const std::string label)
|
|
|
|
- :filename(filename), label(label),category("") { }
|
|
|
|
|
|
+ DataFileDescriptor(const std::string filename, const std::string label, const std::string category)
|
|
|
|
+ :filename(filename), label(label),category(category) { }
|
|
|
|
|
|
- DataFileDescriptor(const std::string line):category(""){
|
|
|
|
- std::string::size_type col_pos = line.find(":");
|
|
|
|
- if(col_pos == std::string::npos){
|
|
|
|
- this->filename = line;
|
|
|
|
- this->label = "";
|
|
|
|
- } else{
|
|
|
|
- this->filename = line.substr(0, col_pos);
|
|
|
|
- this->label = line.substr(col_pos+1);
|
|
|
|
- }
|
|
|
|
|
|
+ DataFileDescriptor(const std::string line)
|
|
|
|
+ :filename(""),label(""),category(""){
|
|
|
|
+ auto fields = split(line, ':');
|
|
|
|
+ filename = strip(fields[0]);
|
|
|
|
+ if(fields.size()>1) label=strip(fields[1]);
|
|
|
|
+ if(fields.size()>2) label=strip(fields[2]);
|
|
}
|
|
}
|
|
|
|
|
|
};
|
|
};
|
|
@@ -70,6 +111,7 @@ std::vector<DataFileDescriptor> read_input_list(const std::string &filename){
|
|
std::vector<DataFileDescriptor> dfds;
|
|
std::vector<DataFileDescriptor> dfds;
|
|
std::string prefix = filename.substr(0, filename.find_last_of("/")+1);
|
|
std::string prefix = filename.substr(0, filename.find_last_of("/")+1);
|
|
while(std::getline(istrm, line)){
|
|
while(std::getline(istrm, line)){
|
|
|
|
+ strip(line);
|
|
if(line[0] != '#')
|
|
if(line[0] != '#')
|
|
dfds.push_back(DataFileDescriptor(prefix+line));
|
|
dfds.push_back(DataFileDescriptor(prefix+line));
|
|
}
|
|
}
|