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

tdecore

kmacroexpander.h

00001 /*
00002     This file is part of the KDE libraries
00003 
00004     Copyright (c) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
00005     Copyright (c) 2003 Waldo Bastian <bastian@kde.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 #ifndef _KMACROEXPANDER_H
00023 #define _KMACROEXPANDER_H
00024 
00025 #include <tqstringlist.h>
00026 #include <tqstring.h>
00027 #include <tqmap.h>
00028 #include "tdelibs_export.h"
00029 
00037 class TDECORE_EXPORT KMacroExpanderBase {
00038 
00039 public:
00044     KMacroExpanderBase( TQChar c = '%' );
00045 
00049     virtual ~KMacroExpanderBase();
00050 
00056     void expandMacros( TQString &str );
00057 
00058     /*
00059      * Perform safe macro expansion (substitution) on a string for use
00060      * in shell commands.
00061      *
00062      * Explicitly supported shell constructs:
00063      *   \ '' "" $'' $"" {} () $(()) ${} $() ``
00064      *
00065      * Implicitly supported shell constructs:
00066      *   (())
00067      *
00068      * Unsupported shell constructs that will cause problems:
00069      *  @li Shortened "case $v in pat)" syntax. Use "case $v in (pat)" instead.
00070      *
00071      * The rest of the shell (incl. bash) syntax is simply ignored,
00072      * as it is not expected to cause problems.
00073      *
00074      * Note that bash contains a bug which makes macro expansion within 
00075      * double quoted substitutions ("${VAR:-%macro}") inherently insecure.
00076      *
00077      * @param str the string in which macros are expanded in-place
00078      * @param pos the position inside the string at which parsing/substitution
00079      *  should start, and upon exit where processing stopped
00080      * @return false if the string could not be parsed and therefore no safe
00081      *  substitution was possible. Note that macros will have been processed
00082      *  up to the point where the error occurred. An unmatched closing paren
00083      *  or brace outside any shell construct is @em not an error (unlike in
00084      *  the function below), but still prematurely terminates processing.
00085      */
00086     bool expandMacrosShellQuote( TQString &str, uint &pos );
00087 
00092     bool expandMacrosShellQuote( TQString &str );
00093 
00098     void setEscapeChar( TQChar c );
00099 
00104     TQChar escapeChar() const;
00105 
00106 protected:
00120     virtual int expandPlainMacro( const TQString &str, uint pos, TQStringList &ret );
00121 
00136     virtual int expandEscapedMacro( const TQString &str, uint pos, TQStringList &ret );
00137 
00138 private:
00139     TQChar escapechar;
00140 };
00141 
00191 class TDECORE_EXPORT KWordMacroExpander : public KMacroExpanderBase {
00192 
00193 public:
00198     KWordMacroExpander( TQChar c = '%' ) : KMacroExpanderBase( c ) {}
00199 
00200 protected:
00201     virtual int expandPlainMacro( const TQString &str, uint pos, TQStringList &ret );
00202     virtual int expandEscapedMacro( const TQString &str, uint pos, TQStringList &ret );
00203 
00211     virtual bool expandMacro( const TQString &str, TQStringList &ret ) = 0;
00212 };
00213 
00224 class TDECORE_EXPORT KCharMacroExpander : public KMacroExpanderBase {
00225 
00226 public:
00231     KCharMacroExpander( TQChar c = '%' ) : KMacroExpanderBase( c ) {}
00232 
00233 protected:
00234     virtual int expandPlainMacro( const TQString &str, uint pos, TQStringList &ret );
00235     virtual int expandEscapedMacro( const TQString &str, uint pos, TQStringList &ret );
00236 
00244     virtual bool expandMacro( TQChar chr, TQStringList &ret ) = 0;
00245 };
00246 
00252 namespace KMacroExpander {
00273     TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQChar,TQString> &map, TQChar c = '%' );
00274 
00298     TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQChar,TQString> &map, TQChar c = '%' );
00299 
00323     TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQString,TQString> &map, TQChar c = '%' );
00324 
00351     TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQString,TQString> &map, TQChar c = '%' );
00352 
00357     TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQChar,TQStringList> &map, TQChar c = '%' );
00362     TDECORE_EXPORT TQString expandMacros( const TQString &str, const TQMap<TQString,TQStringList> &map, TQChar c = '%' );
00363 
00370     TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQChar,TQStringList> &map, TQChar c = '%' );
00377     TDECORE_EXPORT TQString expandMacrosShellQuote( const TQString &str, const TQMap<TQString,TQStringList> &map, TQChar c = '%' );
00378 }
00379 
00380 #endif /* _KMACROEXPANDER_H */

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.6.3
This website is maintained by Timothy Pearson.