1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
module ActiveLdap
module Compatible
module_function
if "".respond_to?(:force_encoding)
def convert_to_utf8_encoded_object(object)
case object
when Array
object.collect {|element| convert_to_utf8_encoded_object(element)}
when Hash
encoded = {}
object.each do |key, value|
key = convert_to_utf8_encoded_object(key)
value = convert_to_utf8_encoded_object(value)
encoded[key] = value
end
encoded
when String
encoded = object.dup
encoded.force_encoding("utf-8")
encoded = object unless encoded.valid_encoding?
encoded
else
object
end
end
else
def convert_to_utf8_encoded_object(object)
object
end
end
if "".respond_to?(:lines)
def string_to_lines(string)
string.lines.to_a
end
else
def string_to_lines(string)
ary = []
string.each_line{|l| ary << l}
ary
end
end
end
end
|