Fixed parser to add proper newlines in multi-line values

Example:

Key: Value1
 Value2
 Value3

Before: "Value1Value2\nValue"
After: "Value1\nValue2\nValue"
This commit is contained in:
Christoph Haas 2015-04-24 13:48:55 +02:00
parent 061306e09e
commit c944e1ba91

View file

@ -34,7 +34,8 @@ module DebImporter
end # open end # open
end # def initialize end # def initialize
# Get package information from translation (i18n) files # Get package information from translation (i18n) files.
# Returns an enumerator of packages.
def i18n(component, language) def i18n(component, language)
url = "#{@dist_url}/#{component}/i18n/Translation-en" url = "#{@dist_url}/#{component}/i18n/Translation-en"
file = find_and_open_compressed_url(url) file = find_and_open_compressed_url(url)
@ -96,12 +97,16 @@ module DebImporter
when /^(.+): (.+)/ # "Key: Value" when /^(.+): (.+)/ # "Key: Value"
fields[name.to_sym]=value unless value.empty? fields[name.to_sym]=value unless value.empty?
name,value=$1,$2 name,value=$1,$2
when /^(.+):\s*/ # "Key:" (start of multi-line entry) when /^(.+):$/ # "Key:" (start of multi-line entry without value in line)
fields[name.to_sym]=value unless value.empty? fields[name.to_sym]=value unless value.empty?
name=$1 name=$1
value='' value=''
when /^\s+(.+)/ # " Indented multi-line value" when /^\s+(.+)/ # " Indented multi-line value"
value << $1+"\n" # Add a newline for multi-line entries ("Key: Value\n Foo\n Bar")
unless value.empty?
value << "\n"
end
value << $1
when /^\s+$/ # Empty line when /^\s+$/ # Empty line
break break
end end