Skip to content

Commit 85d5676

Browse files
authored
Merge pull request #421 from rdoc/removed-ruby18-code
Removed code for Ruby 1.8
2 parents 18f7c3f + 18b2388 commit 85d5676

26 files changed

+73
-247
lines changed

lib/rdoc/code_object.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def comment=(comment)
150150
else
151151
# HACK correct fix is to have #initialize create @comment
152152
# with the correct encoding
153-
if String === @comment and
154-
Object.const_defined? :Encoding and @comment.empty? then
153+
if String === @comment and @comment.empty? then
155154
@comment.force_encoding comment.encoding
156155
end
157156
@comment
@@ -427,4 +426,3 @@ def suppressed?
427426
end
428427

429428
end
430-

lib/rdoc/comment.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def parse
200200
def remove_private
201201
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
202202
empty = ''
203-
empty.force_encoding @text.encoding if Object.const_defined? :Encoding
203+
empty.force_encoding @text.encoding
204204

205205
@text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
206206
@text = @text.sub(%r%^\s*[#*]?--.*%m, '')
@@ -227,4 +227,3 @@ def tomdoc?
227227
end
228228

229229
end
230-

lib/rdoc/encoding.rb

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,41 @@ def self.read_file filename, encoding, force_transcode = false
2525

2626
RDoc::Encoding.set_encoding content
2727

28-
if Object.const_defined? :Encoding then
29-
begin
30-
encoding ||= Encoding.default_external
31-
orig_encoding = content.encoding
32-
33-
if not orig_encoding.ascii_compatible? then
34-
content.encode! encoding
35-
elsif utf8 then
36-
content.force_encoding Encoding::UTF_8
37-
content.encode! encoding
38-
else
39-
# assume the content is in our output encoding
40-
content.force_encoding encoding
41-
end
42-
43-
unless content.valid_encoding? then
44-
# revert and try to transcode
45-
content.force_encoding orig_encoding
46-
content.encode! encoding
47-
end
48-
49-
unless content.valid_encoding? then
50-
warn "unable to convert #{filename} to #{encoding}, skipping"
51-
content = nil
52-
end
53-
rescue Encoding::InvalidByteSequenceError,
54-
Encoding::UndefinedConversionError => e
55-
if force_transcode then
56-
content.force_encoding orig_encoding
57-
content.encode!(encoding,
58-
:invalid => :replace, :undef => :replace,
59-
:replace => '?')
60-
return content
61-
else
62-
warn "unable to convert #{e.message} for #{filename}, skipping"
63-
return nil
64-
end
28+
begin
29+
encoding ||= Encoding.default_external
30+
orig_encoding = content.encoding
31+
32+
if not orig_encoding.ascii_compatible? then
33+
content.encode! encoding
34+
elsif utf8 then
35+
content.force_encoding Encoding::UTF_8
36+
content.encode! encoding
37+
else
38+
# assume the content is in our output encoding
39+
content.force_encoding encoding
40+
end
41+
42+
unless content.valid_encoding? then
43+
# revert and try to transcode
44+
content.force_encoding orig_encoding
45+
content.encode! encoding
46+
end
47+
48+
unless content.valid_encoding? then
49+
warn "unable to convert #{filename} to #{encoding}, skipping"
50+
content = nil
51+
end
52+
rescue Encoding::InvalidByteSequenceError,
53+
Encoding::UndefinedConversionError => e
54+
if force_transcode then
55+
content.force_encoding orig_encoding
56+
content.encode!(encoding,
57+
:invalid => :replace, :undef => :replace,
58+
:replace => '?')
59+
return content
60+
else
61+
warn "unable to convert #{e.message} for #{filename}, skipping"
62+
return nil
6563
end
6664
end
6765

@@ -103,11 +101,8 @@ def self.set_encoding string
103101

104102
remove_frozen_string_literal string
105103

106-
return unless Object.const_defined? :Encoding
107-
108104
enc = Encoding.find name
109105
string.force_encoding enc if enc
110106
end
111107

112108
end
113-

lib/rdoc/generator/darkfish.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def render_template template_file, out_file = nil # :yield: io
698698

699699
out_file.dirname.mkpath
700700
out_file.open 'w', 0644 do |io|
701-
io.set_encoding @options.encoding if Object.const_defined? :Encoding
701+
io.set_encoding @options.encoding
702702

703703
@context = yield io
704704

@@ -744,8 +744,7 @@ def template_for file, page = true, klass = ERB
744744
erbout = 'io'
745745
else
746746
template = file.read
747-
template = template.encode @options.encoding if
748-
Object.const_defined? :Encoding
747+
template = template.encode @options.encoding
749748

750749
file_var = File.basename(file).sub(/\..*/, '')
751750

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

760759
end
761-

lib/rdoc/generator/json_index.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def generate
142142
FileUtils.mkdir_p index_file.dirname, :verbose => $DEBUG_RDOC
143143

144144
index_file.open 'w', 0644 do |io|
145-
io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
145+
io.set_encoding Encoding::UTF_8
146146
io.write 'var search_data = '
147147

148148
JSON.dump data, io, 0
@@ -295,4 +295,3 @@ def search_string string
295295
end
296296

297297
end
298-

lib/rdoc/markup/parser.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def initialize
7979
@binary_input = nil
8080
@current_token = nil
8181
@debug = false
82-
@have_encoding = Object.const_defined? :Encoding
83-
@have_byteslice = ''.respond_to? :byteslice
8482
@input = nil
8583
@input_encoding = nil
8684
@line = 0
@@ -324,15 +322,7 @@ def build_verbatim margin
324322
# The character offset for the input string at the given +byte_offset+
325323

326324
def char_pos byte_offset
327-
if @have_byteslice then
328-
@input.byteslice(0, byte_offset).length
329-
elsif @have_encoding then
330-
matched = @binary_input[0, byte_offset]
331-
matched.force_encoding @input_encoding
332-
matched.length
333-
else
334-
byte_offset
335-
end
325+
@input.byteslice(0, byte_offset).length
336326
end
337327

338328
##
@@ -430,11 +420,6 @@ def setup_scanner input
430420
@line_pos = 0
431421
@input = input.dup
432422

433-
if @have_encoding and not @have_byteslice then
434-
@input_encoding = @input.encoding
435-
@binary_input = @input.force_encoding Encoding::BINARY
436-
end
437-
438423
@s = StringScanner.new input
439424
end
440425

@@ -556,4 +541,3 @@ def unget
556541
end
557542

558543
end
559-

lib/rdoc/options.rb

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -379,23 +379,15 @@ def init_ivars # :nodoc:
379379
@visibility = :protected
380380
@webcvs = nil
381381
@write_options = false
382-
383-
if Object.const_defined? :Encoding then
384-
@encoding = Encoding::UTF_8
385-
@charset = @encoding.name
386-
else
387-
@encoding = nil
388-
@charset = 'UTF-8'
389-
end
382+
@encoding = Encoding::UTF_8
383+
@charset = @encoding.name
390384
end
391385

392386
def init_with map # :nodoc:
393387
init_ivars
394388

395389
encoding = map['encoding']
396-
@encoding = if Object.const_defined? :Encoding then
397-
encoding ? Encoding.find(encoding) : encoding
398-
end
390+
@encoding = encoding ? Encoding.find(encoding) : encoding
399391

400392
@charset = map['charset']
401393
@exclude = map['exclude']
@@ -689,19 +681,16 @@ def parse argv
689681
opt.separator "Parsing options:"
690682
opt.separator nil
691683

692-
if Object.const_defined? :Encoding then
693-
opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
694-
"Specifies the output encoding. All files",
695-
"read will be converted to this encoding.",
696-
"The default encoding is UTF-8.",
697-
"--encoding is preferred over --charset") do |value|
698-
@encoding = Encoding.find value
699-
@charset = @encoding.name # may not be valid value
700-
end
701-
702-
opt.separator nil
703-
end
684+
opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
685+
"Specifies the output encoding. All files",
686+
"read will be converted to this encoding.",
687+
"The default encoding is UTF-8.",
688+
"--encoding is preferred over --charset") do |value|
689+
@encoding = Encoding.find value
690+
@charset = @encoding.name # may not be valid value
691+
end
704692

693+
opt.separator nil
705694

706695
opt.on("--locale=NAME",
707696
"Specifies the output locale.") do |value|
@@ -1242,11 +1231,10 @@ def write_options
12421231
RDoc.load_yaml
12431232

12441233
open '.rdoc_options', 'w' do |io|
1245-
io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
1234+
io.set_encoding Encoding::UTF_8
12461235

12471236
YAML.dump self, io
12481237
end
12491238
end
12501239

12511240
end
1252-

lib/rdoc/parser/ruby.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def initialize(top_level, file_name, content, options, stats)
170170
@prev_seek = nil
171171
@markup = @options.markup
172172
@track_visibility = :nodoc != @options.visibility
173-
174-
@encoding = nil
175-
@encoding = @options.encoding if Object.const_defined? :Encoding
173+
@encoding = @options.encoding
176174

177175
reset
178176
end
@@ -2158,4 +2156,3 @@ def warn message
21582156
end
21592157

21602158
end
2161-

lib/rdoc/parser/simple.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ def remove_coding_comment text
5252
def remove_private_comment comment
5353
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
5454
empty = ''
55-
empty.force_encoding comment.encoding if Object.const_defined? :Encoding
55+
empty.force_encoding comment.encoding
5656

5757
comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty)
5858
comment.sub(%r%^--\n.*%m, empty)
5959
end
6060

6161
end
62-

lib/rdoc/rdoc.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,8 @@ def list_files_in_directory dir
340340
# Parses +filename+ and returns an RDoc::TopLevel
341341

342342
def parse_file filename
343-
if Object.const_defined? :Encoding then
344-
encoding = @options.encoding
345-
filename = filename.encode encoding
346-
end
343+
encoding = @options.encoding
344+
filename = filename.encode encoding
347345

348346
@stats.add_file filename
349347

0 commit comments

Comments
 (0)