Skip to content

Fix & Deprecate REXML::Text#text_indent #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rexml/child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def document

# This doesn't yet handle encodings
def bytes
document.encoding
document&.encoding

to_s
end
Expand Down
5 changes: 3 additions & 2 deletions lib/rexml/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,15 @@ def wrap(string, width, addnewline=false)
end

def indent_text(string, level=1, style="\t", indentfirstline=true)
Kernel.warn("#{self.class.name}#indent_text is deprecated. See REXML::Formatters", uplevel: 1)
return string if level < 0
new_string = ''
string.each_line { |line|
indent_string = style * level
new_line = (indent_string + line).sub(/[\s]+$/,'')
new_string << new_line
new_string += new_line
}
new_string.strip! unless indentfirstline
new_string = new_string.strip unless indentfirstline
new_string
end

Expand Down
5 changes: 5 additions & 0 deletions test/test_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ def test_clone
assert_equal(text.to_s,
text.clone.to_s)
end

def test_indent_text
text = Text.new("")
assert_equal("\tline1\tline2\tline3", text.indent_text("line1\r\nline2\r\nline3\r\n"))
end
end
end