lib/rbCFPropertyList.rb in CFPropertyList-2.2.1 vs lib/rbCFPropertyList.rb in CFPropertyList-2.2.2
- old
+ new
@@ -160,11 +160,16 @@
else
case
when Object.const_defined?('BigDecimal') && object.is_a?(BigDecimal)
CFReal.new(object)
when object.respond_to?(:read)
- CFData.new(object.read(), CFData::DATA_RAW)
+ raw_data = object.read
+ # treat the data as a bytestring (ASCII-8BIT) if Ruby supports it. Do this by forcing
+ # the encoding, on the assumption that the bytes were read correctly, and just tagged with
+ # an inappropriate encoding, rather than transcoding.
+ raw_data.force_encoding(Encoding::ASCII_8BIT) if raw_data.respond_to?(:force_encoding)
+ CFData.new(raw_data, CFData::DATA_RAW)
when options[:converter_method] && object.respond_to?(options[:converter_method])
if options[:converter_with_opts]
CFPropertyList.guess(object.send(options[:converter_method],options),options)
else
CFPropertyList.guess(object.send(options[:converter_method]),options)
@@ -378,12 +383,17 @@
# convert plist to string
# format = List::FORMAT_BINARY:: The format to save the plist
# opts={}:: Pass parser options
def to_str(format=List::FORMAT_BINARY,opts={})
+ raise CFFormatError.new("Format #{format} not supported, use List::FORMAT_BINARY or List::FORMAT_XML") if format != FORMAT_BINARY && format != FORMAT_XML
+
prsr = @@parsers[format-1].new
+
opts[:root] = @value
+ opts[:formatted] = @formatted unless opts.has_key?(:formatted)
+
return prsr.to_str(opts)
end
end
end
@@ -393,32 +403,32 @@
def to_plist(options={})
options[:plist_format] ||= CFPropertyList::List::FORMAT_BINARY
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(self, options)
- plist.to_str(options[:plist_format])
+ plist.to_str(options[:plist_format], options)
end
end
class Enumerator
# convert an array to plist format
def to_plist(options={})
options[:plist_format] ||= CFPropertyList::List::FORMAT_BINARY
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(self, options)
- plist.to_str(options[:plist_format])
+ plist.to_str(options[:plist_format], options)
end
end
class Hash
# convert a hash to plist format
def to_plist(options={})
options[:plist_format] ||= CFPropertyList::List::FORMAT_BINARY
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(self, options)
- plist.to_str(options[:plist_format])
+ plist.to_str(options[:plist_format], options)
end
end
# eof