summaryrefslogtreecommitdiff
path: root/lib/rexml/xmldecl.rb
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-20 02:49:10 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-20 02:49:10 +0000
commit0d1abb904e9eda11dfed19181553725764a3d950 (patch)
tree0fc7858ebbc6c76f81249c37ce3ed0c31a8d5253 /lib/rexml/xmldecl.rb
parent0b38221d4ea75d8ac96b2adb1f7fafb0b20f9d29 (diff)
rexml: upgrade to 3.1.8
See https://github.com/ruby/rexml/blob/master/NEWS.md for change summary. Changes for spec/ has been reported: https://github.com/ruby/spec/pull/639 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/xmldecl.rb')
-rw-r--r--lib/rexml/xmldecl.rb35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/rexml/xmldecl.rb b/lib/rexml/xmldecl.rb
index d02204931c..89c0747d49 100644
--- a/lib/rexml/xmldecl.rb
+++ b/lib/rexml/xmldecl.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: false
+
require_relative 'encoding'
require_relative 'source'
@@ -7,11 +8,11 @@ module REXML
class XMLDecl < Child
include Encoding
- DEFAULT_VERSION = "1.0";
- DEFAULT_ENCODING = "UTF-8";
- DEFAULT_STANDALONE = "no";
- START = '<\?xml';
- STOP = '\?>';
+ DEFAULT_VERSION = "1.0"
+ DEFAULT_ENCODING = "UTF-8"
+ DEFAULT_STANDALONE = "no"
+ START = "<?xml"
+ STOP = "?>"
attr_accessor :version, :standalone
attr_reader :writeencoding, :writethis
@@ -46,9 +47,9 @@ module REXML
# Ignored
def write(writer, indent=-1, transitive=false, ie_hack=false)
return nil unless @writethis or writer.kind_of? Output
- writer << START.sub(/\\/u, '')
+ writer << START
writer << " #{content encoding}"
- writer << STOP.sub(/\\/u, '')
+ writer << STOP
end
def ==( other )
@@ -102,14 +103,26 @@ module REXML
end
def inspect
- START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
+ "#{START} ... #{STOP}"
end
private
def content(enc)
- rv = "version='#@version'"
- rv << " encoding='#{enc}'" if @writeencoding || enc !~ /\Autf-8\z/i
- rv << " standalone='#@standalone'" if @standalone
+ context = nil
+ context = parent.context if parent
+ if context and context[:prologue_quote] == :quote
+ quote = "\""
+ else
+ quote = "'"
+ end
+
+ rv = "version=#{quote}#{@version}#{quote}"
+ if @writeencoding or enc !~ /\Autf-8\z/i
+ rv << " encoding=#{quote}#{enc}#{quote}"
+ end
+ if @standalone
+ rv << " standalone=#{quote}#{@standalone}#{quote}"
+ end
rv
end
end