|
8 | 8 | *
|
9 | 9 | * New BSD License
|
10 | 10 | *
|
11 |
| - * Copyright © 2007-2015, Ivan Enderlin. All rights reserved. |
| 11 | + * Copyright © 2007-2015, Hoa community. All rights reserved. |
12 | 12 | *
|
13 | 13 | * Redistribution and use in source and binary forms, with or without
|
14 | 14 | * modification, are permitted provided that the following conditions are met:
|
|
34 | 34 | * POSSIBILITY OF SUCH DAMAGE.
|
35 | 35 | */
|
36 | 36 |
|
37 |
| -namespace { |
| 37 | +namespace Hoa\Stringbuffer; |
38 | 38 |
|
39 |
| -from('Hoa') |
40 |
| - |
41 |
| -/** |
42 |
| - * \Hoa\Stringbuffer\Exception |
43 |
| - */ |
44 |
| --> import('Stringbuffer.Exception') |
45 |
| - |
46 |
| -/** |
47 |
| - * \Hoa\Stringbuffer |
48 |
| - */ |
49 |
| --> import('Stringbuffer.~') |
50 |
| - |
51 |
| -/** |
52 |
| - * \Hoa\Stream\IStream\In |
53 |
| - */ |
54 |
| --> import('Stream.I~.In'); |
55 |
| - |
56 |
| -} |
57 |
| - |
58 |
| -namespace Hoa\Stringbuffer { |
| 39 | +use Hoa\Stream; |
59 | 40 |
|
60 | 41 | /**
|
61 | 42 | * Class \Hoa\Stringbuffer\Read.
|
62 | 43 | *
|
63 | 44 | * Read a string buffer.
|
64 | 45 | *
|
65 |
| - * @author Ivan Enderlin <ivan.enderlin@hoa-project.net> |
66 |
| - * @copyright Copyright © 2007-2015 Ivan Enderlin. |
| 46 | + * @copyright Copyright © 2007-2015 Hoa community |
67 | 47 | * @license New BSD License
|
68 | 48 | */
|
69 |
| - |
70 |
| -class Read extends Stringbuffer implements \Hoa\Stream\IStream\In { |
71 |
| - |
| 49 | +class Read extends Stringbuffer implements Stream\IStream\In |
| 50 | +{ |
72 | 51 | /**
|
73 | 52 | * Test for end-of-file.
|
74 | 53 | *
|
75 |
| - * @access public |
76 | 54 | * @return bool
|
77 | 55 | */
|
78 |
| - public function eof ( ) { |
79 |
| - |
| 56 | + public function eof() |
| 57 | + { |
80 | 58 | return feof($this->getStream());
|
81 | 59 | }
|
82 | 60 |
|
83 | 61 | /**
|
84 | 62 | * Read n characters.
|
85 | 63 | *
|
86 |
| - * @access public |
87 | 64 | * @param int $length Length.
|
88 | 65 | * @return string
|
89 |
| - * @throw \Hoa\Stringbuffer\Exception |
| 66 | + * @throws \Hoa\Stringbuffer\Exception |
90 | 67 | */
|
91 |
| - public function read ( $length ) { |
92 |
| - |
93 |
| - if(0 > $length) |
| 68 | + public function read($length) |
| 69 | + { |
| 70 | + if (0 > $length) { |
94 | 71 | throw new Exception(
|
95 |
| - 'Length must be greater than 0, given %d.', 0, $length); |
| 72 | + 'Length must be greater than 0, given %d.', |
| 73 | + 0, |
| 74 | + $length |
| 75 | + ); |
| 76 | + } |
96 | 77 |
|
97 | 78 | return fread($this->getStream(), $length);
|
98 | 79 | }
|
99 | 80 |
|
100 | 81 | /**
|
101 | 82 | * Alias of $this->read().
|
102 | 83 | *
|
103 |
| - * @access public |
104 | 84 | * @param int $length Length.
|
105 | 85 | * @return string
|
106 | 86 | */
|
107 |
| - public function readString ( $length ) { |
108 |
| - |
| 87 | + public function readString($length) |
| 88 | + { |
109 | 89 | return $this->read($length);
|
110 | 90 | }
|
111 | 91 |
|
112 | 92 | /**
|
113 | 93 | * Read a character.
|
114 | 94 | *
|
115 |
| - * @access public |
116 | 95 | * @return string
|
117 | 96 | */
|
118 |
| - public function readCharacter ( ) { |
119 |
| - |
| 97 | + public function readCharacter() |
| 98 | + { |
120 | 99 | return fgetc($this->getStream());
|
121 | 100 | }
|
122 | 101 |
|
123 | 102 | /**
|
124 | 103 | * Read a boolean.
|
125 | 104 | *
|
126 |
| - * @access public |
127 | 105 | * @return bool
|
128 | 106 | */
|
129 |
| - public function readBoolean ( ) { |
130 |
| - |
| 107 | + public function readBoolean() |
| 108 | + { |
131 | 109 | return (bool) $this->read(1);
|
132 | 110 | }
|
133 | 111 |
|
134 | 112 | /**
|
135 | 113 | * Read an integer.
|
136 | 114 | *
|
137 |
| - * @access public |
138 | 115 | * @param int $length Length.
|
139 | 116 | * @return int
|
140 | 117 | */
|
141 |
| - public function readInteger ( $length = 1 ) { |
142 |
| - |
| 118 | + public function readInteger($length = 1) |
| 119 | + { |
143 | 120 | return (int) $this->read($length);
|
144 | 121 | }
|
145 | 122 |
|
146 | 123 | /**
|
147 | 124 | * Read a float.
|
148 | 125 | *
|
149 |
| - * @access public |
150 | 126 | * @param int $length Length.
|
151 | 127 | * @return float
|
152 | 128 | */
|
153 |
| - public function readFloat ( $length = 1 ) { |
154 |
| - |
| 129 | + public function readFloat($length = 1) |
| 130 | + { |
155 | 131 | return (float) $this->read($length);
|
156 | 132 | }
|
157 | 133 |
|
158 | 134 | /**
|
159 | 135 | * Read an array.
|
160 | 136 | * Alias of the $this->scanf() method.
|
161 | 137 | *
|
162 |
| - * @access public |
163 | 138 | * @param string $format Format (see printf's formats).
|
164 | 139 | * @return array
|
165 | 140 | */
|
166 |
| - public function readArray ( $format = null ) { |
167 |
| - |
| 141 | + public function readArray($format = null) |
| 142 | + { |
168 | 143 | return $this->scanf($format);
|
169 | 144 | }
|
170 | 145 |
|
171 | 146 | /**
|
172 | 147 | * Read a line.
|
173 | 148 | *
|
174 |
| - * @access public |
175 | 149 | * @return string
|
176 | 150 | */
|
177 |
| - public function readLine ( ) { |
178 |
| - |
| 151 | + public function readLine() |
| 152 | + { |
179 | 153 | return fgets($this->getStream());
|
180 | 154 | }
|
181 | 155 |
|
182 | 156 | /**
|
183 | 157 | * Read all, i.e. read as much as possible.
|
184 | 158 | *
|
185 |
| - * @access public |
186 | 159 | * @param int $offset Offset.
|
187 | 160 | * @return string
|
188 | 161 | */
|
189 |
| - public function readAll ( $offset = 0 ) { |
190 |
| - |
| 162 | + public function readAll($offset = 0) |
| 163 | + { |
191 | 164 | return stream_get_contents($this->getStream(), -1, $offset);
|
192 | 165 | }
|
193 | 166 |
|
194 | 167 | /**
|
195 | 168 | * Parse input from a stream according to a format.
|
196 | 169 | *
|
197 |
| - * @access public |
198 | 170 | * @param string $format Format (see printf's formats).
|
199 | 171 | * @return array
|
200 | 172 | */
|
201 |
| - public function scanf ( $format ) { |
202 |
| - |
| 173 | + public function scanf($format) |
| 174 | + { |
203 | 175 | return fscanf($this->getStream(), $format);
|
204 | 176 | }
|
205 | 177 |
|
206 | 178 | /**
|
207 | 179 | * Transform this object to a string.
|
208 | 180 | *
|
209 |
| - * @access public |
210 | 181 | * @return string
|
211 | 182 | */
|
212 |
| - public function __toString ( ) { |
213 |
| - |
| 183 | + public function __toString() |
| 184 | + { |
214 | 185 | return $this->readAll();
|
215 | 186 | }
|
216 | 187 | }
|
217 |
| - |
218 |
| -} |
0 commit comments