Commit 46c4ab7b authored by hjk's avatar hjk

Utils: Introduce a not-so-abstract MacroExpander utility class

The current use of AbstractMacroExpander requires some boiler plate
code that can be avoided.

Change-Id: I753d872d824274d94d5105232a8fc05ac7bf0711
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 08127189
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "utils_global.h" #include "utils_global.h"
#include <functional>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QStringList; class QStringList;
QT_END_NAMESPACE QT_END_NAMESPACE
...@@ -75,6 +77,19 @@ private: ...@@ -75,6 +77,19 @@ private:
bool expandNestedMacros(const QString &str, int *pos, QString *ret); bool expandNestedMacros(const QString &str, int *pos, QString *ret);
}; };
class QTCREATOR_UTILS_EXPORT MacroExpander : public AbstractMacroExpander
{
public:
typedef std::function<bool(const QString &name, QString *ret)> Resolver;
explicit MacroExpander(const Resolver &resolver) : m_resolver(resolver) {}
bool resolveMacro(const QString &name, QString *ret) { return m_resolver(name, ret); }
private:
Resolver m_resolver;
};
QTCREATOR_UTILS_EXPORT void expandMacros(QString *str, AbstractMacroExpander *mx); QTCREATOR_UTILS_EXPORT void expandMacros(QString *str, AbstractMacroExpander *mx);
QTCREATOR_UTILS_EXPORT QString expandMacros(const QString &str, AbstractMacroExpander *mx); QTCREATOR_UTILS_EXPORT QString expandMacros(const QString &str, AbstractMacroExpander *mx);
......
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