Пример #1
0
 private function create_named_host_from_string(h\string $literal)
 {
     $end = $literal->search(':');
     if (-1 === $end) {
         $end = $literal->search('/');
     }
     if (-1 === $end) {
         $end = $literal->length();
     }
     $hostname = $literal->behead($end);
     $impl = new h\inet\host();
     $impl->segments = $hostname->explode('.');
     return $impl;
 }
Пример #2
0
 public function do_feed(h\string $meat)
 {
     if ($meat->length() < 1) {
         return null;
     }
     if (h\string(':')->is_equal($meat[0])) {
         $meat->behead(1);
     } else {
         return null;
     }
     for ($end_port = 0; \is_numeric((string) $meat[$end_port]); ++$end_port) {
         /* */
     }
     $port = $meat->behead($end_port);
     $port = $port->as_integer();
     if (1 > $port || $port > 65535) {
         throw $this->_exception_format('Specified port \'%d\' is incorrect', $port);
     }
     return $port;
 }
Пример #3
0
 public function do_parse(h\string $template)
 {
     $begin = 0;
     $end = 0;
     $opening_delimiter = self::OPENING_DELIMITER;
     $closing_delimiter = self::CLOSING_DELIMITER;
     $parser_stack = h\collection();
     $parser_stack[] = new tag\begin();
     do {
         // Open tag ////////////////////////////////////////////////////////////////////
         $end = $template->search($opening_delimiter, $begin);
         if (-1 === $end) {
             $end = $template->length();
         }
         $element = new tag\raw();
         $element->content = $template->slice($begin, $end);
         $parser_stack[] = $element;
         $begin = $end;
         if ($template->length() === $begin) {
             break;
         }
         // Close tag ///////////////////////////////////////////////////////////////////
         $begin += strlen($opening_delimiter);
         $end = $template->search($closing_delimiter, $begin);
         $first = $template[$begin];
         ++$begin;
         if ($first->is_equal(h\string('#'))) {
             $element = new tag\section();
             $element->name = $template->slice($begin, $end);
             $parser_stack[] = $element;
         } elseif ($first->is_equal(h\string('^'))) {
             $element = new tag\inverted();
             $element->name = $template->slice($begin, $end);
             $parser_stack[] = $element;
         } elseif ($first->is_equal(h\string('/'))) {
             $element = new tag\close();
             $element->name = $template->slice($begin, $end);
             $parser_stack[] = $element;
         } elseif ($first->is_equal(h\string('!'))) {
             $element = new tag\comment();
             $element->content = $template->slice($begin, $end);
             $parser_stack[] = $element;
         } elseif ($first->is_equal(h\string('{'))) {
             if ('}' !== $template[++$end]) {
                 throw 'Ill-formed';
             }
             $element = new tag\unescaped();
             $element->name = $template->slice($begin, $end - 1)->trimmed();
             $parser_stack[] = $element;
         } elseif ($first->is_equal(h\string('&'))) {
             $element = new tag\unescaped();
             $element->name = $template->slice($begin, $end - 1)->trimmed();
             $parser_stack[] = $element;
         } elseif ($first->is_equal(h\string('>'))) {
             throw 'TODO';
         } elseif ($first->is_equal(h\string('='))) {
             throw 'TODO';
         } else {
             $element = new tag\variable();
             $element->name = $template->slice($begin - 1, $end)->trimmed();
             $parser_stack[] = $element;
         }
         $begin = $end = $end + strlen($closing_delimiter);
     } while (true);
     $parser_stack[] = new tag\end();
     return $parser_stack;
 }