Commit d1ad2ab7 authored by Yann Boucher's avatar Yann Boucher
Browse files

Improved support of RLE files

parent f72925d1
Pipeline #78287 passed with stages
in 16 seconds
......@@ -84,6 +84,7 @@ public:
private:
unsigned read_state();
void read_comment_line(Structure& s);
};
//! \class StructureReader
......
#N Puffer train
#C This was created simply by perturbing the sides of a B-heptomino
#C with two LWSS's. A B-heptomino is a naturally occurring object,
#C a precursor to the Herschel pattern, which lurches forward at the
#C speed c/2 before its own debris usually destroys it.
#C -- Not in this case! The LWSS escorts keep the B-heptomino alive.
#O From Alan Hensel's "lifebc" pattern collection.
x = 5, y = 18, rule = B3/S23
3bo$4bo$o3bo$b4o4$o$boo$bbo$bbo$bo3$3bo$4bo$o3bo$b4o!
......@@ -132,10 +132,17 @@ void StructureLibraryView::update_info(QTreeWidgetItem *item, int column)
ui->button_copy->setEnabled(false);
return;
}
if (!s.title.empty())
ui->struct_title->setText(QString::fromStdString(s.title));
else
{
QString filename = QFileInfo(item->data(0, Qt::UserRole).toString()).fileName();
if (!filename.isEmpty()) // failsafe, in case it actually is empty
filename.replace(0, 1, filename[0].toUpper());
ui->struct_title->setText(filename);
}
ui->struct_author->setText(QString::fromStdString(s.author));
ui->struct_date->setText(QString::fromStdString(s.date));
ui->struct_title->setText(QString::fromStdString(s.title));
ui->struct_desc->setPlainText(QString::fromStdString(s.desc));
ui->button_copy->setEnabled(true);
......
......@@ -125,12 +125,32 @@ unsigned RLEStructureReader::read_state()
return 0;
}
void RLEStructureReader::read_comment_line(Structure &s)
{
std::string tag = read_word();
std::string line = read_line();
if (tag == "C" || tag == "c")
{
s.desc += line + '\n';
}
else if (tag == "N")
{
s.title += line;
}
else if (tag == "O")
{
s.author += line;
}
}
// ref : http://golly.sourceforge.net/Help/formats.html#rle
Structure RLEStructureReader::read_structure()
{
Structure s;
// ignore first comment lines
while (accept("#"))
read_line();
read_comment_line(s);
// First Line
{
......@@ -159,8 +179,7 @@ Structure RLEStructureReader::read_structure()
// comment line
if (accept("#"))
{
//char tag = read();
std::string line = read_line();
read_comment_line(s);
}
// end of data
else if (accept("!"))
......@@ -194,7 +213,14 @@ Structure RLEStructureReader::read_structure()
}
}
return Structure(data.begin(), data.end());
// remove the final '\n' of the text fields
while (!s.author.empty() && s.author.back() == '\n') s.author.pop_back();
while (!s.date.empty() && s.date.back() == '\n') s.date.pop_back();
while (!s.title.empty() && s.title.back() == '\n') s.title.pop_back();
while (!s.desc.empty() && s.desc.back() == '\n') s.desc.pop_back();
s.load(data.begin(), data.end());
return s;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment