From edf5b58da83696ad908ac21b18bdd9a343d842ee Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Fri, 3 Dec 2010 17:07:11 -0300 Subject: 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 Reviewed by Luciano Wolf --- tests/QtCore/qregexp_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/QtCore/qregexp_test.py (limited to 'tests/QtCore/qregexp_test.py') diff --git a/tests/QtCore/qregexp_test.py b/tests/QtCore/qregexp_test.py new file mode 100644 index 000000000..54991854a --- /dev/null +++ b/tests/QtCore/qregexp_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/python + +import unittest +from PySide.QtCore import QRegExp + +class QRegExpTest(unittest.TestCase): + + def testReplace1(self): + re = QRegExp('a[mn]') + string = re.replace('Banana', 'ox') + self.assertEqual(string, 'Boxoxa') + + def testReplace2(self): + re = QRegExp('([^<]*)') + string = re.replace('A bon mot.', '\\emph{\\1}') + self.assertEqual(string, 'A \\emph{bon mot}.') + +if __name__ == '__main__': + unittest.main() + -- cgit v1.2.3