46 QString Parser::readLine() |
46 QString Parser::readLine() |
47 { |
47 { |
48 return QString::fromUtf8(this->device.readLine()).trimmed(); |
48 return QString::fromUtf8(this->device.readLine()).trimmed(); |
49 } |
49 } |
50 |
50 |
51 static const QMap<QString, LDHeader::FileType> typeStrings { |
|
52 {"Part", LDHeader::Part}, |
|
53 {"Subpart", LDHeader::Subpart}, |
|
54 {"Shortcut", LDHeader::Shortcut}, |
|
55 {"Primitive", LDHeader::Primitive}, |
|
56 {"8_Primitive", LDHeader::Primitive_8}, |
|
57 {"48_Primitive", LDHeader::Primitive_48}, |
|
58 {"Configuration", LDHeader::Configuration}, |
|
59 }; |
|
60 |
|
61 /* |
51 /* |
62 * Parses a single line of the header. |
52 * Parses a single line of the header. |
63 * Possible parse results: |
53 * Possible parse results: |
64 * · ParseSuccess: the header line was parsed successfully. |
54 * · ParseSuccess: the header line was parsed successfully. |
65 * · ParseFailure: the header line was parsed incorrectly and needs to be handled otherwise. |
55 * · ParseFailure: the header line was parsed incorrectly and needs to be handled otherwise. |
89 // Anything that enters LDForge becomes unofficial in any case if saved. |
79 // Anything that enters LDForge becomes unofficial in any case if saved. |
90 // Therefore we don't need to give the Unofficial type any special |
80 // Therefore we don't need to give the Unofficial type any special |
91 // consideration. |
81 // consideration. |
92 if (partTypeString.startsWith("Unofficial_")) |
82 if (partTypeString.startsWith("Unofficial_")) |
93 partTypeString = partTypeString.mid(strlen("Unofficial_")); |
83 partTypeString = partTypeString.mid(strlen("Unofficial_")); |
94 header.type = typeStrings.value(partTypeString, LDHeader::Part); |
84 header.type = headerTypeFromString(partTypeString); |
95 header.qualfiers = {}; |
85 header.qualfiers = {}; |
96 if (tokens.contains("Alias")) |
86 if (tokens.contains("Alias")) |
97 header.qualfiers |= LDHeader::Alias; |
87 header.qualfiers |= LDHeader::Alias; |
98 if (tokens.contains("Physical_Color")) |
88 if (tokens.contains("Physical_Color")) |
99 header.qualfiers |= LDHeader::PhysicalColour; |
89 header.qualfiers |= LDHeader::PhysicalColour; |
181 else if (line.startsWith("0 !CMDLINE ")) |
171 else if (line.startsWith("0 !CMDLINE ")) |
182 { |
172 { |
183 header.cmdline = line.mid(strlen("0 !CMDLINE ")); |
173 header.cmdline = line.mid(strlen("0 !CMDLINE ")); |
184 return ParseSuccess; |
174 return ParseSuccess; |
185 } |
175 } |
186 else if (line.startsWith("0 !LICENSE Redistributable under CCAL version 2.0")) |
176 else if (line.startsWith(LDHeader::caLicenseString)) |
187 { |
177 { |
188 header.license = LDHeader::CaLicense; |
178 header.license = LDHeader::CaLicense; |
189 return ParseSuccess; |
179 return ParseSuccess; |
190 } |
180 } |
191 else if (line.startsWith("0 !LICENSE Not redistributable")) |
181 else if (line.startsWith(LDHeader::nonCaLicenseString)) |
192 { |
182 { |
193 header.license = LDHeader::NonCaLicense; |
183 header.license = LDHeader::NonCaLicense; |
194 return ParseSuccess; |
184 return ParseSuccess; |
195 } |
185 } |
196 else |
186 else |