[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/utils/qsr
From: Aurélien Gâteau <aurelien.gateau () free ! fr>
Date: 2007-03-31 21:30:27
Message-ID: 1175376627.893487.21186.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 648643 by gateau:
Added unit test for highlightMatches.
Rewrote highlightMatches to escape HTML text.
M +19 -19 MainWindow.py
A tests/MainWindowTestCase.py
M +8 -0 tests/sandbox.py
--- trunk/playground/utils/qsr/MainWindow.py #648642:648643
@@ -1,4 +1,5 @@
# vi: expandtab tabstop=4
+import cgi
import os
import sys
@@ -10,31 +11,29 @@
from Config import Config
from EditorController import EditorController
-def highlightMatches(rx, line, color):
- before=u"<b><font color='%s'>" % color
- after="</font></b>"
- def format(x):
- #txt=unicode(QStyleSheet.escape(x[0]))
- txt = unicode(x[0], "utf8", "replace")
- if x[1]:
- return before + txt + after
- else:
- return txt
- txt=[]
+def highlightMatches(rx, line, hlStart, hlStop):
+ lst=[]
pos=0
while True:
match=rx.search(line, pos)
if match is None:
break
- txt.append( (line[pos:match.start()], False) )
- txt.append( (line[match.start():match.end()], True) )
+ beforeMatchTxt = line[pos:match.start()]
+ lst.append(cgi.escape(beforeMatchTxt))
+
+ lst.append(hlStart)
+
+ matchTxt = line[match.start():match.end()]
+ lst.append(cgi.escape(matchTxt))
+ lst.append(hlStop)
+
pos=match.end()
-
- txt.append( (line[pos:], False) )
- txt=map(format, txt)
- return "".join(txt)
+ lst.append(cgi.escape(line[pos:]))
+ return "".join(lst)
+
+
class SearchLVItem(QTreeWidgetItem):
def __init__(self, parent, text1, text2):
QTreeWidgetItem.__init__(self, parent)
@@ -259,13 +258,14 @@
def fillSearchListView(self):
color = self.palette().color(QPalette.Highlight)
- colorName = unicode(color.name())
+ hlStart = u"<b><font color='%s'>" % unicode(color.name())
+ hlStop = u"</font></b>"
for filename,num,line in self._matchList:
filename = os.path.abspath(filename)
filename = filename[len(self._absoluteDir)+1:]
- highlightedLine = highlightMatches(self._worker.src(), line, colorName)
+ highlightedLine = highlightMatches(self._worker.src(), line, hlStart, hlStop)
SearchLVItem(
self.lvSearchTrace,
--- trunk/playground/utils/qsr/tests/sandbox.py #648642:648643
@@ -10,6 +10,14 @@
printf("Hello World\\n");
return 0;
}
+""",
+
+ "helloworld.html": """
+<html>
+<body>
+Hello World
+</body>
+</html>
"""
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic