174{
175 enum { ST_START, ST_AFTER_OPEN, ST_AFTER_GUI,
176 ST_EXPECT_VERSION, ST_VERSION_NUM
177 } state = ST_START;
178 const int length = xml.length();
179 for (
int pos = 0; pos <
length; pos++) {
180 switch (state) {
181 case ST_START:
182 if (xml[pos] == QLatin1Char('<')) {
183 state = ST_AFTER_OPEN;
184 }
185 break;
186 case ST_AFTER_OPEN: {
187
188 const int guipos = xml.indexOf(QStringLiteral("gui"), pos, Qt::CaseInsensitive);
189 if (guipos == -1) {
190 return QString();
191 }
192
193 pos = guipos + 2;
194 state = ST_AFTER_GUI;
195 break;
196 }
197 case ST_AFTER_GUI:
198 state = ST_EXPECT_VERSION;
199 break;
200 case ST_EXPECT_VERSION: {
201 const int verpos = xml.indexOf(QStringLiteral("version"), pos, Qt::CaseInsensitive);
202 if (verpos == -1) {
203 return QString();
204 }
205 pos = verpos + 7;
206 while (xml.at(pos).isSpace()) {
207 ++pos;
208 }
209 if (xml.at(pos++) != QLatin1Char('=')) {
210 return QString();
211 }
212 while (xml.at(pos).isSpace()) {
213 ++pos;
214 }
215
216 state = ST_VERSION_NUM;
217 break;
218 }
219 case ST_VERSION_NUM: {
220 int endpos;
221 for (endpos = pos; endpos <
length; endpos++) {
222 const ushort ch = xml[endpos].unicode();
223 if (ch >= QLatin1Char('0') && ch <= QLatin1Char('9')) {
224 continue;
225 }
226 if (ch == QLatin1Char('"')) {
227 break;
228 } else {
230 }
231 }
232
233 if (endpos != pos && endpos <
length) {
234 const QString matchCandidate = xml.mid(pos, endpos - pos);
235 return matchCandidate;
236 }
237
238 state = ST_EXPECT_VERSION;
239 break;
240 }
241 }
242 }
243
244 return QString();
245}
qreal length(const QPointF &vec)