class Prism::ASCIISource
Prism::Source 的专用版本,用于仅包含 ASCII 字符的源代码。此类用于应用不能应用于包含多字节字符的源的性能优化。
在极少数情况下,如果源包含多字节字符但由于魔术编码注释而被标记为二进制,并且无法主动转换为 UTF-8,那么此类也将被使用。这是因为在那时,我们将所有内容都视为单字节字符。
Public Instance Methods
Source
# File lib/prism/parse_result.rb, line 248 def character_column(byte_offset) byte_offset - line_start(byte_offset) end
返回给定字节偏移量处的字符列号。
Source
# File lib/prism/parse_result.rb, line 243 def character_offset(byte_offset) byte_offset end
返回给定字节偏移量处的字符偏移量。
Source
# File lib/prism/parse_result.rb, line 265 def code_units_cache(encoding) ->(byte_offset) { byte_offset } end
返回一个缓存,该缓存是恒等函数,以保持相同的接口。我们可以这样做,因为对于仅 ASCII 源,代码单元始终等同于字节偏移量。
Source
# File lib/prism/parse_result.rb, line 272 def code_units_column(byte_offset, encoding) byte_offset - line_start(byte_offset) end
code_units_column 的专用版本,不依赖于 code_units_offset(这是一个更昂贵的操作)。这基本上与 Prism::Source#column 相同。
Source
# File lib/prism/parse_result.rb, line 258 def code_units_offset(byte_offset, encoding) byte_offset end
返回给定字节偏移量处到文件开头的偏移量,以给定编码的代码单元计数。
此方法已使用 UTF-8、UTF-16 和 UTF-32 进行测试。如果存在与其他编码中的字符数不同的代码单元的概念,则此处未捕获。