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

kdecore

  • kdecore
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 "kdelibs_export.h"
29 
37 class KDECORE_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 KDECORE_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 KDECORE_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  KDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQChar,TQString> &map, TQChar c = '%' );
274 
298  KDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQChar,TQString> &map, TQChar c = '%' );
299 
323  KDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQString,TQString> &map, TQChar c = '%' );
324 
351  KDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQString,TQString> &map, TQChar c = '%' );
352 
357  KDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQChar,TQStringList> &map, TQChar c = '%' );
362  KDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQString,TQStringList> &map, TQChar c = '%' );
363 
370  KDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQChar,TQStringList> &map, TQChar c = '%' );
377  KDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQString,TQStringList> &map, TQChar c = '%' );
378 }
379 
380 #endif /* _KMACROEXPANDER_H */

kdecore

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

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |