Commit e29912eb authored by Wouter's avatar Wouter

Add unquote filter to unquote quoted strings

parent 1f99e93d
......@@ -22,7 +22,9 @@
#include "helpers.h"
#include "../lib/metacode/type.h"
// TODO migrate all QRegExp->QRegularExpression
#include <QtCore/QRegExp>
#include <QtCore/QRegularExpression>
#include <QtCore/QFileInfo>
QVariant QJsonIntrospect::Codegen::IndentFilter::doFilter(const QVariant& input, const QVariant& argument, bool autoescape) const
......@@ -106,6 +108,20 @@ QVariant QJsonIntrospect::Codegen::SplitWordsFilter::doFilter(const QVariant& in
return Grantlee::SafeString(in.replace(m_regex, "\\1" + arg + "\\2"));
}
QVariant QJsonIntrospect::Codegen::UnquoteFilter::doFilter(const QVariant& input, const QVariant& argument, bool autoescape) const
{
static QRegularExpression re("^\"(.*)\"$");
QString in = Helpers::getString(input);
QString out = in;
QRegularExpressionMatch match = re.match(in);
if (match.isValid()) {
out = match.capturedRef(1).toString();
}
return Grantlee::SafeString(out);
}
QVariant QJsonIntrospect::Codegen::ToAccessFilter::doFilter(const QVariant& input, const QVariant& argument, bool autoescape) const
{
QJsonIntrospect::Type::ProtectionLevel value;
......
......@@ -49,6 +49,12 @@ class TrimFilter: public Grantlee::Filter
virtual bool isSafe() const { return true; };
};
class UnquoteFilter: public Grantlee::Filter
{
virtual QVariant doFilter(const QVariant& input, const QVariant& argument = QVariant(), bool autoescape = false) const;
virtual bool isSafe() const { return true; };
};
class SplitWordsFilter: public Grantlee::Filter
{
private:
......
......@@ -45,6 +45,7 @@ QHash< QString, Grantlee::Filter* > QJsonIntrospect::Codegen::Library::filters(c
filters["toaccess"] = new ToAccessFilter();
filters["identifier"] = new IdentifierFilter();
filters["filename"] = new FilenameFilter();
filters["unquote"] = new UnquoteFilter();
return filters;
}
......
Markdown is supported
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