summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-12-08 23:48:12 +0900
committergit <svn-admin@ruby-lang.org>2022-11-27 16:35:07 +0000
commit1b67c58f41a9387d762afffa09c27ced8245c0f6 (patch)
tree806f107a7871358ba9469633def5d07e8d2c5169 /lib
parentd055c44b0cfeeed2d02f8899200863d69758abc1 (diff)
[ruby/rdoc] Pull up handle_tab_width to RDoc::Parser
To share with the duplicate code in RDoc::Parser::Ruby#initialize. https://github.com/ruby/rdoc/commit/27829ac119
Diffstat (limited to 'lib')
-rw-r--r--lib/rdoc/parser.rb17
-rw-r--r--lib/rdoc/parser/c.rb17
-rw-r--r--lib/rdoc/parser/ruby.rb10
3 files changed, 18 insertions, 26 deletions
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb
index 7006265b63..3bb6f5d1f2 100644
--- a/lib/rdoc/parser.rb
+++ b/lib/rdoc/parser.rb
@@ -266,6 +266,23 @@ class RDoc::Parser
autoload :RubyTools, "#{__dir__}/parser/ruby_tools"
autoload :Text, "#{__dir__}/parser/text"
+ ##
+ # Normalizes tabs in +body+
+
+ def handle_tab_width(body)
+ if /\t/ =~ body
+ tab_width = @options.tab_width
+ body.split(/\n/).map do |line|
+ 1 while line.gsub!(/\t+/) do
+ b, e = $~.offset(0)
+ ' ' * (tab_width * (e-b) - b % tab_width)
+ end
+ line
+ end.join "\n"
+ else
+ body
+ end
+ end
end
# simple must come first in order to show up last in the parsers list
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb
index a03e4663e4..5695bf1acb 100644
--- a/lib/rdoc/parser/c.rb
+++ b/lib/rdoc/parser/c.rb
@@ -1058,23 +1058,6 @@ class RDoc::Parser::C < RDoc::Parser
end
##
- # Normalizes tabs in +body+
-
- def handle_tab_width(body)
- if /\t/ =~ body
- tab_width = @options.tab_width
- body.split(/\n/).map do |line|
- 1 while line.gsub!(/\t+/) do
- ' ' * (tab_width * $&.length - $`.length % tab_width)
- end && $~
- line
- end.join "\n"
- else
- body
- end
- end
-
- ##
# Loads the variable map with the given +name+ from the RDoc::Store, if
# present.
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index 3c5f79632c..b74ead65ab 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -164,15 +164,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def initialize(top_level, file_name, content, options, stats)
super
- if /\t/ =~ content then
- tab_width = @options.tab_width
- content = content.split(/\n/).map do |line|
- 1 while line.gsub!(/\t+/) {
- ' ' * (tab_width*$&.length - $`.length % tab_width)
- } && $~
- line
- end.join("\n")
- end
+ content = handle_tab_width(content)
@size = 0
@token_listeners = nil