2003-06-10 05:31:01 +04:00
|
|
|
require 'rexml/encoding'
|
|
|
|
|
|
|
|
module REXML
|
2008-10-01 17:46:53 +04:00
|
|
|
class Output
|
|
|
|
include Encoding
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2003-12-09 05:41:33 +03:00
|
|
|
attr_reader :encoding
|
|
|
|
|
2008-10-01 17:46:53 +04:00
|
|
|
def initialize real_IO, encd="iso-8859-1"
|
|
|
|
@output = real_IO
|
|
|
|
self.encoding = encd
|
2003-06-10 05:31:01 +04:00
|
|
|
|
2012-11-03 09:43:28 +04:00
|
|
|
@to_utf = encoding != 'UTF-8'
|
2012-11-03 09:42:40 +04:00
|
|
|
|
|
|
|
if encoding == "UTF-16"
|
|
|
|
@output << "\ufeff".encode("UTF-16BE")
|
|
|
|
self.encoding = "UTF-16BE"
|
|
|
|
end
|
2008-10-01 17:46:53 +04:00
|
|
|
end
|
2003-06-10 05:31:01 +04:00
|
|
|
|
2008-10-01 17:46:53 +04:00
|
|
|
def <<( content )
|
|
|
|
@output << (@to_utf ? self.encode(content) : content)
|
|
|
|
end
|
2003-12-09 05:41:33 +03:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
"Output[#{encoding}]"
|
|
|
|
end
|
2008-10-01 17:46:53 +04:00
|
|
|
end
|
2003-06-10 05:31:01 +04:00
|
|
|
end
|