Class: PhpSerialization::Tokenizer

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

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Tokenizer

Returns a new instance of Tokenizer.



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

def initialize(string)
  @string = string
end

Instance Method Details

#each {|[false, '$']| ... } ⇒ Object

Yields:

  • ([false, '$'])


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

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