pb_input_string_reader.php 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Reads string input
  4. */
  5. class PBInputStringReader extends PBInputReader
  6. {
  7. var $length = 0;
  8. public function __construct($string)
  9. {
  10. parent::__construct();
  11. $this->string = $string;
  12. $this->length = strlen($string);
  13. }
  14. /**
  15. * get the next
  16. * @param boolean $is_string - if set to true only one byte is read
  17. */
  18. public function next($is_string = false)
  19. {
  20. $package = '';
  21. while (true)
  22. {
  23. if ($this->pointer >= $this->length)
  24. {
  25. return false;
  26. }
  27. $string = '';
  28. $string = $this->string[$this->pointer];
  29. $this->pointer++;
  30. if ($is_string == true)
  31. return ord($string);
  32. $value = decbin(ord($string));
  33. if ($value >= 10000000 && $is_string == false)
  34. {
  35. // now fill to eight with 00
  36. $package .= $value;
  37. }
  38. else
  39. {
  40. // now fill to length of eight with 0
  41. $value = substr('00000000', 0, 8 - strlen($value) % 8) . $value;
  42. return $this->base128->get_value($package . $value);
  43. }
  44. }
  45. }
  46. }
  47. ?>