~ubuntu-branches/ubuntu/utopic/ruby-kpeg/utopic

« back to all changes in this revision

Viewing changes to lib/kpeg/position.rb

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont
  • Date: 2014-04-15 09:01:50 UTC
  • Revision ID: package-import@ubuntu.com-20140415090150-b3pvbpg66n78yp4x
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module KPeg
 
2
  module Position
 
3
    # STANDALONE START
 
4
 
 
5
    def current_column(target=pos)
 
6
      if c = string.rindex("\n", target-1)
 
7
        return target - c - 1
 
8
      end
 
9
 
 
10
      target + 1
 
11
    end
 
12
 
 
13
    def current_line(target=pos)
 
14
      cur_offset = 0
 
15
      cur_line = 0
 
16
 
 
17
      string.each_line do |line|
 
18
        cur_line += 1
 
19
        cur_offset += line.size
 
20
        return cur_line if cur_offset >= target
 
21
      end
 
22
 
 
23
      -1
 
24
    end
 
25
 
 
26
    def lines
 
27
      lines = []
 
28
      string.each_line { |l| lines << l }
 
29
      lines
 
30
    end
 
31
 
 
32
    # STANDALONE END
 
33
 
 
34
  end
 
35
end