2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# We manage a set of attributes. Each attribute has a symbol name and a bit
|
|
|
|
# value.
|
|
|
|
|
|
|
|
class RDoc::Markup::Attributes
|
|
|
|
|
|
|
|
##
|
2018-10-17 02:28:20 -04:00
|
|
|
# The regexp handling attribute type. See RDoc::Markup#add_regexp_handling
|
2012-11-26 23:28:14 -05:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
attr_reader :regexp_handling
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a new attributes set.
|
|
|
|
|
|
|
|
def initialize
|
2018-10-17 02:28:20 -04:00
|
|
|
@regexp_handling = 1
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
@name_to_bitmap = [
|
2018-10-17 02:28:20 -04:00
|
|
|
[:_REGEXP_HANDLING_, @regexp_handling],
|
2012-11-26 23:28:14 -05:00
|
|
|
]
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
@next_bitmap = @regexp_handling << 1
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns a unique bit for +name+
|
|
|
|
|
|
|
|
def bitmap_for name
|
|
|
|
bitmap = @name_to_bitmap.assoc name
|
|
|
|
|
|
|
|
unless bitmap then
|
|
|
|
bitmap = @next_bitmap
|
|
|
|
@next_bitmap <<= 1
|
|
|
|
@name_to_bitmap << [name, bitmap]
|
|
|
|
else
|
|
|
|
bitmap = bitmap.last
|
|
|
|
end
|
|
|
|
|
|
|
|
bitmap
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns a string representation of +bitmap+
|
|
|
|
|
|
|
|
def as_string bitmap
|
|
|
|
return 'none' if bitmap.zero?
|
|
|
|
res = []
|
|
|
|
|
|
|
|
@name_to_bitmap.each do |name, bit|
|
|
|
|
res << name if (bitmap & bit) != 0
|
|
|
|
end
|
|
|
|
|
|
|
|
res.join ','
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# yields each attribute name in +bitmap+
|
|
|
|
|
|
|
|
def each_name_of bitmap
|
|
|
|
return enum_for __method__, bitmap unless block_given?
|
|
|
|
|
|
|
|
@name_to_bitmap.each do |name, bit|
|
2018-10-17 02:28:20 -04:00
|
|
|
next if bit == @regexp_handling
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
yield name.to_s if (bitmap & bit) != 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|