Commit 08cd0274 authored by Michal Čihař's avatar Michal Čihař

Properly handle locale specific extensions to format string

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 7a6ea1d8
...@@ -57,7 +57,7 @@ C_PRINTF_MATCH = re.compile( ...@@ -57,7 +57,7 @@ C_PRINTF_MATCH = re.compile(
%( # initial % %( # initial %
(?:(?P<ord>\d+)\$)? # variable order, like %1$s (?:(?P<ord>\d+)\$)? # variable order, like %1$s
(?P<fullvar> (?P<fullvar>
[+#-]* # flags [+#-']* # flags
(?:\d+)? # width (?:\d+)? # width
(?:\.\d+)? # precision (?:\.\d+)? # precision
(hh\|h\|l\|ll)? # length formatting (hh\|h\|l\|ll)? # length formatting
...@@ -152,6 +152,12 @@ class BaseFormatCheck(TargetCheck): ...@@ -152,6 +152,12 @@ class BaseFormatCheck(TargetCheck):
# Check did not fire # Check did not fire
return False return False
def cleanup_string(self, text):
"""Removes locale specific code from format string"""
if '\'' in text:
return text.replace('\'', '')
return text
def check_format(self, source, target, unit, cache_slot, ignore_missing): def check_format(self, source, target, unit, cache_slot, ignore_missing):
''' '''
Generic checker for format strings. Generic checker for format strings.
...@@ -176,7 +182,7 @@ class BaseFormatCheck(TargetCheck): ...@@ -176,7 +182,7 @@ class BaseFormatCheck(TargetCheck):
# Cache miss, so calculate value # Cache miss, so calculate value
if src_matches is None: if src_matches is None:
src_matches = [ src_matches = [
x[0] self.cleanup_string(x[0])
for x in self.regexp.findall(source) for x in self.regexp.findall(source)
if x[0] != '%' if x[0] != '%'
] ]
...@@ -187,7 +193,7 @@ class BaseFormatCheck(TargetCheck): ...@@ -187,7 +193,7 @@ class BaseFormatCheck(TargetCheck):
self.set_cache(unit, (uses_position, src_matches), cache_slot) self.set_cache(unit, (uses_position, src_matches), cache_slot)
tgt_matches = [ tgt_matches = [
x[0] self.cleanup_string(x[0])
for x in self.regexp.findall(target) for x in self.regexp.findall(target)
if x[0] != '%' if x[0] != '%'
] ]
......
...@@ -340,6 +340,15 @@ class CFormatCheckTest(TestCase): ...@@ -340,6 +340,15 @@ class CFormatCheckTest(TestCase):
False False
)) ))
def test_locale_delimiter(self):
self.assertFalse(self.check.check_format(
u'lines: %6.3f',
u'radky: %\'6.3f',
MockUnit('c_locale_delimiter'),
0,
False
))
class PythonBraceFormatCheckTest(TestCase): class PythonBraceFormatCheckTest(TestCase):
def setUp(self): def setUp(self):
......
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