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>
This commit is contained in:
Marcelo Lira 2010-12-03 17:07:11 -03:00
commit ed1c4c72b9
3 changed files with 56 additions and 0 deletions

View file

@ -49,6 +49,7 @@ PYSIDE_TEST(qobject_tr_as_instance_test.py)
PYSIDE_TEST(qpoint_test.py)
PYSIDE_TEST(qprocess_test.py)
PYSIDE_TEST(qrect_test.py)
PYSIDE_TEST(qregexp_test.py)
PYSIDE_TEST(qresource_test.py)
PYSIDE_TEST(qsize_test.py)
PYSIDE_TEST(qslot_object_test.py)

View file

@ -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('<i>([^<]*)</i>')
string = re.replace('A <i>bon mot</i>.', '\\emph{\\1}')
self.assertEqual(string, 'A \\emph{bon mot}.')
if __name__ == '__main__':
unittest.main()