summaryrefslogtreecommitdiff
path: root/lib/rexml/text.rb
diff options
context:
space:
mode:
-rw-r--r--lib/rexml/text.rb47
1 files changed, 24 insertions, 23 deletions
@@ -42,6 +42,7 @@ module REXML
# 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 ) #-> "&lt;&amp;"
# Text.new( "<&", false, nil, true ) #-> Parse exception
# Text.new( "&lt;&amp;", false, nil, true ) #-> "&lt;&amp;"
# # Assume that the entity "s" is defined to be "sean"
@@ -172,17 +173,6 @@ module REXML
end
@unnormalized = Text::unnormalize( @string, doctype )
end
-
- def wrap(string, width, addnewline=false)
- # Recursivly wrap string at width.
- return string if string.length <= width
- place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
- if addnewline then
- return "\n" + string[0,place] + "\n" + wrap(string[place+1..-1], width)
- else
- return string[0,place] + "\n" + wrap(string[place+1..-1], width)
- end
- end
# Sets the contents of this text node. This expects the text to be
# unnormalized. It returns self.
@@ -198,17 +188,28 @@ module REXML
@raw = false
end
- def indent_text(string, level=1, style="\t", indentfirstline=true)
- return string if level < 0
- new_string = ''
- string.each { |line|
- indent_string = style * level
- new_line = (indent_string + line).sub(/[\s]+$/,'')
- new_string << new_line
- }
- new_string.strip! unless indentfirstline
- return new_string
end
def write( writer, indent=-1, transitive=false, ie_hack=false )
s = to_s()
@@ -286,9 +287,10 @@ module REXML
def Text::normalize( input, doctype=nil, entity_filter=nil )
copy = input
# Doing it like this rather than in a loop improves the speed
if doctype
# Replace all ampersands that aren't part of an entity
- copy = copy.gsub( EREFERENCE, '&amp;' )
doctype.entities.each_value do |entity|
copy = copy.gsub( entity.value,
"&#{entity.name};" ) if entity.value and
@@ -296,7 +298,6 @@ module REXML
end
else
# Replace all ampersands that aren't part of an entity
- copy = copy.gsub( EREFERENCE, '&amp;' )
DocType::DEFAULT_ENTITIES.each_value do |entity|
copy = copy.gsub(entity.value, "&#{entity.name};" )
end