Skip to content

Commit 4870620

Browse files
committed
REXML 3.1.7.4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent d6d2f17 commit 4870620

File tree

10 files changed

+782
-146
lines changed

10 files changed

+782
-146
lines changed

lib/rexml/doctype.rb

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@
77
require 'rexml/xmltokens'
88

99
module REXML
10+
class ReferenceWriter
11+
def initialize(id_type,
12+
public_id_literal,
13+
system_literal)
14+
@id_type = id_type
15+
@public_id_literal = public_id_literal
16+
@system_literal = system_literal
17+
@default_quote = "\""
18+
end
19+
20+
def write(output)
21+
output << " #{@id_type}"
22+
if @public_id_literal
23+
if @public_id_literal.include?("'")
24+
quote = "\""
25+
else
26+
quote = @default_quote
27+
end
28+
output << " #{quote}#{@public_id_literal}#{quote}"
29+
end
30+
if @system_literal
31+
if @system_literal.include?("'")
32+
quote = "\""
33+
elsif @system_literal.include?("\"")
34+
quote = "'"
35+
else
36+
quote = @default_quote
37+
end
38+
output << " #{quote}#{@system_literal}#{quote}"
39+
end
40+
end
41+
end
42+
1043
# Represents an XML DOCTYPE declaration; that is, the contents of <!DOCTYPE
1144
# ... >. DOCTYPES can be used to declare the DTD of a document, as well as
1245
# being used to declare entities used in the document.
@@ -50,6 +83,8 @@ def initialize( first, parent=nil )
5083
super( parent )
5184
@name = first.name
5285
@external_id = first.external_id
86+
@long_name = first.instance_variable_get(:@long_name)
87+
@uri = first.instance_variable_get(:@uri)
5388
elsif first.kind_of? Array
5489
super( parent )
5590
@name = first[0]
@@ -112,9 +147,12 @@ def write( output, indent=0, transitive=false, ie_hack=false )
112147
output << START
113148
output << ' '
114149
output << @name
115-
output << " #@external_id" if @external_id
116-
output << " #{@long_name.inspect}" if @long_name
117-
output << " #{@uri.inspect}" if @uri
150+
if @external_id
151+
reference_writer = ReferenceWriter.new(@external_id,
152+
@long_name,
153+
@uri)
154+
reference_writer.write(output)
155+
end
118156
unless @children.empty?
119157
output << ' ['
120158
@children.each { |child|
@@ -249,9 +287,9 @@ def initialize name, middle, pub, sys
249287
end
250288

251289
def to_s
252-
notation = "<!NOTATION #{@name} #{@middle}"
253-
notation << " #{@public.inspect}" if @public
254-
notation << " #{@system.inspect}" if @system
290+
notation = "<!NOTATION #{@name}"
291+
reference_writer = ReferenceWriter.new(@middle, @public, @system)
292+
reference_writer.write(notation)
255293
notation << ">"
256294
notation
257295
end

0 commit comments

Comments
 (0)