* lib/rexml/document.rb (REXML::Document#write): Add :encoding option

to support custom XML encoding.
  [Feature #4872] (work in progress)
* test/rexml/test_document.rb: Add tests for the above change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2012-10-28 06:43:38 +00:00
Родитель 292c659b5c
Коммит af83fcfe4d
3 изменённых файлов: 36 добавлений и 5 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Sun Oct 28 15:41:50 2012 Kouhei Sutou <kou@cozmixng.org>
* lib/rexml/document.rb (REXML::Document#write): Add :encoding option
to support custom XML encoding.
[Feature #4872] (work in progress)
* test/rexml/test_document.rb: Add tests for the above change.
Sun Oct 28 15:00:19 2012 Kouhei Sutou <kou@cozmixng.org>
* lib/rexml/document.rb (REXML::Document#write): Remove needless

Просмотреть файл

@ -207,17 +207,19 @@ module REXML
indent = options[:indent]
transitive = options[:transitive]
ie_hack = options[:ie_hack]
encoding = options[:encoding]
else
output, indent, transitive, ie_hack, = *arguments
output, indent, transitive, ie_hack, encoding, = *arguments
end
output ||= $stdout
indent ||= -1
output ||= $stdout
indent ||= -1
transitive = false if transitive.nil?
ie_hack = false if ie_hack.nil?
encoding ||= xml_decl.encoding
if xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output)
output = Output.new( output, xml_decl.encoding )
if encoding != 'UTF-8' && !output.kind_of?(Output)
output = Output.new( output, encoding )
end
formatter = if indent > -1
if transitive

Просмотреть файл

@ -159,6 +159,19 @@ EOX
document.write(output, indent, transitive, ie_hack)
assert_equal("<empty />", output)
end
def test_encoding
output = ""
indent = -1
transitive = false
ie_hack = false
encoding = "Shift_JIS"
@document.write(output, indent, transitive, ie_hack, encoding)
assert_equal(<<-EOX, output)
<?xml version='1.0' encoding='SHIFT_JIS'?>
<message>Hello world!</message>
EOX
end
end
class OptionsTest < self
@ -199,6 +212,15 @@ EOX
document.write(:output => output, :ie_hack => true)
assert_equal("<empty />", output)
end
def test_encoding
output = ""
@document.write(:output => output, :encoding => "Shift_JIS")
assert_equal(<<-EOX, output)
<?xml version='1.0' encoding='SHIFT_JIS'?>
<message>Hello world!</message>
EOX
end
end
end
end