56 * @return mixed The integer, corresponding to the next 32 bits from |
58 * @return mixed The integer, corresponding to the next 32 bits from |
57 * the stream of false if there are not enough bytes or on error |
59 * the stream of false if there are not enough bytes or on error |
58 */ |
60 */ |
59 public function readint32() { |
61 public function readint32() { |
60 $bytes = $this->read( 4 ); |
62 $bytes = $this->read( 4 ); |
61 if ( 4 != $this->strlen( $bytes ) ) { |
63 if ( 4 !== $this->strlen( $bytes ) ) { |
62 return false; |
64 return false; |
63 } |
65 } |
64 $endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V'; |
66 $endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V'; |
65 $int = unpack( $endian_letter, $bytes ); |
67 $int = unpack( $endian_letter, $bytes ); |
66 return reset( $int ); |
68 return reset( $int ); |
73 * @return mixed Array of integers or false if there isn't |
75 * @return mixed Array of integers or false if there isn't |
74 * enough data or on error |
76 * enough data or on error |
75 */ |
77 */ |
76 public function readint32array( $count ) { |
78 public function readint32array( $count ) { |
77 $bytes = $this->read( 4 * $count ); |
79 $bytes = $this->read( 4 * $count ); |
78 if ( 4 * $count != $this->strlen( $bytes ) ) { |
80 if ( 4 * $count !== $this->strlen( $bytes ) ) { |
79 return false; |
81 return false; |
80 } |
82 } |
81 $endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V'; |
83 $endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V'; |
82 return unpack( $endian_letter . $count, $bytes ); |
84 return unpack( $endian_letter . $count, $bytes ); |
83 } |
85 } |
84 |
86 |
85 /** |
87 /** |
86 * @param string $string |
88 * @param string $input_string |
87 * @param int $start |
89 * @param int $start |
88 * @param int $length |
90 * @param int $length |
89 * @return string |
91 * @return string |
90 */ |
92 */ |
91 public function substr( $string, $start, $length ) { |
93 public function substr( $input_string, $start, $length ) { |
92 if ( $this->is_overloaded ) { |
94 if ( $this->is_overloaded ) { |
93 return mb_substr( $string, $start, $length, 'ascii' ); |
95 return mb_substr( $input_string, $start, $length, 'ascii' ); |
94 } else { |
96 } else { |
95 return substr( $string, $start, $length ); |
97 return substr( $input_string, $start, $length ); |
96 } |
98 } |
97 } |
99 } |
98 |
100 |
99 /** |
101 /** |
100 * @param string $string |
102 * @param string $input_string |
101 * @return int |
103 * @return int |
102 */ |
104 */ |
103 public function strlen( $string ) { |
105 public function strlen( $input_string ) { |
104 if ( $this->is_overloaded ) { |
106 if ( $this->is_overloaded ) { |
105 return mb_strlen( $string, 'ascii' ); |
107 return mb_strlen( $input_string, 'ascii' ); |
106 } else { |
108 } else { |
107 return strlen( $string ); |
109 return strlen( $input_string ); |
108 } |
110 } |
109 } |
111 } |
110 |
112 |
111 /** |
113 /** |
112 * @param string $string |
114 * @param string $input_string |
113 * @param int $chunk_size |
115 * @param int $chunk_size |
114 * @return array |
116 * @return array |
115 */ |
117 */ |
116 public function str_split( $string, $chunk_size ) { |
118 public function str_split( $input_string, $chunk_size ) { |
117 if ( ! function_exists( 'str_split' ) ) { |
119 if ( ! function_exists( 'str_split' ) ) { |
118 $length = $this->strlen( $string ); |
120 $length = $this->strlen( $input_string ); |
119 $out = array(); |
121 $out = array(); |
120 for ( $i = 0; $i < $length; $i += $chunk_size ) { |
122 for ( $i = 0; $i < $length; $i += $chunk_size ) { |
121 $out[] = $this->substr( $string, $i, $chunk_size ); |
123 $out[] = $this->substr( $input_string, $i, $chunk_size ); |
122 } |
124 } |
123 return $out; |
125 return $out; |
124 } else { |
126 } else { |
125 return str_split( $string, $chunk_size ); |
127 return str_split( $input_string, $chunk_size ); |
126 } |
128 } |
127 } |
129 } |
128 |
130 |
129 /** |
131 /** |
130 * @return int |
132 * @return int |