[osm/formatting] Fixing formatting tagged addresses with comma separated fields
This commit is contained in:
@@ -121,9 +121,10 @@ class AddressFormatter(object):
|
|||||||
|
|
||||||
splitter = self.splitter if not tagged else ' {}/{} '.format(self.splitter.strip(), self.field_separator_tag)
|
splitter = self.splitter if not tagged else ' {}/{} '.format(self.splitter.strip(), self.field_separator_tag)
|
||||||
|
|
||||||
|
values = [self.strip_component(val, tagged=tagged) for val in values]
|
||||||
|
|
||||||
output = splitter.join([
|
output = splitter.join([
|
||||||
self.strip_component(val, tagged=tagged)
|
val for val in values if val.strip()
|
||||||
for val in values
|
|
||||||
])
|
])
|
||||||
|
|
||||||
return output
|
return output
|
||||||
@@ -184,26 +185,30 @@ class AddressFormatter(object):
|
|||||||
|
|
||||||
return value[start:end]
|
return value[start:end]
|
||||||
else:
|
else:
|
||||||
i = j = 0
|
start = end = 0
|
||||||
tokens = value.split()
|
tokens = value.split()
|
||||||
|
|
||||||
separator_tag = self.separator_tag
|
separator_tag = self.separator_tag
|
||||||
|
|
||||||
for i, t in enumerate(tokens):
|
for i, t in enumerate(tokens):
|
||||||
t, c = t.rsplit('/', 1)
|
t, c = t.rsplit('/', 1)
|
||||||
|
start = i
|
||||||
if c != separator_tag:
|
if c != separator_tag:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
start = i + 1
|
||||||
|
|
||||||
|
num_tokens = len(tokens)
|
||||||
|
|
||||||
for j, t in enumerate(reversed(tokens)):
|
for j, t in enumerate(reversed(tokens)):
|
||||||
t, c = t.rsplit('/', 1)
|
t, c = t.rsplit('/', 1)
|
||||||
|
end = num_tokens - j
|
||||||
if c != separator_tag:
|
if c != separator_tag:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
end = num_tokens - j - 1
|
||||||
|
|
||||||
if j == 0:
|
return u' '.join(tokens[start:end])
|
||||||
j = None
|
|
||||||
else:
|
|
||||||
j = -j
|
|
||||||
return u' '.join(tokens[i:j])
|
|
||||||
|
|
||||||
def format_address(self, country, components, minimal_only=True, tag_components=True):
|
def format_address(self, country, components, minimal_only=True, tag_components=True):
|
||||||
template = self.config.get(country.upper())
|
template = self.config.get(country.upper())
|
||||||
|
|||||||
Reference in New Issue
Block a user