File: position.rb

package info (click to toggle)
ruby-sass 3.7.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,396 kB
  • sloc: ruby: 32,443; sh: 26; makefile: 25
file content (39 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Sass::Source
  class Position
    # The one-based line of the document associated with the position.
    #
    # @return [Integer]
    attr_accessor :line

    # The one-based offset in the line of the document associated with the
    # position.
    #
    # @return [Integer]
    attr_accessor :offset

    # @param line [Integer] The source line
    # @param offset [Integer] The source offset
    def initialize(line, offset)
      @line = line
      @offset = offset
    end

    # @return [String] A string representation of the source position.
    def inspect
      "#{line.inspect}:#{offset.inspect}"
    end

    # @param str [String] The string to move through.
    # @return [Position] The source position after proceeding forward through
    #   `str`.
    def after(str)
      newlines = str.count("\n")
      Position.new(line + newlines,
        if newlines == 0
          offset + str.length
        else
          str.length - str.rindex("\n") - 1
        end)
    end
  end
end