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