Swift_CharacterStream_ArrayCharacterStream::read PHP Метод

read() публичный Метод

Read $length characters from the stream and move the internal pointer $length further into the stream.
public read ( integer $length ) : string
$length integer
Результат string
    public function read($length)
    {
        if ($this->_offset == $this->_array_size) {
            return false;
        }
        // Don't use array slice
        $arrays = array();
        $end = $length + $this->_offset;
        for ($i = $this->_offset; $i < $end; ++$i) {
            if (!isset($this->_array[$i])) {
                break;
            }
            $arrays[] = $this->_array[$i];
        }
        $this->_offset += $i - $this->_offset;
        // Limit function calls
        $chars = false;
        foreach ($arrays as $array) {
            $chars .= implode('', array_map('chr', $array));
        }
        return $chars;
    }

Usage Example

 public function testAlgorithmWithFixedWidthCharsets()
 {
     $reader = $this->_getReader();
     $factory = $this->_getFactory($reader);
     $seq = $this->_mockery()->sequence('read-chars');
     $this->_checking(Expectations::create()->ignoring($reader)->getInitialByteSize()->returns(2)->one($reader)->validateByteSequence(array(0xd1, 0x8d), 2)->inSequence($seq)->one($reader)->validateByteSequence(array(0xd0, 0xbb), 2)->inSequence($seq)->one($reader)->validateByteSequence(array(0xd0, 0xb0), 2)->inSequence($seq));
     $stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
     $stream->importString(pack('C*', 0xd1, 0x8d, 0xd0, 0xbb, 0xd0, 0xb0));
     $this->assertIdenticalBinary(pack('C*', 0xd1, 0x8d), $stream->read(1));
     $this->assertIdenticalBinary(pack('C*', 0xd0, 0xbb), $stream->read(1));
     $this->assertIdenticalBinary(pack('C*', 0xd0, 0xb0), $stream->read(1));
     $this->assertIdentical(false, $stream->read(1));
 }
All Usage Examples Of Swift_CharacterStream_ArrayCharacterStream::read