KCoreAddons

kmacroexpander.h
1 /*
2  This file is part of the KDE libraries
3 
4  SPDX-FileCopyrightText: 2002-2003 Oswald Buddenhagen <[email protected]>
5  SPDX-FileCopyrightText: 2003 Waldo Bastian <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 #ifndef KMACROEXPANDER_H
10 #define KMACROEXPANDER_H
11 
12 #include <kcoreaddons_export.h>
13 #include <QChar>
14 
15 class QString;
16 class QStringList;
17 template <typename KT, typename VT> class QHash;
18 class KMacroExpanderBasePrivate;
19 
28 class KCOREADDONS_EXPORT KMacroExpanderBase
29 {
30 
31 public:
36  explicit KMacroExpanderBase(QChar c = QLatin1Char('%'));
37 
41  virtual ~KMacroExpanderBase();
42 
48  void expandMacros(QString &str);
49 
50  // TODO: This documentation is relevant for end-users. Where to put it?
98  bool expandMacrosShellQuote(QString &str, int &pos);
99 
104  bool expandMacrosShellQuote(QString &str);
105 
110  void setEscapeChar(QChar c);
111 
116  QChar escapeChar() const;
117 
118 protected:
132  virtual int expandPlainMacro(const QString &str, int pos, QStringList &ret);
133 
149  virtual int expandEscapedMacro(const QString &str, int pos, QStringList &ret);
150 
151 private:
152  KMacroExpanderBasePrivate *const d;
153 };
154 
205 class KCOREADDONS_EXPORT KWordMacroExpander : public KMacroExpanderBase
206 {
207 
208 public:
214 
215 protected:
217  int expandPlainMacro(const QString &str, int pos, QStringList &ret) override;
219  int expandEscapedMacro(const QString &str, int pos, QStringList &ret) override;
220 
228  virtual bool expandMacro(const QString &str, QStringList &ret) = 0;
229 };
230 
242 class KCOREADDONS_EXPORT KCharMacroExpander : public KMacroExpanderBase
243 {
244 
245 public:
251 
252 protected:
254  int expandPlainMacro(const QString &str, int pos, QStringList &ret) override;
256  int expandEscapedMacro(const QString &str, int pos, QStringList &ret) override;
257 
265  virtual bool expandMacro(QChar chr, QStringList &ret) = 0;
266 };
267 
272 namespace KMacroExpander
273 {
294 KCOREADDONS_EXPORT QString expandMacros(const QString &str, const QHash<QChar, QString> &map, QChar c = QLatin1Char('%'));
295 
319 KCOREADDONS_EXPORT QString expandMacrosShellQuote(const QString &str, const QHash<QChar, QString> &map,
320  QChar c = QLatin1Char('%'));
321 
345 KCOREADDONS_EXPORT QString expandMacros(const QString &str, const QHash<QString, QString> &map,
346  QChar c = QLatin1Char('%'));
347 
375 KCOREADDONS_EXPORT QString expandMacrosShellQuote(const QString &str, const QHash<QString, QString> &map,
376  QChar c = QLatin1Char('%'));
377 
382 KCOREADDONS_EXPORT QString expandMacros(const QString &str, const QHash<QChar, QStringList> &map,
383  QChar c = QLatin1Char('%'));
384 KCOREADDONS_EXPORT QString expandMacros(const QString &str, const QHash<QString, QStringList> &map,
385  QChar c = QLatin1Char('%'));
386 
393 KCOREADDONS_EXPORT QString expandMacrosShellQuote(const QString &str, const QHash<QChar, QStringList> &map,
394  QChar c = QLatin1Char('%'));
395 KCOREADDONS_EXPORT QString expandMacrosShellQuote(const QString &str, const QHash<QString, QStringList> &map,
396  QChar c = QLatin1Char('%'));
397 }
398 
399 #endif /* KMACROEXPANDER_H */
Abstract base class for the worker classes behind the KMacroExpander namespace and the KCharMacroExpa...
KWordMacroExpander(QChar c=QLatin1Char('%'))
Constructor.
virtual int expandEscapedMacro(const QString &str, int pos, QStringList &ret)
This function is called every time the escape char is found if it is not QChar::null.
virtual int expandPlainMacro(const QString &str, int pos, QStringList &ret)
This function is called for every single char within the string if the escape char is QChar::null...
A group of functions providing macro expansion (substitution) in strings, optionally with quoting app...
Abstract base class for simple word macro substitutors.
Abstract base class for single char macro substitutors.
KCharMacroExpander(QChar c=QLatin1Char('%'))
Constructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 18 2020 23:01:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.