Skip to content

Removed code for Ruby 1.8 #421

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

Merged
merged 3 commits into from
Sep 7, 2016
Merged
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
4 changes: 1 addition & 3 deletions lib/rdoc/code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def comment=(comment)
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
Expand Down Expand Up @@ -427,4 +426,3 @@ def suppressed?
end

end

3 changes: 1 addition & 2 deletions lib/rdoc/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def parse
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, '')
Expand All @@ -227,4 +227,3 @@ def tomdoc?
end

end

75 changes: 35 additions & 40 deletions lib/rdoc/encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,41 @@ def self.read_file filename, encoding, force_transcode = false

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

Expand Down Expand Up @@ -103,11 +101,8 @@ def self.set_encoding string

remove_frozen_string_literal string

return unless Object.const_defined? :Encoding

enc = Encoding.find name
string.force_encoding enc if enc
end

end

6 changes: 2 additions & 4 deletions lib/rdoc/generator/darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def render_template template_file, out_file = nil # :yield: io

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

Expand Down Expand Up @@ -744,8 +744,7 @@ def template_for file, page = true, klass = ERB
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(/\..*/, '')

Expand All @@ -758,4 +757,3 @@ def template_for file, page = true, klass = ERB
end

end

3 changes: 1 addition & 2 deletions lib/rdoc/generator/json_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def generate
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
Expand Down Expand Up @@ -295,4 +295,3 @@ def search_string string
end

end

18 changes: 1 addition & 17 deletions lib/rdoc/markup/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def initialize
@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
Expand Down Expand Up @@ -324,15 +322,7 @@ def build_verbatim margin
# 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

##
Expand Down Expand Up @@ -430,11 +420,6 @@ def setup_scanner input
@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

Expand Down Expand Up @@ -556,4 +541,3 @@ def unget
end

end

38 changes: 13 additions & 25 deletions lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,15 @@ def init_ivars # :nodoc:
@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']
Expand Down Expand Up @@ -689,19 +681,16 @@ def parse argv
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|
Expand Down Expand Up @@ -1242,11 +1231,10 @@ def write_options
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

5 changes: 1 addition & 4 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ def initialize(top_level, file_name, content, options, stats)
@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
Expand Down Expand Up @@ -2158,4 +2156,3 @@ def warn message
end

end

3 changes: 1 addition & 2 deletions lib/rdoc/parser/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ def remove_coding_comment text
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

6 changes: 2 additions & 4 deletions lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,8 @@ def list_files_in_directory dir
# 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

Expand Down
2 changes: 0 additions & 2 deletions lib/rdoc/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def setup

@top_level = nil

@have_encoding = Object.const_defined? :Encoding

@RM = RDoc::Markup

RDoc::Markup::PreProcess.reset
Expand Down
29 changes: 7 additions & 22 deletions lib/rdoc/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -71,7 +71,7 @@ def expand_tabs 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

Expand All @@ -93,7 +93,7 @@ def flush_left text
end

empty = ''
empty.force_encoding text.encoding if Object.const_defined? :Encoding
empty.force_encoding text.encoding

text.gsub(/^ {0,#{indent}}/, empty)
end
Expand Down Expand Up @@ -160,7 +160,7 @@ def strip_hashes 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
Expand All @@ -178,7 +178,7 @@ def strip_newlines 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:.#=!?]+%, ''

Expand All @@ -199,24 +199,9 @@ def strip_stars 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
Expand Down
Loading