Commit 1eabc8c8 authored by Michal Čihař's avatar Michal Čihař

Include end position in result

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1fd77b3b
...@@ -211,9 +211,7 @@ class BaseFormatCheck(TargetCheck): ...@@ -211,9 +211,7 @@ class BaseFormatCheck(TargetCheck):
ret = [] ret = []
match_objects = self.regexp.finditer(source) match_objects = self.regexp.finditer(source)
for match in match_objects: for match in match_objects:
if match.start() == match.end(): ret.append((match.start(), match.end(), match.group()))
continue
ret.append((match.start(), match.group()))
return ret return ret
class PythonFormatCheck(BaseFormatCheck): class PythonFormatCheck(BaseFormatCheck):
......
...@@ -71,8 +71,12 @@ class BBCodeCheck(TargetCheck): ...@@ -71,8 +71,12 @@ class BBCodeCheck(TargetCheck):
return [] return []
ret = [] ret = []
for match in BBCODE_MATCH.finditer(source): for match in BBCODE_MATCH.finditer(source):
ret.append((match.start('start'), match.group('start'))) for tag in ('start', 'end'):
ret.append((match.start('end'), match.group('end'))) ret.append((
match.start(tag),
match.end(tag),
match.group(tag)
))
return ret return ret
...@@ -118,7 +122,7 @@ class XMLTagsCheck(TargetCheck): ...@@ -118,7 +122,7 @@ class XMLTagsCheck(TargetCheck):
def check_highlight(self, source, unit): def check_highlight(self, source, unit):
ret = [] ret = []
for match in XML_MATCH.finditer(source): for match in XML_MATCH.finditer(source):
ret.append((match.start(), match.group())) ret.append((match.start(), match.end(), match.group()))
for match in XML_ENTITY_MATCH.finditer(source): for match in XML_ENTITY_MATCH.finditer(source):
ret.append((match.start(), match.group())) ret.append((match.start(), match.end(), match.group()))
return ret return ret
...@@ -98,14 +98,13 @@ def fmt_check_highlights(value, checks): ...@@ -98,14 +98,13 @@ def fmt_check_highlights(value, checks):
if hl_idx >= len(highlights): if hl_idx >= len(highlights):
break break
elref = highlights[hl_idx] elref = highlights[hl_idx]
elref_end = elref[0] + len(elref[1])
for hl_idx_next in xrange(hl_idx + 1, len(highlights)): for hl_idx_next in xrange(hl_idx + 1, len(highlights)):
if hl_idx_next >= len(highlights): if hl_idx_next >= len(highlights):
break break
eltest = highlights[hl_idx_next] eltest = highlights[hl_idx_next]
if eltest[0] >= elref[0] and eltest[0] < elref_end: if eltest[0] >= elref[0] and eltest[0] < elref[1]:
highlights.pop(hl_idx_next) highlights.pop(hl_idx_next)
elif eltest[0] > elref_end: elif eltest[0] > elref[1]:
break break
#then transform highlights to escaped html #then transform highlights to escaped html
highlights = [(h[0], escape(force_text(h[1]))) for h in highlights] highlights = [(h[0], escape(force_text(h[1]))) for h in highlights]
...@@ -152,7 +151,7 @@ def format_translation(value, language, diff=None, search_match=None, ...@@ -152,7 +151,7 @@ def format_translation(value, language, diff=None, search_match=None,
# Create span for checks highlights # Create span for checks highlights
if highlights: if highlights:
start_search = 0 start_search = 0
for htext in [h[1] for h in highlights]: for htext in [h[2] for h in highlights]:
find_highlight = value.find(htext, start_search) find_highlight = value.find(htext, start_search)
if find_highlight >= 0: if find_highlight >= 0:
newpart = u'<span class="hlcheck">{0}</span>'.format(htext) newpart = u'<span class="hlcheck">{0}</span>'.format(htext)
......
...@@ -37,7 +37,7 @@ class PythonFormatCheckTest(CheckTestCase): ...@@ -37,7 +37,7 @@ class PythonFormatCheckTest(CheckTestCase):
self.test_highlight = ( self.test_highlight = (
'python-format', 'python-format',
'%sstring%d', '%sstring%d',
[(0, u'%s'), (8, u'%d')], [(0, 2, u'%s'), (8, 10, u'%d')],
) )
def test_no_format(self): def test_no_format(self):
...@@ -133,7 +133,7 @@ class PHPFormatCheckTest(CheckTestCase): ...@@ -133,7 +133,7 @@ class PHPFormatCheckTest(CheckTestCase):
self.test_highlight = ( self.test_highlight = (
'php-format', 'php-format',
'%sstring%d', '%sstring%d',
[(0, u'%s'), (8, u'%d')], [(0, 2, u'%s'), (8, 10, u'%d')],
) )
def test_no_format(self): def test_no_format(self):
...@@ -229,7 +229,7 @@ class CFormatCheckTest(CheckTestCase): ...@@ -229,7 +229,7 @@ class CFormatCheckTest(CheckTestCase):
self.test_highlight = ( self.test_highlight = (
'c-format', 'c-format',
'%sstring%d', '%sstring%d',
[(0, u'%s'), (8, u'%d')], [(0, 2, u'%s'), (8, 10, u'%d')],
) )
def test_no_format(self): def test_no_format(self):
...@@ -311,7 +311,7 @@ class PythonBraceFormatCheckTest(CheckTestCase): ...@@ -311,7 +311,7 @@ class PythonBraceFormatCheckTest(CheckTestCase):
self.test_highlight = ( self.test_highlight = (
'python-brace-format', 'python-brace-format',
'{0}string{1}', '{0}string{1}',
[(0, u'{0}'), (9, u'{1}')], [(0, 3, u'{0}'), (9, 12, u'{1}')],
) )
def test_no_format(self): def test_no_format(self):
......
...@@ -40,7 +40,7 @@ class BBCodeCheckTest(CheckTestCase): ...@@ -40,7 +40,7 @@ class BBCodeCheckTest(CheckTestCase):
self.test_highlight = ( self.test_highlight = (
'', '',
'[a]string[/a]', '[a]string[/a]',
[(0, '[a]'), (9, '[/a]')] [(0, 3, '[a]'), (9, 13, '[/a]')]
) )
...@@ -56,5 +56,10 @@ class XMLTagsCheckTest(CheckTestCase): ...@@ -56,5 +56,10 @@ class XMLTagsCheckTest(CheckTestCase):
self.test_highlight = ( self.test_highlight = (
'', '',
'<b><a href="foo">bar</a></b>', '<b><a href="foo">bar</a></b>',
[(0, '<b>'), (3, '<a href="foo">'), (20, '</a>'), (24, '</b>')] [
(0, 3, '<b>'),
(3, 17, '<a href="foo">'),
(20, 24, '</a>'),
(24, 28, '</b>'),
]
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment