[TASK] Implemented getBufferLength() and getNextChars()
This commit is contained in:
parent
3880b59f94
commit
e424ea2cbe
|
@ -3,7 +3,6 @@
|
||||||
* Buffer class for a string.
|
* Buffer class for a string.
|
||||||
* Will fix issues with sockets that don't care about linebreaks.
|
* Will fix issues with sockets that don't care about linebreaks.
|
||||||
* Can also be used for all kinds of purpose.
|
* Can also be used for all kinds of purpose.
|
||||||
* TODO: implement a method to return the next X bytes (return false if not enough bytes there,yet)
|
|
||||||
* @author jpt
|
* @author jpt
|
||||||
* @package Misc
|
* @package Misc
|
||||||
*/
|
*/
|
||||||
|
@ -76,12 +75,23 @@ class Misc_Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next $length chars from the buffer.
|
* Returns the length of the buffer.
|
||||||
* @return string Returns "" if no
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBufferLength() {
|
||||||
|
return strlen($this->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next $length chars from the buffer or throws an exception if this cannot be done.
|
||||||
|
* @throws Exception_GeneralException
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getNextChars($length) {
|
public function getNextChars($length) {
|
||||||
//TODO: substr und so
|
if(strlen($this->buffer) < $length) throw new Exception_GeneralException("Cannot return ".$length." chars, there are only ".strlen($this->buffer)." chars left!", 1292780386);
|
||||||
throw new Exception_GeneralException("This feature is not implemented yet!", 1291824224);
|
$data = substr($this->buffer, 0, $length);
|
||||||
|
$this->buffer = substr($this->buffer, $length);
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue