Encode true/false, sort keys

This commit is contained in:
Matthias Neeracher 2007-08-30 21:57:48 +00:00
parent 8dacdf5dea
commit e1c8e71c86

View File

@ -18,6 +18,10 @@ end
def _encodePlist(object) def _encodePlist(object)
e = nil e = nil
case object case object
when false then
e = REXML::Element.new("false")
when true then
e = REXML::Element.new("true")
when String then when String then
e = REXML::Element.new("string") e = REXML::Element.new("string")
e.add_text(object) e.add_text(object)
@ -40,11 +44,11 @@ def _encodePlist(object)
end end
when Hash then when Hash then
e = REXML::Element.new("dict") e = REXML::Element.new("dict")
object.each do |key,elt| object.keys.sort.each do |key|
k = REXML::Element.new("key") k = REXML::Element.new("key")
k.add_text(key) k.add_text(key)
e.add_element(k) e.add_element(k)
e.add_element(_encodePlist(elt)) e.add_element(_encodePlist(object[key]))
end end
else else
raise "plistWriter can't encode objects of type `#{object.class}'" raise "plistWriter can't encode objects of type `#{object.class}'"