Exemplo n.º 1
0
 /**
  * Constructs the class with given parameters.
  *
  * @param Zend_Io_Reader $reader The reader object.
  * @param Array          $options The options array.
  */
 public function __construct($reader)
 {
     $this->_reader = $reader;
     if (!in_array($this->_packetType = $this->_reader->readUInt8(), array(1, 3, 5))) {
         require_once 'Zend/Media/Vorbis/Exception.php';
         throw new Zend_Media_Vorbis_Exception('Unknown header packet type: ' . $this->_packetType);
     }
     if (($vorbis = $this->_reader->read(6)) != 'vorbis') {
         require_once 'Zend/Media/Vorbis/Exception.php';
         throw new Zend_Media_Vorbis_Exception('Unknown header packet: ' . $vorbis);
     }
     $skipBytes = $this->_reader->getCurrentPagePosition();
     for ($page = $this->_reader->getCurrentPageNumber();; $page++) {
         $segments = $this->_reader->getPage($page)->getSegmentTable();
         for ($i = 0, $skippedSegments = 0; $i < count($segments); $i++) {
             // Skip page segments that are already read in
             if ($skipBytes > $segments[$i]) {
                 $skipBytes -= $segments[$i];
                 continue;
             }
             // Skip segments that are full
             if ($segments[$i] == 255 && ++$skippedSegments) {
                 continue;
             }
             // Record packet size from the first non-255 segment
             $this->_packetSize += $i * 255 + $segments[$i];
             break 2;
         }
         $this->_packetSize += $skippedSegments * 255;
     }
 }
    function testWorkaround()
    {
        // See https://github.com/fruux/sabre-vobject/issues/36
        $event = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:Titel
SEQUENCE:1
TRANSP:TRANSPARENT
RRULE:FREQ=YEARLY
LAST-MODIFIED:20130323T225737Z
DTSTAMP:20130323T225737Z
UID:1833bd44-188b-405c-9f85-1a12105318aa
CATEGORIES:Jubiläum
X-MOZ-GENERATION:3
RECURRENCE-ID;RANGE=THISANDFUTURE;VALUE=DATE:20131013
DTSTART;VALUE=DATE:20131013
CREATED:20100721T121914Z
DURATION:P1D
END:VEVENT
END:VCALENDAR
ICS;
        $obj = Reader::read($event);
        // If this does not throw an exception, it's all good.
        $it = new Recur\EventIterator($obj, '1833bd44-188b-405c-9f85-1a12105318aa');
        $this->assertInstanceOf('Sabre\\VObject\\Recur\\EventIterator', $it);
    }
    function testGetDTEnd()
    {
        $ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.4//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND;TZID=America/New_York:20070925T170000
UID:uuid
DTSTAMP:19700101T000000Z
LOCATION:
DESCRIPTION:
STATUS:CONFIRMED
SEQUENCE:18
SUMMARY:Stuff
DTSTART;TZID=America/New_York:20070925T160000
CREATED:20071004T144642Z
RRULE:FREQ=MONTHLY;INTERVAL=1;UNTIL=20071030T035959Z;BYDAY=5TU
END:VEVENT
END:VCALENDAR
ICS;
        $vObject = Reader::read($ics);
        $it = new RecurrenceIterator($vObject, (string) $vObject->VEVENT->UID);
        while ($it->valid()) {
            $it->next();
        }
        // If we got here, it means we were successful. The bug that was in teh
        // system before would fail on the 5th tuesday of the month, if the 5th
        // tuesday did not exist.
    }
Exemplo n.º 4
0
 /**
  * Finds and returns the previous start code. Start codes are reserved bit
  * patterns in the video file that do not otherwise occur in the video
  * stream.
  *
  * All start codes are byte aligned and start with the following byte
  * sequence: 0x00 0x00 0x01.
  *
  * @return integer
  */
 protected final function prevStartCode()
 {
     $buffer = '    ';
     $start;
     $position = $this->_reader->getOffset();
     while ($position > 0) {
         $start = 0;
         $position = $position - 512;
         if ($position < 0) {
             require_once 'Zend/Media/Mpeg/Exception.php';
             throw new Zend_Media_Mpeg_Exception('Invalid data');
         }
         $this->_reader->setOffset($position);
         $buffer = $this->_reader->read(512) . substr($buffer, 0, 4);
         $pos = 512 - 8;
         while ($pos > 3) {
             list(, $int) = unpack('n*', substr($buffer, $pos + 1, 2));
             if (ord($buffer[$pos]) == 0 && $int == 1) {
                 list(, $int) = unpack('n*', substr($buffer, $pos + 3, 2));
                 if ($pos + 2 < 512 && $int == 0 && ord($buffer[$pos + 5]) == 1) {
                     $pos--;
                     continue;
                 }
                 $this->_reader->setOffset($position + $pos);
                 return ord($buffer[$pos + 3]) & 0xff | 0x100;
             }
             $pos--;
         }
         $this->_reader->setOffset($position = $position + 3);
     }
     return 0;
 }
Exemplo n.º 5
0
 /**
  * This method tests wether two vcards or icalendar objects are
  * semantically identical.
  *
  * It supports objects being supplied as strings, streams or
  * Sabre\VObject\Component instances.
  *
  * PRODID is removed from both objects as this is often changes and would
  * just get in the way.
  *
  * CALSCALE will automatically get removed if it's set to GREGORIAN.
  *
  * Any property that has the value **ANY** will be treated as a wildcard.
  *
  * @param resource|string|Component $expected
  * @param resource|string|Component $actual
  * @param string $message
  */
 function assertVObjEquals($expected, $actual, $message = '')
 {
     $self = $this;
     $getObj = function ($input) use($self) {
         if (is_resource($input)) {
             $input = stream_get_contents($input);
         }
         if (is_string($input)) {
             $input = Reader::read($input);
         }
         if (!$input instanceof Component) {
             $this->fail('Input must be a string, stream or VObject component');
         }
         unset($input->PRODID);
         if ($input instanceof Component\VCalendar && (string) $input->CALSCALE === 'GREGORIAN') {
             unset($input->CALSCALE);
         }
         return $input;
     };
     $expected = $getObj($expected)->serialize();
     $actual = $getObj($actual)->serialize();
     // Finding wildcards in expected.
     preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\\r$|m', $expected, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $actual = preg_replace('|^' . preg_quote($match[1], '|') . ':(.*)\\r$|m', $match[1] . ':**ANY**' . "\r", $actual);
     }
     $this->assertEquals($expected, $actual, $message);
 }
Exemplo n.º 6
0
    function testRead()
    {
        $input = <<<VCF
BEGIN:VCARD
VERSION:2.1
N:Doe;Jon;;;
FN:Jon Doe
EMAIL;X-INTERN:foo@example.org
UID:foo
END:VCARD
VCF;
        $vcard = Reader::read($input);
        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $vcard);
        $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30);
        $vcard = $vcard->serialize();
        $converted = Reader::read($vcard);
        $converted->validate();
        $this->assertTrue(isset($converted->EMAIL['X-INTERN']));
        $version = Version::VERSION;
        $expected = <<<VCF
BEGIN:VCARD
VERSION:3.0
PRODID:-//Sabre//Sabre VObject {$version}//EN
N:Doe;Jon;;;
FN:Jon Doe
EMAIL;X-INTERN=:foo@example.org
UID:foo
END:VCARD

VCF;
        $this->assertEquals($expected, str_replace("\r", "", $vcard));
    }
 /**
  * fgetcsvの代替メソッド
  * @param string $d = ',' CSV区切り文字
  * @param string $e = '"' CSV文字列囲み文字
  * @return array 読み出したCSV配列
  * @access private
  */
 private function fgetcsv_reg($d = ',', $e = '"')
 {
     $d = preg_quote($d);
     $e = preg_quote($e);
     $_line = "";
     while ($eof != true) {
         $__line = parent::read();
         if ($__line === false) {
             break;
         } else {
             $_line .= $__line;
         }
         $itemcnt = preg_match_all('/' . $e . '/', $_line, $dummy);
         if ($itemcnt % 2 == 0) {
             $eof = true;
         }
     }
     $_csv_line = preg_replace('/(?:\\r\\n|[\\r\\n])?$/', $d, trim($_line));
     $_csv_pattern = '/(' . $e . '[^' . $e . ']*(?:' . $e . $e . '[^' . $e . ']*)*' . $e . '|[^' . $d . ']*)' . $d . '/';
     preg_match_all($_csv_pattern, $_csv_line, $_csv_matches);
     $_csv_data = $_csv_matches[1];
     for ($_csv_i = 0; $_csv_i < count($_csv_data); $_csv_i++) {
         $_csv_data[$_csv_i] = preg_replace('/^' . $e . '(.*)' . $e . '$/s', '$1', $_csv_data[$_csv_i]);
         $_csv_data[$_csv_i] = str_replace($e . $e, $e, $_csv_data[$_csv_i]);
     }
     return preg_replace('/(?:\\r\\n|[\\r\\n])?$/', '', trim($_line)) === '' ? false : $_csv_data;
 }
Exemplo n.º 8
0
 /**
  * Constructs the ID3v1 class with given file. The file is not mandatory
  * argument and may be omitted. A new tag can be written to a file also by
  * giving the filename to the {@link #write} method of this class.
  *
  * @param string $filename The path to the file.
  */
 public function __construct($filename = false)
 {
     if (($this->_filename = $filename) === false || file_exists($filename) === false) {
         return;
     }
     $this->_reader = new Reader($filename);
     if ($this->_reader->getSize() < 128) {
         return;
     }
     $this->_reader->setOffset(-128);
     if ($this->_reader->read(3) != "TAG") {
         $this->_reader = false;
         // reset reader, see write
         return;
     }
     $this->_title = rtrim($this->_reader->readString8(30), " ");
     $this->_artist = rtrim($this->_reader->readString8(30), " ");
     $this->_album = rtrim($this->_reader->readString8(30), " ");
     $this->_year = $this->_reader->readString8(4);
     $this->_comment = rtrim($this->_reader->readString8(28), " ");
     /* ID3v1.1 support for tracks */
     $v11_null = $this->_reader->read(1);
     $v11_track = $this->_reader->read(1);
     if (ord($v11_null) == 0 && ord($v11_track) != 0) {
         $this->_track = ord($v11_track);
     } else {
         $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " ");
     }
     $this->_genre = $this->_reader->readInt8();
 }
Exemplo n.º 9
0
 /**
  * Wrap code in namespace
  *
  * @expectOutputRegex #namespace Foo#
  */
 public function exampleWrapInNamespace()
 {
     $reader = new Reader("<?php class Bar {}");
     $writer = new Writer();
     $writer->apply(new Action\NamespaceWrapper('Foo'));
     // Outputs class Bar wrapped in namespace Foo
     echo $writer->write($reader->read('Bar'));
 }
Exemplo n.º 10
0
 function testRead()
 {
     $vcard = Reader::read(file_get_contents(dirname(__FILE__) . '/issue64.vcf'));
     $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30);
     $vcard = $vcard->serialize();
     $converted = Reader::read($vcard);
     $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $converted);
 }
Exemplo n.º 11
0
 /**
  * Starts the parsing process.
  *
  * @param  string  the option to set
  * @return int     1 if the parsing succeeded
  * @throws ExpatParseException if something gone wrong during parsing
  * @throws IOException if XML file can not be accessed
  * @access public
  */
 function parse()
 {
     while (($data = $this->reader->read()) !== -1) {
         if (!xml_parse($this->parser, $data, $this->reader->eof())) {
             $error = xml_error_string(xml_get_error_code($this->parser));
             $e = new ExpatParseException($error, $this->getLocation());
             xml_parser_free($this->parser);
             throw $e;
         }
     }
     xml_parser_free($this->parser);
     return 1;
 }
Exemplo n.º 12
0
    function testRead()
    {
        $event = <<<ICS
BEGIN:VCALENDAR
BEGIN:VEVENT
ATTACH;FMTTYPE=;ENCODING=:Zm9v
END:VEVENT
END:VCALENDAR

ICS;
        $obj = Reader::read($event);
        $this->assertEquals($event, $obj->serialize());
    }
Exemplo n.º 13
0
    function testRead()
    {
        $event = <<<ICS
BEGIN:VCALENDAR
BEGIN:VEVENT
DESCRIPTION:TEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\nTEST\\nTEST, TEST
END:VEVENT
END:VCALENDAR

ICS;
        $obj = Reader::read($event);
        $this->assertEquals($event, $obj->serialize());
    }
Exemplo n.º 14
0
    function testRead()
    {
        $input = <<<VCF
BEGIN:VCARD
VERSION:2.1
SOURCE:Yahoo Contacts (http://contacts.yahoo.com)
URL;CHARSET=utf-8;ENCODING=QUOTED-PRINTABLE:=
http://www.example.org
END:VCARD
VCF;
        $vcard = Reader::read($input, Reader::OPTION_FORGIVING);
        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $vcard);
        $this->assertEquals("http://www.example.org", $vcard->URL->getValue());
    }
Exemplo n.º 15
0
    function testDecodeValue()
    {
        $input = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DESCRIPTION:This is a descpription\\nwith a linebreak and a \\; \\, and :
END:VEVENT
END:VCALENDAR
ICS;
        $vobj = Reader::read($input);
        // Before this bug was fixed, getValue() would return nothing.
        $this->assertEquals("This is a descpription\nwith a linebreak and a ; , and :", $vobj->VEVENT->DESCRIPTION->getValue());
    }
    function testDecode()
    {
        $vcard = <<<VCF
BEGIN:VCARD
VERSION:3.0
FN:Evert Pot
N:Pot;Evert;;;
EMAIL;TYPE=INTERNET;TYPE=WORK:evert@fruux.com
BDAY:1985-04-07
item7.URL:http\\://www.rooftopsolutions.nl/
END:VCARD
VCF;
        $vobj = Reader::read($vcard);
        $this->assertEquals('http://www.rooftopsolutions.nl/', $vobj->URL->getValue());
    }
    /**
     * @expectedException \Sabre\VObject\ParseException
     */
    function testRead()
    {
        $input = <<<VCF
BEGIN:VCARD
VERSION:3.0
PRODID:foo
N:Holmes;Sherlock;;;
FN:Sherlock Holmes
ORG:Acme Inc;
ADR;type=WORK;type=pref:;;,
\\n221B,Baker Street;London;;12345;United Kingdom
UID:foo
END:VCARD
VCF;
        $vcard = Reader::read($input, Reader::OPTION_FORGIVING);
    }
    /**
     * @expectedException \Sabre\VObject\ParseException
     */
    function testRead()
    {
        $input = <<<VCF
BEGIN:VCARD
VERSION:3.0
PRODID:foo
N:Holmes;Sherlock;;;
FN:Sherlock Holmes
ORG:Acme Inc;
ADR;type=WORK;type=pref:;;,
\\n221B,Baker Street;London;;12345;United Kingdom
UID:foo
END:VCARD
VCF;
        $vcard = Reader::read($input, Reader::OPTION_FORGIVING);
        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $vcard);
    }
Exemplo n.º 19
0
    /**
     * @expectedException \InvalidArgumentException
     */
    function testExpand()
    {
        $input = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:bae5d57a98
RRULE:FREQ=MONTHLY;BYDAY=0MO,0TU,0WE,0TH,0FR;INTERVAL=1
DTSTART;VALUE=DATE:20130401
DTEND;VALUE=DATE:20130402
END:VEVENT
END:VCALENDAR
ICS;
        $vcal = Reader::read($input);
        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
        $it = new Recur\EventIterator($vcal, 'bae5d57a98');
        iterator_to_array($it);
    }
Exemplo n.º 20
0
    function testParseTz()
    {
        $str = 'BEGIN:VCALENDAR
X-WR-CALNAME:Blackhawks Schedule 2011-12
X-APPLE-CALENDAR-COLOR:#E51717
X-WR-TIMEZONE:America/Chicago
CALSCALE:GREGORIAN
PRODID:-//eM Client/4.0.13961.0
VERSION:2.0
BEGIN:VTIMEZONE
TZID:America/Chicago
BEGIN:DAYLIGHT
TZOFFSETFROM:-0600
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
DTSTART:20070311T020000
TZNAME:CDT
TZOFFSETTO:-0500
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0500
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
DTSTART:20071104T020000
TZNAME:CST
TZOFFSETTO:-0600
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20110624T181236Z
UID:be3bbfff-96e8-4c66-9908-ab791a62231d
DTEND;TZID="America/Chicago":20111008T223000
TRANSP:OPAQUE
SUMMARY:Stars @ Blackhawks (Home Opener)
DTSTART;TZID="America/Chicago":20111008T193000
DTSTAMP:20120330T013232Z
SEQUENCE:2
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
LAST-MODIFIED:20120330T013237Z
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR';
        $vObject = Reader::read($str);
        $dt = $vObject->VEVENT->DTSTART->getDateTime();
        $this->assertEquals(new \DateTime('2011-10-08 19:30:00', new \DateTimeZone('America/Chicago')), $dt);
    }
    function testMinusOne()
    {
        $ics = <<<ICS
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTAMP:20120314T203127Z
UID:foo
SUMMARY:foo
RRULE:FREQ=YEARLY;UNTIL=20120314
DTSTART;VALUE=DATE:20120315
DTEND;VALUE=DATE:20120316
SEQUENCE:1
END:VEVENT
END:VCALENDAR
ICS;
        $vObject = Reader::read($ics);
        $it = new RecurrenceIterator($vObject, (string) $vObject->VEVENT->UID);
        $this->assertTrue($it->valid());
    }
Exemplo n.º 22
0
 /**
  * This method tests wether two vcards or icalendar objects are
  * semantically identical.
  *
  * It supports objects being supplied as strings, streams or
  * Sabre\VObject\Component instances.
  *
  * PRODID is removed from both objects as this is often variable.
  *
  * @param resource|string|Component $expected
  * @param resource|string|Component $actual
  * @param string $message
  */
 function assertVObjEquals($expected, $actual, $message = '')
 {
     $self = $this;
     $getObj = function ($input) use($self) {
         if (is_resource($input)) {
             $input = stream_get_contents($input);
         }
         if (is_string($input)) {
             $input = Reader::read($input);
         }
         if (!$input instanceof Component) {
             $this->fail('Input must be a string, stream or VObject component');
         }
         unset($input->PRODID);
         return $input;
     };
     $expected = $getObj($expected);
     $actual = $getObj($actual);
     $this->assertEquals($expected->serialize(), $actual->serialize(), $message);
 }
Exemplo n.º 23
0
    function testPropertyPadValueCount()
    {
        $input = <<<VCF
BEGIN:VCARD
VERSION:2.1
N:Foo
END:VCARD

VCF;
        $vobj = Reader::read($input);
        $output = $vobj->serialize();
        $expected = <<<VCF
BEGIN:VCARD
VERSION:2.1
N:Foo;;;;
END:VCARD

VCF;
        $this->assertEquals($expected, $output);
    }
Exemplo n.º 24
0
 /**
  * Reads and constructs the boxes found within this box.
  *
  * @todo Does not parse iTunes internal ---- boxes.
  */
 protected function constructBoxes($defaultclassname = "ISO14496_Box")
 {
   $base = $this->getOption("base", "");
   if ($this->getType() != "file")
     self::$_path[] = $this->getType();
   $path = implode(self::$_path, ".");
   
   while (true) {
     $offset = $this->_reader->getOffset();
     if ($offset >= $this->_offset + $this->_size)
       break;
     $size = $this->_reader->readUInt32BE();
     $type = rtrim($this->_reader->read(4), " ");
     if ($size == 1)
       $size = $this->_reader->readInt64BE();
     if ($size == 0)
       $size = $this->_reader->getSize() - $offset;
     
     if (preg_match("/^\xa9?[a-z0-9]{3,4}$/i", $type) &&
         substr($base, 0, min(strlen($base), strlen
                              ($tmp = $path . ($path ? "." : "") . $type))) ==
         substr($tmp,  0, min(strlen($base), strlen($tmp))))
     {
       $this->_reader->setOffset($offset);
       if (@fopen($filename = "ISO14496/Box/" . strtoupper($type) . ".php",
                  "r", true) !== false)
         require_once($filename);
       if (class_exists($classname = "ISO14496_Box_" . strtoupper($type)))
         $box = new $classname($this->_reader, $this->_options);
       else
         $box = new $defaultclassname($this->_reader, $this->_options);
       $box->setParent($this);
       if (!isset($this->_boxes[$box->getType()]))
         $this->_boxes[$box->getType()] = array();
       $this->_boxes[$box->getType()][] = $box;
     }
     $this->_reader->setOffset($offset + $size);
   }
   
   array_pop(self::$_path);
 }
Exemplo n.º 25
0
    public function testSaveGlobalUseStatements()
    {
        $reader = new Reader(<<<EOF
<?php
use random\\Exception;
class ClassName
{
}
EOF
);
        $expected = <<<EOF
namespace  {
    use random\\Exception;
    class ClassName
    {
    }
}
EOF;
        $writer = new Writer();
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
Exemplo n.º 26
0
 /**
  * Reads and constructs the boxes found within this box.
  *
  * @todo Does not parse iTunes internal ---- boxes.
  */
 protected final function constructBoxes($defaultclassname = 'Zend_Media_Iso14496_Box')
 {
     $base = $this->getOption('base', '');
     if ($this->getType() != 'file') {
         self::$_path[] = $this->getType();
     }
     $path = implode(self::$_path, '.');
     while (true) {
         $offset = $this->_reader->getOffset();
         if ($offset >= $this->_offset + $this->_size) {
             break;
         }
         $size = $this->_reader->readUInt32BE();
         $type = rtrim($this->_reader->read(4), ' ');
         if ($size == 1) {
             $size = $this->_reader->readInt64BE();
         }
         if ($size == 0) {
             $size = $this->_reader->getSize() - $offset;
         }
         if (preg_match("/^©?[a-z0-9]{3,4}\$/i", $type) && substr($base, 0, min(strlen($base), strlen($tmp = $path . ($path ? '.' : '') . $type))) == substr($tmp, 0, min(strlen($base), strlen($tmp)))) {
             $this->_reader->setOffset($offset);
             if (@fopen($filename = 'Zend/Media/Iso14496/Box/' . ucfirst($type) . '.php', 'r', true) !== false) {
                 require_once $filename;
             }
             if (class_exists($classname = 'Zend_Media_Iso14496_Box_' . ucfirst($type))) {
                 $box = new $classname($this->_reader, $this->_options);
             } else {
                 $box = new $defaultclassname($this->_reader, $this->_options);
             }
             $box->setParent($this);
             if (!isset($this->_boxes[$box->getType()])) {
                 $this->_boxes[$box->getType()] = array();
             }
             $this->_boxes[$box->getType()][] = $box;
         }
         $this->_reader->setOffset($offset + $size);
     }
     array_pop(self::$_path);
 }
Exemplo n.º 27
0
    public function testReader()
    {
        $text = <<<HTML
HELLO WORLD
HTML;
        $reader = new Reader($text);
        $this->assertEquals(strlen($text), strlen(trim($text)));
        $this->assertEquals("HE", $reader->read(2));
        $this->assertEquals(strlen($text), $reader->length());
        $this->assertEquals(6, $reader->moveCursor(6)->getCursor());
        $this->assertEquals('WORLD', $reader->readToEnd());
        $this->assertEquals('HELLO WORLD', $reader->rewind()->readToEnd());
        $this->assertEquals('HELLO ', $reader->readAndGo(6));
        $this->assertEquals('WORLD', $reader->readToEnd());
        # Reset position
        $reader->rewind();
        $this->assertNotFalse($reader->match('/(?=[a-z])/iA'));
        $this->assertEquals('HELLO', $reader->match('/\\w+/A'));
        $this->assertEquals(0, $reader->getCursor());
        $this->assertFalse($reader->matchAndGo('/\\d+/A'));
        $this->assertEquals('HELLO', $reader->matchAndGo('/\\w+/A'));
        $this->assertEquals(' ', $reader->matchAndGo('/\\s+/A'));
        $this->assertEquals('WORLD', $reader->matchAndGo('/\\w+/A'));
        $this->assertTrue($reader->isEnd());
        $reader->rewind();
        $this->assertEquals('HELLO WORLD', $reader->readToEndAndGo());
        $this->assertEquals(11, $reader->length());
        $this->assertEquals(10, $reader->getCursor());
        $this->assertTrue($reader->isEnd());
        $reader = new Reader('
		Hello
		World
		');
        $reader->setCursor(strpos($reader->readAll(), 'World'));
        $this->assertEquals(3, $reader->getLine());
        $this->assertEquals(2, $reader->getColumn());
    }
Exemplo n.º 28
0
 function testReadPropertyParameterQuotedColon()
 {
     $data = "PROPNAME;PARAMNAME=\"param:value\":propValue";
     $result = Reader::read($data);
     $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
     $this->assertEquals('PROPNAME', $result->name);
     $this->assertEquals('propValue', $result->value);
     $this->assertEquals(1, count($result->parameters));
     $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
     $this->assertEquals('param:value', $result->parameters[0]->value);
 }
Exemplo n.º 29
0
<?php

require_once 'symbol.php';
require_once 'reader.php';
$buf = "";
while (!feof(STDIN)) {
    $buf .= fgets(STDIN);
}
$x = Reader::tok($buf);
$x = Reader::read($x);
function gensym()
{
    static $FUNCTIONAL_TABLE = array();
    $x = rand_str(5);
    for ($x = rand_str(5); in_array($x, $FUNCTIONAL_TABLE); $x = rand_str()) {
    }
    array_push($FUNCTIONAL_TABLE, $x);
    return $x;
}
function compile($expr, &$oob)
{
    global $ENVIRONMENT;
    if (is_array($expr)) {
        switch ($expr[0] . "") {
            case "def":
                return compile_def($expr, $oob);
            case "define":
                return compile_def($expr, $oob);
            case "fn":
                return compile_fn($expr, $oob);
            case "λ":
Exemplo n.º 30
0
 /**
  * Read data from source.
  * FIXME: Clean up this function signature, as it a) params aren't being used
  * and b) it doesn't make much sense.
  */
 public function read($len = null)
 {
     return $this->in->read($len);
 }