Class: RubyPhpSerialization::Tokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_php_serialization/tokenizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Tokenizer

Returns a new instance of Tokenizer.



3
4
5
# File 'lib/ruby_php_serialization/tokenizer.rb', line 3

def initialize(string)
  @string = string
end

Instance Method Details

#next_tokenObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ruby_php_serialization/tokenizer.rb', line 7

def next_token
  token = nil

  token = case @string
  when /\A[0-9]+(\.[0-9]+)?/m then [:NUMBER, $&]
  when /\A"([^"]*)"/m         then [:STRING, $1]
  when /\A[^\s]/m             then [$&, $&]
  end
  @string = $'

  token unless token.nil?
end