From ba6ae341bab83dfc7a624c5bf20d8d162dacaff9 Mon Sep 17 00:00:00 2001 From: hsbt Date: Wed, 7 Sep 2016 22:23:38 +0000 Subject: * lib/rdoc/*, test/rdoc/*: Update rdoc-5.0.0.beta2 Fixed ri parse defect with left-hand matched classes. https://github.com/rdoc/rdoc/pull/420 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/code_object.rb | 4 +-- lib/rdoc/comment.rb | 3 +- lib/rdoc/encoding.rb | 75 +++++++++++++++++++--------------------- lib/rdoc/generator/darkfish.rb | 6 ++-- lib/rdoc/generator/json_index.rb | 3 +- lib/rdoc/markup/parser.rb | 18 +--------- lib/rdoc/options.rb | 38 +++++++------------- lib/rdoc/parser/ruby.rb | 5 +-- lib/rdoc/parser/simple.rb | 3 +- lib/rdoc/rdoc.gemspec | 3 +- lib/rdoc/rdoc.rb | 23 +++++------- lib/rdoc/ri/driver.rb | 3 +- lib/rdoc/ri/paths.rb | 3 -- lib/rdoc/ri/task.rb | 1 - lib/rdoc/rubygems_hook.rb | 2 -- lib/rdoc/task.rb | 2 -- lib/rdoc/test_case.rb | 4 --- lib/rdoc/text.rb | 29 ++++------------ 18 files changed, 74 insertions(+), 151 deletions(-) (limited to 'lib/rdoc') diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index dc195cc6ac..21aa2b09f5 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -150,8 +150,7 @@ class RDoc::CodeObject else # HACK correct fix is to have #initialize create @comment # with the correct encoding - if String === @comment and - Object.const_defined? :Encoding and @comment.empty? then + if String === @comment and @comment.empty? then @comment.force_encoding comment.encoding end @comment @@ -427,4 +426,3 @@ class RDoc::CodeObject end end - diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index ebff742233..c655763b3e 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -200,7 +200,7 @@ class RDoc::Comment def remove_private # Workaround for gsub encoding for Ruby 1.9.2 and earlier empty = '' - empty.force_encoding @text.encoding if Object.const_defined? :Encoding + empty.force_encoding @text.encoding @text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty) @text = @text.sub(%r%^\s*[#*]?--.*%m, '') @@ -227,4 +227,3 @@ class RDoc::Comment end end - diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb index 1056827937..44881d043c 100644 --- a/lib/rdoc/encoding.rb +++ b/lib/rdoc/encoding.rb @@ -25,43 +25,41 @@ module RDoc::Encoding RDoc::Encoding.set_encoding content - if Object.const_defined? :Encoding then - begin - encoding ||= Encoding.default_external - orig_encoding = content.encoding - - if not orig_encoding.ascii_compatible? then - content.encode! encoding - elsif utf8 then - content.force_encoding Encoding::UTF_8 - content.encode! encoding - else - # assume the content is in our output encoding - content.force_encoding encoding - end - - unless content.valid_encoding? then - # revert and try to transcode - content.force_encoding orig_encoding - content.encode! encoding - end - - unless content.valid_encoding? then - warn "unable to convert #{filename} to #{encoding}, skipping" - content = nil - end - rescue Encoding::InvalidByteSequenceError, - Encoding::UndefinedConversionError => e - if force_transcode then - content.force_encoding orig_encoding - content.encode!(encoding, - :invalid => :replace, :undef => :replace, - :replace => '?') - return content - else - warn "unable to convert #{e.message} for #{filename}, skipping" - return nil - end + begin + encoding ||= Encoding.default_external + orig_encoding = content.encoding + + if not orig_encoding.ascii_compatible? then + content.encode! encoding + elsif utf8 then + content.force_encoding Encoding::UTF_8 + content.encode! encoding + else + # assume the content is in our output encoding + content.force_encoding encoding + end + + unless content.valid_encoding? then + # revert and try to transcode + content.force_encoding orig_encoding + content.encode! encoding + end + + unless content.valid_encoding? then + warn "unable to convert #{filename} to #{encoding}, skipping" + content = nil + end + rescue Encoding::InvalidByteSequenceError, + Encoding::UndefinedConversionError => e + if force_transcode then + content.force_encoding orig_encoding + content.encode!(encoding, + :invalid => :replace, :undef => :replace, + :replace => '?') + return content + else + warn "unable to convert #{e.message} for #{filename}, skipping" + return nil end end @@ -103,11 +101,8 @@ module RDoc::Encoding remove_frozen_string_literal string - return unless Object.const_defined? :Encoding - enc = Encoding.find name string.force_encoding enc if enc end end - diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 18394a2c34..e961518fcc 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -698,7 +698,7 @@ class RDoc::Generator::Darkfish out_file.dirname.mkpath out_file.open 'w', 0644 do |io| - io.set_encoding @options.encoding if Object.const_defined? :Encoding + io.set_encoding @options.encoding @context = yield io @@ -744,8 +744,7 @@ class RDoc::Generator::Darkfish erbout = 'io' else template = file.read - template = template.encode @options.encoding if - Object.const_defined? :Encoding + template = template.encode @options.encoding file_var = File.basename(file).sub(/\..*/, '') @@ -758,4 +757,3 @@ class RDoc::Generator::Darkfish end end - diff --git a/lib/rdoc/generator/json_index.rb b/lib/rdoc/generator/json_index.rb index 624a2e512e..931438b3c3 100644 --- a/lib/rdoc/generator/json_index.rb +++ b/lib/rdoc/generator/json_index.rb @@ -142,7 +142,7 @@ class RDoc::Generator::JsonIndex FileUtils.mkdir_p index_file.dirname, :verbose => $DEBUG_RDOC index_file.open 'w', 0644 do |io| - io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding + io.set_encoding Encoding::UTF_8 io.write 'var search_data = ' JSON.dump data, io, 0 @@ -295,4 +295,3 @@ class RDoc::Generator::JsonIndex end end - diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb index 2f8b7628e2..22cca20420 100644 --- a/lib/rdoc/markup/parser.rb +++ b/lib/rdoc/markup/parser.rb @@ -79,8 +79,6 @@ class RDoc::Markup::Parser @binary_input = nil @current_token = nil @debug = false - @have_encoding = Object.const_defined? :Encoding - @have_byteslice = ''.respond_to? :byteslice @input = nil @input_encoding = nil @line = 0 @@ -324,15 +322,7 @@ class RDoc::Markup::Parser # The character offset for the input string at the given +byte_offset+ def char_pos byte_offset - if @have_byteslice then - @input.byteslice(0, byte_offset).length - elsif @have_encoding then - matched = @binary_input[0, byte_offset] - matched.force_encoding @input_encoding - matched.length - else - byte_offset - end + @input.byteslice(0, byte_offset).length end ## @@ -430,11 +420,6 @@ class RDoc::Markup::Parser @line_pos = 0 @input = input.dup - if @have_encoding and not @have_byteslice then - @input_encoding = @input.encoding - @binary_input = @input.force_encoding Encoding::BINARY - end - @s = StringScanner.new input end @@ -556,4 +541,3 @@ class RDoc::Markup::Parser end end - diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 17b0bb105d..2bc7474eb0 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -379,23 +379,15 @@ class RDoc::Options @visibility = :protected @webcvs = nil @write_options = false - - if Object.const_defined? :Encoding then - @encoding = Encoding::UTF_8 - @charset = @encoding.name - else - @encoding = nil - @charset = 'UTF-8' - end + @encoding = Encoding::UTF_8 + @charset = @encoding.name end def init_with map # :nodoc: init_ivars encoding = map['encoding'] - @encoding = if Object.const_defined? :Encoding then - encoding ? Encoding.find(encoding) : encoding - end + @encoding = encoding ? Encoding.find(encoding) : encoding @charset = map['charset'] @exclude = map['exclude'] @@ -689,19 +681,16 @@ Usage: #{opt.program_name} [options] [names...] opt.separator "Parsing options:" opt.separator nil - if Object.const_defined? :Encoding then - opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name }, - "Specifies the output encoding. All files", - "read will be converted to this encoding.", - "The default encoding is UTF-8.", - "--encoding is preferred over --charset") do |value| - @encoding = Encoding.find value - @charset = @encoding.name # may not be valid value - end - - opt.separator nil - end + opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name }, + "Specifies the output encoding. All files", + "read will be converted to this encoding.", + "The default encoding is UTF-8.", + "--encoding is preferred over --charset") do |value| + @encoding = Encoding.find value + @charset = @encoding.name # may not be valid value + end + opt.separator nil opt.on("--locale=NAME", "Specifies the output locale.") do |value| @@ -1242,11 +1231,10 @@ Usage: #{opt.program_name} [options] [names...] RDoc.load_yaml open '.rdoc_options', 'w' do |io| - io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding + io.set_encoding Encoding::UTF_8 YAML.dump self, io end end end - diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index ac7094f488..c30dbf0f4e 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -170,9 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser @prev_seek = nil @markup = @options.markup @track_visibility = :nodoc != @options.visibility - - @encoding = nil - @encoding = @options.encoding if Object.const_defined? :Encoding + @encoding = @options.encoding reset end @@ -2158,4 +2156,3 @@ class RDoc::Parser::Ruby < RDoc::Parser end end - diff --git a/lib/rdoc/parser/simple.rb b/lib/rdoc/parser/simple.rb index 73bb7bdffb..f2ab27a92e 100644 --- a/lib/rdoc/parser/simple.rb +++ b/lib/rdoc/parser/simple.rb @@ -52,11 +52,10 @@ class RDoc::Parser::Simple < RDoc::Parser def remove_private_comment comment # Workaround for gsub encoding for Ruby 1.9.2 and earlier empty = '' - empty.force_encoding comment.encoding if Object.const_defined? :Encoding + empty.force_encoding comment.encoding comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty) comment.sub(%r%^--\n.*%m, empty) end end - diff --git a/lib/rdoc/rdoc.gemspec b/lib/rdoc/rdoc.gemspec index 606021f8b1..74d7a152bd 100644 --- a/lib/rdoc/rdoc.gemspec +++ b/lib/rdoc/rdoc.gemspec @@ -6,8 +6,7 @@ Gem::Specification.new do |s| s.name = "rdoc" s.version = RDoc::VERSION - s.required_rubygems_version = Gem::Requirement.new(">= 1.3") if - s.respond_to? :required_rubygems_version= + s.required_rubygems_version = Gem::Requirement.new(">= 1.3") s.require_paths = ["lib"] s.authors = [ diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 89ba6619aa..ec50d8eba5 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -340,10 +340,8 @@ option) # Parses +filename+ and returns an RDoc::TopLevel def parse_file filename - if Object.const_defined? :Encoding then - encoding = @options.encoding - filename = filename.encode encoding - end + encoding = @options.encoding + filename = filename.encode encoding @stats.add_file filename @@ -553,16 +551,14 @@ end begin require 'rubygems' - if Gem.respond_to? :find_files then - rdoc_extensions = Gem.find_files 'rdoc/discover' + rdoc_extensions = Gem.find_files 'rdoc/discover' - rdoc_extensions.each do |extension| - begin - load extension - rescue => e - warn "error loading #{extension.inspect}: #{e.message} (#{e.class})" - warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG - end + rdoc_extensions.each do |extension| + begin + load extension + rescue => e + warn "error loading #{extension.inspect}: #{e.message} (#{e.class})" + warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG end end rescue LoadError @@ -572,4 +568,3 @@ end require 'rdoc/generator/darkfish' require 'rdoc/generator/ri' require 'rdoc/generator/pot' - diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 3bd0e50d84..7942406ceb 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -908,7 +908,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the def expand_class klass ary = classes.keys.grep(Regexp.new("\\A#{klass.gsub(/(?=::|\z)/, '[^:]*')}\\z")) - raise NotFoundError, klass if ary.length != 1 + raise NotFoundError, klass if ary.length != 1 && ary.first != klass ary.first end @@ -1480,4 +1480,3 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the end end - diff --git a/lib/rdoc/ri/paths.rb b/lib/rdoc/ri/paths.rb index 41529a3e0d..94db2216a2 100644 --- a/lib/rdoc/ri/paths.rb +++ b/lib/rdoc/ri/paths.rb @@ -82,8 +82,6 @@ module RDoc::RI::Paths # ri documentation. def self.gemdirs filter = :latest - require 'rubygems' unless defined?(Gem) - ri_paths = {} all = Gem::Specification.map do |spec| @@ -185,4 +183,3 @@ module RDoc::RI::Paths end end - diff --git a/lib/rdoc/ri/task.rb b/lib/rdoc/ri/task.rb index d45f0c664c..cc0a85d4b7 100644 --- a/lib/rdoc/ri/task.rb +++ b/lib/rdoc/ri/task.rb @@ -1,5 +1,4 @@ # frozen_string_literal: false -require 'rubygems' begin gem 'rdoc' rescue Gem::LoadError diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index f6aeb84598..e2afb1fa91 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -1,5 +1,4 @@ # frozen_string_literal: false -require 'rubygems' require 'rubygems/user_interaction' require 'fileutils' require 'rdoc' @@ -251,4 +250,3 @@ class RDoc::RubygemsHook end end - diff --git a/lib/rdoc/task.rb b/lib/rdoc/task.rb index 0577677054..1074de0197 100644 --- a/lib/rdoc/task.rb +++ b/lib/rdoc/task.rb @@ -22,7 +22,6 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -require 'rubygems' begin gem 'rdoc' rescue Gem::LoadError @@ -328,4 +327,3 @@ module Rake end # :startdoc: - diff --git a/lib/rdoc/test_case.rb b/lib/rdoc/test_case.rb index 3b928f2f3d..7c80ecdf9c 100644 --- a/lib/rdoc/test_case.rb +++ b/lib/rdoc/test_case.rb @@ -1,6 +1,4 @@ # frozen_string_literal: false -require 'rubygems' - begin gem 'minitest', '~> 4.0' unless defined?(Test::Unit) rescue NoMethodError, Gem::LoadError @@ -41,8 +39,6 @@ class RDoc::TestCase < MiniTest::Unit::TestCase @top_level = nil - @have_encoding = Object.const_defined? :Encoding - @RM = RDoc::Markup RDoc::Markup::PreProcess.reset diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb index b40c89806a..a38bb921ad 100644 --- a/lib/rdoc/text.rb +++ b/lib/rdoc/text.rb @@ -52,7 +52,7 @@ module RDoc::Text :open_squote => encode_fallback('‘', encoding, '\''), :trademark => encode_fallback('®', encoding, '(r)'), } - end if Object.const_defined? :Encoding + end ## # Transcodes +character+ to +encoding+ with a +fallback+ character. @@ -71,7 +71,7 @@ module RDoc::Text text.each_line do |line| nil while line.gsub!(/(?:\G|\r)((?:.{8})*?)([^\t\r\n]{0,7})\t/) do r = "#{$1}#{$2}#{' ' * (8 - $2.size)}" - r.force_encoding text.encoding if Object.const_defined? :Encoding + r.force_encoding text.encoding r end @@ -93,7 +93,7 @@ module RDoc::Text end empty = '' - empty.force_encoding text.encoding if Object.const_defined? :Encoding + empty.force_encoding text.encoding text.gsub(/^ {0,#{indent}}/, empty) end @@ -160,7 +160,7 @@ module RDoc::Text return text if text =~ /^(?>\s*)[^\#]/ empty = '' - empty.force_encoding text.encoding if Object.const_defined? :Encoding + empty.force_encoding text.encoding text.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }.gsub(/^\s+$/, empty) end @@ -178,7 +178,7 @@ module RDoc::Text def strip_stars text return text unless text =~ %r%/\*.*\*/%m - encoding = text.encoding if Object.const_defined? :Encoding + encoding = text.encoding text = text.gsub %r%Document-method:\s+[\w:.#=!?]+%, '' @@ -199,24 +199,9 @@ module RDoc::Text # trademark symbols in +text+ to properly encoded characters. def to_html text - if Object.const_defined? :Encoding then - html = ''.encode text.encoding + html = ''.encode text.encoding - encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding] - else - html = '' - encoded = { - :close_dquote => '”', - :close_squote => '’', - :copyright => '©', - :ellipsis => '…', - :em_dash => '—', - :en_dash => '–', - :open_dquote => '“', - :open_squote => '‘', - :trademark => '®', - } - end + encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding] s = StringScanner.new text insquotes = false -- cgit v1.2.3