[localecfg] Be slightly more conservative interpreting comments

- A valid line (as explained in the comments at the top of
   the locale.gen file) is <locale> <encoding> (two fields),
   so lines with more than two fields can't be valid locale-
   listing lines. For them, pretend they name locale "",
   which won't be matched.
main
Adriaan de Groot 7 years ago
parent 8551653575
commit 25f249180b

@ -34,6 +34,7 @@ def is_comment(line):
"""
return bool(RE_IS_COMMENT.match(line))
RE_TRAILING_COMMENT = re.compile("#.*$")
RE_REST_OF_LINE = re.compile("\\s.*$")
def extract_locale(line):
"""
@ -46,9 +47,14 @@ def extract_locale(line):
# Remove leading spaces and comment signs
line = RE_IS_COMMENT.sub("", line)
uncommented = line.strip()
# Drop all but first field
locale = RE_REST_OF_LINE.sub("", uncommented)
return locale, uncommented
fields = RE_TRAILING_COMMENT.sub("", uncommented).strip().split()
if len(fields) != 2:
# Not exactly two fields, can't be a proper locale line
return "", uncommented
else:
# Drop all but first field
locale = RE_REST_OF_LINE.sub("", uncommented)
return locale, uncommented
def rewrite_locale_gen(srcfilename, destfilename, locale_conf):

Loading…
Cancel
Save