diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-12-03 17:07:11 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:47:56 -0300 |
commit | edf5b58da83696ad908ac21b18bdd9a343d842ee (patch) | |
tree | 3ce899c72ff81b7958e463c4d96ae6f58d7835af /PySide/QtCore | |
parent | 1c6fad98417ad5be5a4748ac865ed81f52b5d9c5 (diff) |
Added QRegExp.replace(QString, const char*) method.
The only way to search and replace using QRegExp is using the
QString::replace method. Since QString was removed, QRegExp now is
useful only to search stuff, but not replace. For this purpose the
QRegExp.replace method was added. The first argument is the string
that will be operated over, the second argument contains the
replacement, and the return value is a new modified Python string.
Unit tests and documentation for QRegExp.replace were added as well.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide/QtCore')
-rw-r--r-- | PySide/QtCore/typesystem_core.xml | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml index 6da4f64c7..5ed694c1a 100644 --- a/PySide/QtCore/typesystem_core.xml +++ b/PySide/QtCore/typesystem_core.xml @@ -1390,6 +1390,41 @@ </insert-template> </inject-code> </add-function> + <add-function signature="replace(QString, QString)" return-type="QString"> + <modify-argument index="1"> + <rename to="sourceString"/> + </modify-argument> + <modify-argument index="2"> + <rename to="after"/> + </modify-argument> + <inject-documentation format="target" mode="append"> + Replaces every occurrence of the regular expression in *sourceString* with *after*. + Returns a new Python string with the modified contents. For example: + + :: + + s = "Banana" + re = QRegExp("a[mn]") + s = re.replace(s, "ox") + # s == "Boxoxa" + + + For regular expressions containing capturing parentheses, occurrences of \1, \2, ..., in *after* + are replaced with rx.cap(1), cap(2), ... + + :: + + t = "A <i>bon mot</i>." + re = QRegExp("<i>([^<]*)</i>") + t = re.replace(t, "\\emph{\\1}") + # t == "A \\emph{bon mot}." + + </inject-documentation> + <inject-code class="target" position="beginning"> + %1.replace(*%CPPSELF, %2); + %PYARG_0 = %CONVERTTOPYTHON[QString](%1); + </inject-code> + </add-function> </value-type> <value-type name="QFileInfo"> <extra-includes> |