diff options
Diffstat (limited to 'lib/rexml/xmldecl.rb')
-rw-r--r-- | lib/rexml/xmldecl.rb | 35 |
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 |