Re-use parse_tags. Handle new tag '' in replace.

This commit is contained in:
Arun Prakash Jana 2016-05-23 21:27:06 +05:30
parent 29be3f6072
commit 5af7a961f7
No known key found for this signature in database
GPG Key ID: C0A712ED95043DCB

24
buku
View File

@ -565,23 +565,7 @@ class BukuDb:
if new is None:
delete = True
else:
for tag in new:
if tag[-1] == ',':
tag = tag.strip(',') + ',' # if delimiter is present, maintain it
else:
tag = tag.strip(',') # a token in a multi-word tag
if tag == ',':
continue
if newtags[-1] == ',':
newtags += tag
else:
newtags += ' ' + tag
if newtags[-1] != ',':
newtags += ','
newtags = parse_tags(new)
if newtags == ',':
delete = True
@ -852,6 +836,9 @@ def parse_tags(keywords=[]):
# Cleanse and get the tags
for tag in keywords:
if tag == '':
continue
if tag[0] == ',': # delimiter precedes token (e.g. token1 ,token2)
if tags[-1] != ',':
tags += ','
@ -871,6 +858,9 @@ def parse_tags(keywords=[]):
else:
tags += ' ' + tag
if tags == ',':
return tags
if tags[-1] != ',':
tags += ','