kdecore Library API Documentation

KMacroExpander Namespace Reference

A group of functions providing macro expansion (substitution) in strings, optionally with quoting appropriate for shell execution. More...


Enumerations

enum  Quoting {
  noquote, singlequote, doublequote, dollarquote,
  paren, subst, group, math
}

Functions

QString expandMacros (const QString &ostr, const QMap< QChar, QString > &map, QChar c)
QString expandMacrosShellQuote (const QString &ostr, const QMap< QChar, QString > &map, QChar c)


Detailed Description

A group of functions providing macro expansion (substitution) in strings, optionally with quoting appropriate for shell execution.

Since:
3.1.3


Function Documentation

KDECORE_EXPORT QString KMacroExpander::expandMacros const QString str,
const QMap< QChar, QString > &  map,
QChar  c = '%'
 

Perform safe macro expansion (substitution) on a string.

The escape char must be quoted with itself to obtain its literal representation in the resulting string.

Parameters:
str The string to expand
map map with substitutions
c escape char indicating start of macro, or QChar::null if none
Returns:
the string with all valid macros expanded
 // Code example
 QMap<QChar,QString> map;
 map.insert('u', "/tmp/myfile.txt");
 map.insert('n', "My File");
 QString s = "%% Title: %u:%n";
 s = KMacroExpander::expandMacros(s, map);
 // s is now "% Title: /tmp/myfile.txt:My File";

Definition at line 519 of file kmacroexpander.cpp.

Referenced by KApplication::invokeMailer().

KDECORE_EXPORT QString KMacroExpander::expandMacrosShellQuote const QString str,
const QMap< QChar, QString > &  map,
QChar  c = '%'
 

Perform safe macro expansion (substitution) on a string for use in shell commands.

The escape char must be quoted with itself to obtain its literal representation in the resulting string.

Parameters:
str The string to expand
map map with substitutions
c escape char indicating start of macro, or QChar::null if none
Returns:
the string with all valid macros expanded, or a null string if a shell syntax error was detected in the command
 // Code example
 QMap<QChar,QString> map;
 map.insert('u', "/tmp/myfile.txt");
 map.insert('n', "My File");
 QString s = "kedit --caption %n %u";
 s = KMacroExpander::expandMacrosShellQuote(s, map);
 // s is now "kedit --caption 'My File' '/tmp/myfile.txt'";
 system(QFile::encodeName(s));

Definition at line 520 of file kmacroexpander.cpp.

KDE Logo
This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Nov 1 10:32:00 2005 by doxygen 1.4.3 written by Dimitri van Heesch, © 1997-2003