src/parser.cpp

changeset 328
3ea38fd469ca
parent 327
2aa15daa0216
child 333
07e65a4c6611
equal deleted inserted replaced
327:2aa15daa0216 328:3ea38fd469ca
28 }; 28 };
29 29
30 /* 30 /*
31 * Constructs an LDraw parser 31 * Constructs an LDraw parser
32 */ 32 */
33 Parser::Parser(QIODevice& device, QObject* parent) : 33 Parser::Parser(QTextStream& stream, QObject* parent) :
34 QObject {parent}, 34 QObject {parent},
35 device {device} {} 35 stream {stream} {}
36 36
37 /* 37 /*
38 * Reads a single line from the device. 38 * Reads a single line from the device.
39 */ 39 */
40 QString Parser::readLine() 40 QString Parser::readLine()
41 { 41 {
42 return QString::fromUtf8(this->device.readLine()).trimmed(); 42 return this->stream.readLine().trimmed();
43 } 43 }
44 44
45 /** 45 /**
46 * @brief Parses the model body into the given model. 46 * @brief Parses the model body into the given model.
47 * @param editor Handle to model edit context 47 * @param editor Handle to model edit context
48 */ 48 */
49 void Parser::parseBody(Model& model) 49 void Parser::parseBody(Model& model)
50 { 50 {
51 bool invertNext = false; 51 bool invertNext = false;
52 while (not this->device.atEnd()) 52 while (not this->stream.atEnd())
53 { 53 {
54 // Some LDraw parts such as 53588.dat can contain "BFC INVERTNEXT" with multiple inner whitespaces. 54 // Some LDraw parts such as 53588.dat can contain "BFC INVERTNEXT" with multiple inner whitespaces.
55 // So we need to pass the string through QString::simplified to catch these cases. 55 // So we need to pass the string through QString::simplified to catch these cases.
56 const QString line = this->readLine().trimmed(); 56 const QString line = this->readLine().trimmed();
57 if (line == "0 BFC INVERTNEXT" or line == "0 BFC CERTIFY INVERTNEXT") 57 if (line == "0 BFC INVERTNEXT" or line == "0 BFC CERTIFY INVERTNEXT")

mercurial