2010-10-17 18:03:49 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-17 18:03:49 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FMPSPARSER_H
|
|
|
|
#define FMPSPARSER_H
|
|
|
|
|
|
|
|
#include <QRegExp>
|
|
|
|
#include <QVariantList>
|
|
|
|
|
|
|
|
class FMPSParser {
|
|
|
|
public:
|
|
|
|
FMPSParser();
|
|
|
|
|
2010-10-17 18:30:22 +02:00
|
|
|
// A FMPS result is a list of lists of values (where a value is a string or
|
|
|
|
// a float).
|
2010-10-17 18:03:49 +02:00
|
|
|
typedef QList<QVariantList> Result;
|
|
|
|
|
2010-10-17 18:30:22 +02:00
|
|
|
// Parses a FMPS value and returns true on success.
|
2010-10-17 18:03:49 +02:00
|
|
|
bool Parse(const QString& data);
|
2010-10-17 18:30:22 +02:00
|
|
|
|
|
|
|
// Gets the result of the last successful Parse.
|
2010-10-17 18:03:49 +02:00
|
|
|
Result result() const { return result_; }
|
|
|
|
|
2010-10-17 18:30:22 +02:00
|
|
|
// Returns true if result() is empty.
|
2010-10-17 18:03:49 +02:00
|
|
|
bool is_empty() const { return result().isEmpty() || result()[0].isEmpty(); }
|
|
|
|
|
2010-10-17 18:30:22 +02:00
|
|
|
// Internal functions, public for unit tests
|
2010-10-17 18:03:49 +02:00
|
|
|
int ParseValue(const QString& data, QVariant* ret) const;
|
|
|
|
int ParseValueRef(const QStringRef& data, QVariant* ret) const;
|
|
|
|
|
|
|
|
int ParseList(const QString& data, QVariantList* ret) const;
|
|
|
|
int ParseListRef(const QStringRef& data, QVariantList* ret) const;
|
|
|
|
|
|
|
|
int ParseListList(const QString& data, Result* ret) const;
|
|
|
|
int ParseListListRef(const QStringRef& data, Result* ret) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QRegExp float_re_;
|
|
|
|
QRegExp string_re_;
|
|
|
|
QRegExp escape_re_;
|
|
|
|
Result result_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FMPSPARSER_H
|