* @package Mammut\IO */ class StringBuffer extends Buffer implements iCharOutput, iLineReader { use CharOutputIterator; const _VERSION_ = '0.5.0.0'; private $charset; public function getCharset() { return $this->charset; } /** * Put data into the buffer. * * If no charset is defined (or set to false/null), the method tries to detect it. * * @param mixed $data * @see \Mammut\IO\Buffer::setBuffer() */ public function setBuffer($data) { parent::setBuffer($data); if(empty($this->charset)) $this->charset = mb_detect_encoding($data); } public function setCharset($charset) { $this->charset = $charset; } public function isMultibyte() { return strtolower($this->charset) == 'utf-8'; } public function readLine($trim = true) { if($this->isEOF()) return false; $result = ''; while(!$this->isEOF()) { $ch = $this->readChar(); $ord = ord($ch); if($trim && ($ord == 10 || $ord == 13)) break; $result .= $ch; if(!$trim && ($ord == 10 || $ord == 13)) break; } return $result; } }