• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

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 QHash< QString, QStringList > &map, QChar c)
QString expandMacros (const QString &str, const QHash< QChar, QStringList > &map, QChar c=QLatin1Char('%'))
QString expandMacros (const QString &str, const QHash< QString, QString > &map, QChar c=QLatin1Char('%'))
QString expandMacros (const QString &str, const QHash< QChar, QString > &map, QChar c= '%')
QString expandMacrosShellQuote (const QString &ostr, const QHash< QString, QStringList > &map, QChar c)
QString expandMacrosShellQuote (const QString &str, const QHash< QChar, QStringList > &map, QChar c=QLatin1Char('%'))
QString expandMacrosShellQuote (const QString &str, const QHash< QString, QString > &map, QChar c=QLatin1Char('%'))
QString expandMacrosShellQuote (const QString &str, const QHash< QChar, QString > &map, QChar c=QLatin1Char('%'))

Detailed Description

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


Enumeration Type Documentation

enum KMacroExpander::Quoting

Enumerator:
noquote 
singlequote 
doublequote 
dollarquote 
paren 
subst 
group 
math 

Definition at line 33 of file kmacroexpander_unix.cpp.


Function Documentation

QString KMacroExpander::expandMacros ( const QString &  ostr,
const QHash< QString, QStringList > &  map,
QChar  c 
)

Definition at line 345 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacros ( const QString &  ostr,
const QHash< QChar, QStringList > &  map,
QChar  c 
)

Same as above, except that the macros expand to string lists that are simply join(" ")ed together.

Definition at line 341 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacros ( const QString &  str,
const QHash< QString, QString > &  map,
QChar  c = QLatin1Char('%') 
)

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. Macro names can consist of chars in the range [A-Za-z0-9_]; use braces to delimit macros from following words starting with these chars, or to use other chars for macro names.

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
 QHash<QString,QString> map;
 map.insert("url", "/tmp/myfile.txt");
 map.insert("name", "My File");
 QString s = "Title: %{url}-%name";
 s = KMacroExpander::expandMacros(s, map);
 // s is now "Title: /tmp/myfile.txt-My File";

Definition at line 337 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacros ( const QString &  str,
const QHash< 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
 QHash<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 333 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacrosShellQuote ( const QString &  ostr,
const QHash< QString, QStringList > &  map,
QChar  c 
)

Definition at line 347 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacrosShellQuote ( const QString &  str,
const QHash< QChar, QStringList > &  map,
QChar  c = QLatin1Char('%') 
)

Same as above, except that the macros expand to string lists.

If the macro appears inside a quoted string, the list is simply join(" ")ed together; otherwise every element expands to a separate quoted string.

Definition at line 343 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacrosShellQuote ( const QString &  str,
const QHash< QString, QString > &  map,
QChar  c = QLatin1Char('%') 
)

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

See KMacroExpanderBase::expandMacrosShellQuote() for the exact semantics. The escape char must be quoted with itself to obtain its literal representation in the resulting string. Macro names can consist of chars in the range [A-Za-z0-9_]; use braces to delimit macros from following words starting with these chars, or to use other chars for macro names.

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
 QHash<QString,QString> map;
 map.insert("url", "/tmp/myfile.txt");
 map.insert("name", "My File");
 QString s = "kedit --caption %name %{url}";
 s = KMacroExpander::expandMacrosShellQuote(s, map);
 // s is now "kedit --caption 'My File' '/tmp/myfile.txt'";
 system(QFile::encodeName(s));

Definition at line 339 of file kmacroexpander.cpp.

QString KMacroExpander::expandMacrosShellQuote ( const QString &  str,
const QHash< QChar, QString > &  map,
QChar  c = QLatin1Char('%') 
)

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
 QHash<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 335 of file kmacroexpander.cpp.

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal