[fix] only commas and hyphens need to be eliminated at the end of phrases in untagged address formatting
This commit is contained in:
@@ -167,18 +167,21 @@ class AddressFormatter(object):
|
|||||||
|
|
||||||
def strip_component(self, value, tagged=False):
|
def strip_component(self, value, tagged=False):
|
||||||
if not tagged:
|
if not tagged:
|
||||||
|
comma = token_types.COMMA.value
|
||||||
|
hyphen = token_types.HYPHEN.value
|
||||||
|
|
||||||
start = end = 0
|
start = end = 0
|
||||||
tokens = tokenize_raw(value.strip())
|
tokens = tokenize_raw(value.strip())
|
||||||
for token_start, token_length, token_type in tokens:
|
for token_start, token_length, token_type in tokens:
|
||||||
start = token_start
|
start = token_start
|
||||||
if token_type < token_types.PERIOD.value:
|
if token_type in (comma, hyphen):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
start = token_start + token_length
|
start = token_start + token_length
|
||||||
|
|
||||||
for token_start, token_length, token_type in reversed(tokens):
|
for token_start, token_length, token_type in reversed(tokens):
|
||||||
end = token_start + token_length
|
end = token_start + token_length
|
||||||
if token_type < token_types.PERIOD.value:
|
if token_type in (comma, hyphen):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
end = token_start
|
end = token_start
|
||||||
|
|||||||
Reference in New Issue
Block a user