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; }
public function do_feed(h\string $meat) { $path = new path(); if (0 === $meat->search(h\string('//'))) { $impl = $this->do_create_net_path($meat); } elseif (0 === $meat->search(h\string('/'))) { $impl = $this->do_create_absolute_path($meat); } elseif (0 === $meat->search(h\string('.'))) { $impl = $this->do_create_relative_path($meat); } else { throw $this->_exception('No path'); } $path->set_impl($impl); return $path; }
public function create_relative_part(h\string $literal, h\uri\absolute $base = null) { $scheme_sep_pos = $literal->search(':'); if (-1 === $scheme_sep_pos) { return $this->create_relative($literal, $base); } $scheme = $literal->head($scheme_sep_pos); $scheme_specific_part = $literal->tail($scheme_sep_pos + 1); if (h\regex_match(static::scheme, $scheme)) { return $this->create_absolute_path($literal); } if ($this->factories->has_key($scheme)) { return $this->factories[$scheme]->do_feed($scheme_specific_part); } throw $this->_exception_format('Scheme \'%s\' not supported', $scheme); }
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; }