• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kmacroexpander.h
1 /*
2  This file is part of the KDE libraries
3 
4  Copyright (c) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
5  Copyright (c) 2003 Waldo Bastian <bastian@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 #ifndef _KMACROEXPANDER_H
23 #define _KMACROEXPANDER_H
24 
25 #include <tqstringlist.h>
26 #include <tqstring.h>
27 #include <tqmap.h>
28 #include "tdelibs_export.h"
29 
37 class TDECORE_EXPORT KMacroExpanderBase {
38 
39 public:
44  KMacroExpanderBase( TQChar c = '%' );
45 
49  virtual ~KMacroExpanderBase();
50 
56  void expandMacros( TQString &str );
57 
58  /*
59  * Perform safe macro expansion (substitution) on a string for use
60  * in shell commands.
61  *
62  * Explicitly supported shell constructs:
63  * \ '' "" $'' $"" {} () $(()) ${} $() ``
64  *
65  * Implicitly supported shell constructs:
66  * (())
67  *
68  * Unsupported shell constructs that will cause problems:
69  * @li Shortened "case $v in pat)" syntax. Use "case $v in (pat)" instead.
70  *
71  * The rest of the shell (incl. bash) syntax is simply ignored,
72  * as it is not expected to cause problems.
73  *
74  * Note that bash contains a bug which makes macro expansion within
75  * double quoted substitutions ("${VAR:-%macro}") inherently insecure.
76  *
77  * @param str the string in which macros are expanded in-place
78  * @param pos the position inside the string at which parsing/substitution
79  * should start, and upon exit where processing stopped
80  * @return false if the string could not be parsed and therefore no safe
81  * substitution was possible. Note that macros will have been processed
82  * up to the point where the error occurred. An unmatched closing paren
83  * or brace outside any shell construct is @em not an error (unlike in
84  * the function below), but still prematurely terminates processing.
85  */
86  bool expandMacrosShellQuote( TQString &str, uint &pos );
87 
92  bool expandMacrosShellQuote( TQString &str );
93 
98  void setEscapeChar( TQChar c );
99 
104  TQChar escapeChar() const;
105 
106 protected:
120  virtual int expandPlainMacro( const TQString &str, uint pos, TQStringList &ret );
121 
136  virtual int expandEscapedMacro( const TQString &str, uint pos, TQStringList &ret );
137 
138 private:
139  TQChar escapechar;
140 };
141 
191 class TDECORE_EXPORT KWordMacroExpander : public KMacroExpanderBase {
192 
193 public:
198  KWordMacroExpander( TQChar c = '%' ) : KMacroExpanderBase( c ) {}
199 
200 protected:
201  virtual int expandPlainMacro( const TQString &str, uint pos, TQStringList &ret );
202  virtual int expandEscapedMacro( const TQString &str, uint pos, TQStringList &ret );
203 
211  virtual bool expandMacro( const TQString &str, TQStringList &ret ) = 0;
212 };
213 
224 class TDECORE_EXPORT KCharMacroExpander : public KMacroExpanderBase {
225 
226 public:
231  KCharMacroExpander( TQChar c = '%' ) : KMacroExpanderBase( c ) {}
232 
233 protected:
234  virtual int expandPlainMacro( const TQString &str, uint pos, TQStringList &ret );
235  virtual int expandEscapedMacro( const TQString &str, uint pos, TQStringList &ret );
236 
244  virtual bool expandMacro( TQChar chr, TQStringList &ret ) = 0;
245 };
246 
252 namespace KMacroExpander {
273  TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQChar,TQString> &map, TQChar c = '%' );
274 
298  TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQChar,TQString> &map, TQChar c = '%' );
299 
323  TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQString,TQString> &map, TQChar c = '%' );
324 
351  TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQString,TQString> &map, TQChar c = '%' );
352 
357  TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQChar,TQStringList> &map, TQChar c = '%' );
362  TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQString,TQStringList> &map, TQChar c = '%' );
363 
370  TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQChar,TQStringList> &map, TQChar c = '%' );
377  TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQString,TQStringList> &map, TQChar c = '%' );
378 }
379 
380 #endif /* _KMACROEXPANDER_H */
KCharMacroExpander
Abstract base class for single char macro substitutors.
Definition: kmacroexpander.h:224
KCharMacroExpander::KCharMacroExpander
KCharMacroExpander(TQChar c='%')
Constructor.
Definition: kmacroexpander.h:231
KCharMacroExpander::expandMacro
virtual bool expandMacro(TQChar chr, TQStringList &ret)=0
Return substitution list ret for single-character macro chr.
KMacroExpanderBase
Abstract base class for the worker classes behind the KMacroExpander namespace and the KCharMacroExpa...
Definition: kmacroexpander.h:37
KWordMacroExpander
Abstract base class for simple word macro substitutors.
Definition: kmacroexpander.h:191
KWordMacroExpander::expandMacro
virtual bool expandMacro(const TQString &str, TQStringList &ret)=0
Return substitution list ret for string macro str.
KWordMacroExpander::KWordMacroExpander
KWordMacroExpander(TQChar c='%')
Constructor.
Definition: kmacroexpander.h:198
KMacroExpander
A group of functions providing macro expansion (substitution) in strings, optionally with quoting app...
Definition: kmacroexpander.cpp:82
KMacroExpander::expandMacros
TQString expandMacros(const TQString &ostr, const TQMap< TQChar, TQString > &map, TQChar c)
Perform safe macro expansion (substitution) on a string.
Definition: kmacroexpander.cpp:520
KMacroExpander::expandMacrosShellQuote
TQString expandMacrosShellQuote(const TQString &ostr, const TQMap< TQChar, TQString > &map, TQChar c)
Perform safe macro expansion (substitution) on a string for use in shell commands.
Definition: kmacroexpander.cpp:521

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.1
This website is maintained by Timothy Pearson.