[TASK] Implemented getBufferLength() and getNextChars()

This commit is contained in:
Jan Philipp Timme 2010-12-19 17:56:58 +00:00
parent 3880b59f94
commit e424ea2cbe
1 changed files with 15 additions and 5 deletions

View File

@ -3,7 +3,6 @@
* Buffer class for a string.
* Will fix issues with sockets that don't care about linebreaks.
* 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
* @package Misc
*/
@ -76,12 +75,23 @@ class Misc_Buffer {
}
/**
* Returns the next $length chars from the buffer.
* @return string Returns "" if no
* Returns the length of the buffer.
* @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) {
//TODO: substr und so
throw new Exception_GeneralException("This feature is not implemented yet!", 1291824224);
if(strlen($this->buffer) < $length) throw new Exception_GeneralException("Cannot return ".$length." chars, there are only ".strlen($this->buffer)." chars left!", 1292780386);
$data = substr($this->buffer, 0, $length);
$this->buffer = substr($this->buffer, $length);
return $data;
}
/**