Method: REXML::Text#initialize
- Defined in:
-
lib/extensions/rexml/rexml/text.rb,
lib/extensions/rhoxml/rexml/text.rb
Constructor arg if a String, the content is set to the String. If a Text, the object is shallowly cloned.
respect_whitespace (boolean, false) if true, whitespace is respected
parent (nil) if this is a Parent object, the parent will be set to this.
raw (nil) This argument can be given three values. If true, then the value of used to construct this object is expected to contain no unescaped XML markup, and REXML will not change the text. If this value is false, the string may contain any characters, and REXML will escape any and all defined entities whose values are contained in the text. If this value is nil (the default), then the raw value of the parent will be used as the raw value for this node. If there is no raw value for the parent, and no value is supplied, the default is false. Use this field if you have entities defined for some text, and you don’t want REXML to escape that text in output.
Text.new( "<&", false, nil, false ) #-> "<&"
Text.new( "<&", false, nil, false ) #-> "&lt;&amp;"
Text.new( "<&", false, nil, true ) #-> Parse exception
Text.new( "<&", false, nil, true ) #-> "<&"
# Assume that the entity "s" is defined to be "sean"
# and that the entity "r" is defined to be "russell"
Text.new( "sean russell" ) #-> "&s; &r;"
Text.new( "sean russell", false, nil, true ) #-> "sean russell"
entity_filter (nil) This can be an array of entities to match in the supplied text. This argument is only useful if raw is set to false.
Text.new( "sean russell", false, nil, false, ["s"] ) #-> "&s; russell"
Text.new( "sean russell", false, nil, true, ["s"] ) #-> "sean russell"
In the last example, the entity_filter argument is ignored.
illegal INTERNAL USE ONLY
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/extensions/rexml/rexml/text.rb', line 92 def initialize(arg, respect_whitespace=false, parent=nil, raw=nil, entity_filter=nil, illegal=NEEDS_A_SECOND_CHECK ) @raw = false @parent = nil if parent super( parent ) @raw = parent.raw end @raw = raw unless raw.nil? @entity_filter = entity_filter @normalized = @unnormalized = nil if arg.kind_of? String @string = arg.dup @string.squeeze!(" \n\t") unless respect_whitespace elsif arg.kind_of? Text @string = arg.to_s @raw = arg.raw elsif raise "Illegal argument of type #{arg.type} for Text constructor (#{arg})" end @string.gsub!( /\r\n?/, "\n" ) Text.check(@string, illegal, doctype) if @raw end |