Skip to content

Commit 6600f2d

Browse files
authored
Merge pull request #851 from nobu/simplify
Simplify attribute exclusiveness conditions
2 parents 186f5fe + 45e33c4 commit 6600f2d

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

lib/rdoc/markup/attribute_manager.rb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ def convert_attrs(str, attrs, exclusive = false)
147147
def convert_attrs_matching_word_pairs(str, attrs, exclusive)
148148
# first do matching ones
149149
tags = @matching_word_pairs.select { |start, bitmap|
150-
if exclusive && exclusive?(bitmap)
151-
true
152-
elsif !exclusive && !exclusive?(bitmap)
153-
true
154-
else
155-
false
156-
end
150+
exclusive == exclusive?(bitmap)
157151
}.keys
158152
return if tags.empty?
159153
all_tags = @matching_word_pairs.keys
@@ -176,11 +170,7 @@ def convert_attrs_word_pair_map(str, attrs, exclusive)
176170
# then non-matching
177171
unless @word_pair_map.empty? then
178172
@word_pair_map.each do |regexp, attr|
179-
if !exclusive
180-
next if exclusive?(attr)
181-
else
182-
next if !exclusive?(attr)
183-
end
173+
next unless exclusive == exclusive?(attr)
184174
1 while str.gsub!(regexp) { |orig|
185175
updated = attrs.set_attrs($`.length + $1.length, $2.length, attr)
186176
if updated
@@ -198,13 +188,7 @@ def convert_attrs_word_pair_map(str, attrs, exclusive)
198188

199189
def convert_html(str, attrs, exclusive = false)
200190
tags = @html_tags.select { |start, bitmap|
201-
if exclusive && exclusive?(bitmap)
202-
true
203-
elsif !exclusive && !exclusive?(bitmap)
204-
true
205-
else
206-
false
207-
end
191+
exclusive == exclusive?(bitmap)
208192
}.keys.join '|'
209193

210194
1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig|
@@ -221,11 +205,7 @@ def convert_html(str, attrs, exclusive = false)
221205

222206
def convert_regexp_handlings str, attrs, exclusive = false
223207
@regexp_handlings.each do |regexp, attribute|
224-
if exclusive
225-
next if !exclusive?(attribute)
226-
else
227-
next if exclusive?(attribute)
228-
end
208+
next unless exclusive == exclusive?(attribute)
229209
str.scan(regexp) do
230210
capture = $~.size == 1 ? 0 : 1
231211

lib/rdoc/parser/c.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ def handle_method(type, var_name, meth_name, function, param_count,
10151015
elsif p_count == -1 then # argc, argv
10161016
rb_scan_args body
10171017
else
1018-
"(#{(1..p_count).map { |i| "p#{i}" }.join ', '})"
1018+
args = (1..p_count).map { |i| "p#{i}" }
1019+
"(#{args.join ', '})"
10191020
end
10201021

10211022

test/rdoc/test_rdoc_parser_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def test_parse_class_lower_name_warning
921921
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
922922
end
923923
err = stds[1]
924-
assert_match(/Expected class name or '<<'\. Got/, err)
924+
assert_match(/Expected class name or '<<\'\. Got/, err)
925925
end
926926

927927
def test_parse_syntax_error_code

0 commit comments

Comments
 (0)