KDE 4.5 PyKDE API Reference

- KDE's Python API

# KMacroExpanderBase Class Reference

`from PyKDE4.kdecore import *`

Subclasses: KWordMacroExpander, KCharMacroExpander

## Detailed Description

\class KMacroExpanderBase kmacroexpander.h <KMacroExpanderBase>

Abstract base class for the worker classes behind the KMacroExpander namespace and the KCharMacroExpander and KWordMacroExpander classes.

Author:
  Oswald Buddenhagen <ossi@kde.org>

## Methods
| __init__ (self, KMacroExpanderBase other)
| __init__ (self, QChar c=QLatin1Char('%'))
QChar | escapeChar (self)
int | expandEscapedMacro (self, QString str, int pos, QStringList ret)
| expandMacros (self, QString str)
bool, int pos | expandMacrosShellQuote (self, QString str)
int | expandPlainMacro (self, QString str, int pos, QStringList ret)
| setEscapeChar (self, QChar c)

## Method Documentation

__init__ | ( | self, |
|  | KMacroExpanderBase | other
| ) |  |  |

__init__ | ( | self, |
|  | QChar | c=QLatin1Char('%')
| ) |  |  |

Constructor.

Parameters:

  | c | escape char indicating start of macros, or QChar.null for none

QChar escapeChar | ( |  | self ) |

Obtain the macro escape character.

Returns:
  escape char indicating start of macros, or QChar.null if none

int expandEscapedMacro | ( | self, |
|  | QString | str,
|  | int | pos,
|  | QStringList | ret
| ) |  |  |

This function is called every time the escape char is found if it is not QChar.null. It should determine whether the string starting at pos witin str is a valid macro and return the substitution value for it if so.

Parameters:

  | str | the input string
  | pos | the offset within str. Note that this is the position of the occurrence of the escape char
  | ret | return value: the string to substitute for the macro

Returns:
  If greater than zero, the number of chars at pos in str to substitute with ret (i.e., a valid macro was found). If less than zero, subtract this value from pos (to skip a macro, i.e., substitute it with itself). If zero, scanning continues as if no escape char was encountered at all.

expandMacros | ( | self, |
|  | QString | str
| ) |  |  |

Perform safe macro expansion (substitution) on a string.

Parameters:

  | str | the string in which macros are expanded in-place

bool, int pos expandMacrosShellQuote | ( | self, |
|  | QString | str
| ) |  |  |

Same as above, but always starts at position 0, and unmatched closing parens and braces are treated as errors.

int expandPlainMacro | ( | self, |
|  | QString | str,
|  | int | pos,
|  | QStringList | ret
| ) |  |  |

This function is called for every single char within the string if the escape char is QChar.null. It should determine whether the string starting at pos within str is a valid macro and return the substitution value for it if so.

Parameters:

  | str | the input string
  | pos | the offset within str
  | ret | return value: the string to substitute for the macro

Returns:
  If greater than zero, the number of chars at pos in str to substitute with ret (i.e., a valid macro was found). If less than zero, subtract this value from pos (to skip a macro, i.e., substitute it with itself). If zero, no macro starts at pos.

setEscapeChar | ( | self, |
|  | QChar | c
| ) |  |  |

Set the macro escape character.

Parameters:

  | c | escape char indicating start of macros, or QChar.null if none