Class HTML5::EncodingBytes
In: lib/feed_tools/vendor/html5/lib/html5/inputstream.rb
Parent: String

String-like object with an assosiated position and various extra methods If the position is ever greater than the string length then an exception is raised

Methods

current_byte   each   find_next   jump_to   match_bytes   new   skip  

Attributes

position  [RW] 

Public Class methods

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 351
351:     def initialize(value)
352:       super(value)
353:       @position = -1
354:     end

Public Instance methods

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 364
364:     def current_byte
365:       raise EOF if @position >= length
366:       return self[@position].chr
367:     end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 356
356:     def each
357:       while @position < length
358:         @position += 1
359:         yield self[@position]
360:       end
361:     rescue EOF
362:     end

Move the pointer so it points to the next byte in a set of possible bytes

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 401
401:     def find_next(byte_list)
402:       until byte_list.include?(current_byte)
403:         @position += 1
404:       end
405:     end

Look for the next sequence of bytes matching a given sequence. If a match is found advance the position to the last byte of the match

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 389
389:     def jump_to(bytes)
390:       new_position = self[position .. -1].index(bytes)
391:       if new_position
392:         @position += (new_position + bytes.length-1)
393:         return true
394:       else
395:         raise EOF
396:       end
397:     end

Look for a sequence of bytes at the start of a string. If the bytes are found return true and advance the position to the byte after the match. Otherwise return false and leave the position alone

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 379
379:     def match_bytes(bytes, lower=false)
380:       data = self[position ... position+bytes.length]
381:       data.downcase! if lower
382:       rv = (data == bytes)
383:       @position += bytes.length if rv == true
384:       return rv
385:     end

Skip past a list of characters

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/inputstream.rb, line 370
370:     def skip(chars=SPACE_CHARACTERS)
371:       while chars.include?(current_byte)
372:         @position += 1
373:       end
374:     end

[Validate]