11<?php
22namespace PHPHtmlParser ;
33
4+ /**
5+ * Class Content
6+ *
7+ * @package PHPHtmlParser
8+ */
49class Content {
510
611 /**
@@ -32,15 +37,25 @@ class Content {
3237 protected $ blank = " \t\r\n" ;
3338 protected $ equal = ' =/> ' ;
3439 protected $ slash = " /> \r\n\t" ;
35- protected $ attr = ' > ' ;
40+ protected $ attr = ' > ' ;
3641
42+ /**
43+ * Content constructor.
44+ *
45+ * @param $content
46+ */
3747 public function __construct ($ content )
3848 {
3949 $ this ->content = $ content ;
4050 $ this ->size = strlen ($ content );
4151 $ this ->pos = 0 ;
4252 }
4353
54+ /**
55+ * Returns the current position of the content.
56+ *
57+ * @return int
58+ */
4459 public function getPosition ()
4560 {
4661 return $ this ->pos ;
@@ -77,6 +92,7 @@ public function char($char = null)
7792 public function fastForward ($ count )
7893 {
7994 $ this ->pos += $ count ;
95+
8096 return $ this ;
8197 }
8298
@@ -93,6 +109,7 @@ public function rewind($count)
93109 {
94110 $ this ->pos = 0 ;
95111 }
112+
96113 return $ this ;
97114 }
98115
@@ -115,8 +132,8 @@ public function copyUntil($string, $char = false, $escape = false)
115132 if ($ escape )
116133 {
117134 $ position = $ this ->pos ;
118- $ found = false ;
119- while ( ! $ found )
135+ $ found = false ;
136+ while ( ! $ found )
120137 {
121138 $ position = strpos ($ this ->content , $ string , $ position );
122139 if ($ position === false )
@@ -138,7 +155,7 @@ public function copyUntil($string, $char = false, $escape = false)
138155 }
139156 elseif ($ char )
140157 {
141- $ position = strcspn ($ this ->content , $ string , $ this ->pos );
158+ $ position = strcspn ($ this ->content , $ string , $ this ->pos );
142159 $ position += $ this ->pos ;
143160 }
144161 else
@@ -151,6 +168,7 @@ public function copyUntil($string, $char = false, $escape = false)
151168 // could not find character, just return the remaining of the content
152169 $ return = substr ($ this ->content , $ this ->pos , $ this ->size - $ this ->pos );
153170 $ this ->pos = $ this ->size ;
171+
154172 return $ return ;
155173 }
156174
@@ -163,6 +181,7 @@ public function copyUntil($string, $char = false, $escape = false)
163181 $ return = substr ($ this ->content , $ this ->pos , $ position - $ this ->pos );
164182 // set the new position
165183 $ this ->pos = $ position ;
184+
166185 return $ return ;
167186 }
168187
@@ -187,6 +206,7 @@ public function copyUntilUnless($string, $unless)
187206 }
188207 // rewind changes and return nothing
189208 $ this ->pos = $ lastPos ;
209+
190210 return '' ;
191211 }
192212
@@ -202,6 +222,7 @@ public function copyUntilUnless($string, $unless)
202222 public function copyByToken ($ token , $ char = false , $ escape = false )
203223 {
204224 $ string = $ this ->$ token ;
225+
205226 return $ this ->copyUntil ($ string , $ char , $ escape );
206227 }
207228
@@ -215,7 +236,7 @@ public function copyByToken($token, $char = false, $escape = false)
215236 public function skip ($ string , $ copy = false )
216237 {
217238 $ len = strspn ($ this ->content , $ string , $ this ->pos );
218-
239+
219240 // make it chainable if they don't want a copy
220241 $ return = $ this ;
221242 if ($ copy )
@@ -240,6 +261,7 @@ public function skip($string, $copy = false)
240261 public function skipByToken ($ token , $ copy = false )
241262 {
242263 $ string = $ this ->$ token ;
264+
243265 return $ this ->skip ($ string , $ copy );
244266 }
245267}
0 commit comments