[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)) return bool(RE_IS_COMMENT.match(line))
RE_TRAILING_COMMENT = re.compile("#.*$")
RE_REST_OF_LINE = re.compile("\\s.*$") RE_REST_OF_LINE = re.compile("\\s.*$")
def extract_locale(line): def extract_locale(line):
""" """
@ -46,9 +47,14 @@ def extract_locale(line):
# Remove leading spaces and comment signs # Remove leading spaces and comment signs
line = RE_IS_COMMENT.sub("", line) line = RE_IS_COMMENT.sub("", line)
uncommented = line.strip() uncommented = line.strip()
# Drop all but first field fields = RE_TRAILING_COMMENT.sub("", uncommented).strip().split()
locale = RE_REST_OF_LINE.sub("", uncommented) if len(fields) != 2:
return locale, uncommented # 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): def rewrite_locale_gen(srcfilename, destfilename, locale_conf):

Loading…
Cancel
Save