Class: ZergXcode::ScanBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/zerg_xcode/file_format/scan_buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ ScanBuffer

Returns a new instance of ScanBuffer.



4
5
6
7
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 4

def initialize(string)
  @string = string
  @i = 0
end

Instance Method Details

#advance(n = 1) ⇒ Object



25
26
27
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 25

def advance(n=1)
  @i += n
end

#at?(literal) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 17

def at?(literal)
  peek(literal.length) == literal
end

#at_beginning?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 9

def at_beginning?
  @i == 0
end

#at_end?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 13

def at_end?
  @i == @string.length
end

#match_and_advance(pattern) ⇒ Object



39
40
41
42
43
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 39

def match_and_advance(pattern)
  match = @string[@i..-1].match(pattern)
  @i += match[0].length if match
  match
end

#peek(n = 1) ⇒ Object



29
30
31
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 29

def peek(n=1)
  @string[@i, n]
end

#take(n = 1) ⇒ Object



33
34
35
36
37
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 33

def take(n=1)
  result = peek(n)
  advance(n)
  result
end

#unconsumedObject



21
22
23
# File 'lib/zerg_xcode/file_format/scan_buffer.rb', line 21

def unconsumed
  @string[@i..-1]
end