class RBS::Buffer
属性
content[R]
name[R]
公共类方法
new(name:, content:) 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 8 def initialize(name:, content:) @name = name @content = content end
公共实例方法
inspect() 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 63 def inspect "#<RBS::Buffer:#{__id__} @name=#{name}, @content=#{content.bytesize} bytes, @lines=#{lines.size} lines,>" end
last_position() 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 59 def last_position content.size end
lines() 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 13 def lines @lines ||= content.lines end
loc_to_pos(loc) 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 49 def loc_to_pos(loc) line, column = loc if range = ranges[line - 1] range.begin + column else last_position end end
pos_to_loc(pos) 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 37 def pos_to_loc(pos) index = ranges.bsearch_index do |range| pos < range.end ? true : false end if index [index + 1, pos - ranges[index].begin] else [ranges.size + 1, 0] end end
ranges() 点击以切换源代码
# File rbs-3.8.0/lib/rbs/buffer.rb, line 17 def ranges @ranges ||= begin @ranges = [] offset = 0 lines.each do |line| size = line.size range = offset...(offset+size) @ranges << range offset += size end if !content.end_with?("\n") && content.size > 0 @ranges[-1] = @ranges[-1].begin...(@ranges[-1].end+1) end @ranges end end