Skip comments at end of colors.txt lines as well

(and detect and report incomplete lines as well)
This commit is contained in:
Rogier 2014-05-21 19:24:07 +02:00
parent f3c25ac729
commit bacbcfc1e4

View File

@ -375,19 +375,22 @@ void TileGenerator::parseColorsStream(std::istream &in, const std::string &filen
int linenr = 0; int linenr = 0;
for (std::getline(in,line); in.good(); std::getline(in,line)) { for (std::getline(in,line); in.good(); std::getline(in,line)) {
linenr++; linenr++;
size_t comment = line.find_first_of('#');
if (comment != string::npos)
line.erase(comment);
istringstream iline; istringstream iline;
iline.str(line); iline.str(line);
iline >> std::skipws; iline >> std::skipws;
string name; string name;
ColorEntry color; ColorEntry color;
iline >> name; iline >> name;
if (name.length() == 0 || name[0] == '#') if (name.length() == 0)
continue; continue;
int r, g, b, a, t; int r, g, b, a, t;
iline >> r; iline >> r;
iline >> g; iline >> g;
iline >> b; iline >> b;
if (!iline.good() && !iline.eof()) { if (iline.fail()) {
std::cerr << filename << ":" << linenr << ": bad line in colors file (" << line << ")" << std::endl; std::cerr << filename << ":" << linenr << ": bad line in colors file (" << line << ")" << std::endl;
continue; continue;
} }