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):
ret = []
match_objects = self.regexp.finditer(source)
for match in match_objects:
if match.start() == match.end():
continue
ret.append((match.start(), match.group()))
ret.append((match.start(), match.end(), match.group()))
return ret
class PythonFormatCheck(BaseFormatCheck):
......
......@@ -71,8 +71,12 @@ class BBCodeCheck(TargetCheck):
return []
ret = []
for match in BBCODE_MATCH.finditer(source):
ret.append((match.start('start'), match.group('start')))
ret.append((match.start('end'), match.group('end')))
for tag in ('start', 'end'):
ret.append((
match.start(tag),
match.end(tag),
match.group(tag)
))
return ret
......@@ -118,7 +122,7 @@ class XMLTagsCheck(TargetCheck):
def check_highlight(self, source, unit):
ret = []
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):
ret.append((match.start(), match.group()))
ret.append((match.start(), match.end(), match.group()))
return ret
......@@ -98,14 +98,13 @@ def fmt_check_highlights(value, checks):
if hl_idx >= len(highlights):
break
elref = highlights[hl_idx]
elref_end = elref[0] + len(elref[1])
for hl_idx_next in xrange(hl_idx + 1, len(highlights)):
if hl_idx_next >= len(highlights):
break
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)
elif eltest[0] > elref_end:
elif eltest[0] > elref[1]:
break
#then transform highlights to escaped html
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,
# Create span for checks highlights
if highlights:
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)
if find_highlight >= 0:
newpart = u'<span class="hlcheck">{0}</span>'.format(htext)
......
......@@ -37,7 +37,7 @@ class PythonFormatCheckTest(CheckTestCase):
self.test_highlight = (
'python-format',
'%sstring%d',
[(0, u'%s'), (8, u'%d')],
[(0, 2, u'%s'), (8, 10, u'%d')],
)
def test_no_format(self):
......@@ -133,7 +133,7 @@ class PHPFormatCheckTest(CheckTestCase):
self.test_highlight = (
'php-format',
'%sstring%d',
[(0, u'%s'), (8, u'%d')],
[(0, 2, u'%s'), (8, 10, u'%d')],
)
def test_no_format(self):
......@@ -229,7 +229,7 @@ class CFormatCheckTest(CheckTestCase):
self.test_highlight = (
'c-format',
'%sstring%d',
[(0, u'%s'), (8, u'%d')],
[(0, 2, u'%s'), (8, 10, u'%d')],
)
def test_no_format(self):
......@@ -311,7 +311,7 @@ class PythonBraceFormatCheckTest(CheckTestCase):
self.test_highlight = (
'python-brace-format',
'{0}string{1}',
[(0, u'{0}'), (9, u'{1}')],
[(0, 3, u'{0}'), (9, 12, u'{1}')],
)
def test_no_format(self):
......
......@@ -40,7 +40,7 @@ class BBCodeCheckTest(CheckTestCase):
self.test_highlight = (
'',
'[a]string[/a]',
[(0, '[a]'), (9, '[/a]')]
[(0, 3, '[a]'), (9, 13, '[/a]')]
)
......@@ -56,5 +56,10 @@ class XMLTagsCheckTest(CheckTestCase):
self.test_highlight = (
'',
'<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