Ejemplo n.º 1
0
 /**
  * TODO performance
  *
  * @param string $text
  * @param ParsePosition $ppos
  * @param bool $isCaseSensitive
  * @return null|string
  */
 private function match($text, ParsePosition $ppos, $isCaseSensitive)
 {
     $ids = ZoneId::getAvailableZoneIds();
     if (!$isCaseSensitive) {
         $ids = \array_map('\\strtolower', $ids);
         $text = \strtolower($text);
     }
     $ids = \array_flip($ids);
     $pos = $ppos->getIndex();
     $max = \strlen($text) - 1;
     for ($i = $max; $i >= $pos; $i--) {
         $str = \substr($text, $pos, $i - $pos + 1);
         if (isset($ids[$str])) {
             $ppos->setIndex($i + 1);
             return ZoneId::getAvailableZoneIds()[$ids[$str]];
         }
     }
     return null;
 }
Ejemplo n.º 2
0
 private function parseUnresolved0($text, ParsePosition $position)
 {
     $context = new DateTimeParseContext($this);
     $pos = $position->getIndex();
     $pos = $this->printerParser->parse($context, $text, $pos);
     if ($pos < 0) {
         $position->setErrorIndex(~$pos);
         // index not updated from input
         return null;
     }
     $position->setIndex($pos);
     // errorIndex not updated from input
     return $context;
 }
 /**
  * @dataProvider data_parseSuccess
  */
 public function test_parseSuccess_prefix($text, $expectedIndex, $expectedErrorIndex, $expected)
 {
     $this->builder->appendZoneId();
     $this->pos->setIndex(3);
     $prefixText = "XXX" . $text;
     $parsed = $this->builder->toFormatter()->parseUnresolved($prefixText, $this->pos);
     $this->assertEquals($this->pos->getErrorIndex(), $expectedErrorIndex >= 0 ? $expectedErrorIndex + 3 : $expectedErrorIndex, "Incorrect error index parsing: " . $prefixText);
     $this->assertEquals($this->pos->getIndex(), $expectedIndex + 3, "Incorrect index parsing: " . $prefixText);
     if ($expected !== null) {
         $this->assertEquals($parsed->query(TemporalQueries::zoneId()), $expected, "Incorrect zoneId parsing: " . $prefixText);
         $this->assertEquals($parsed->query(TemporalQueries::offset()), null, "Incorrect offset parsing: " . $prefixText);
         $this->assertEquals($parsed->query(TemporalQueries::zone()), $expected, "Incorrect zone parsing: " . $prefixText);
     } else {
         $this->assertEquals($parsed, null);
     }
 }