/** * Description * * @param blaze\lang\String|string $url Description of the parameter $var * @return blaze\net\URL Description of what the method returns * @throws blaze\lang\Exception */ public static function parseURL(\blaze\lang\String $url) { $idx = $url->indexOf('://'); if ($idx == -1) { throw new \blaze\lang\Exception('Invalid URL'); } $parts = parse_url($url); if ($parts === false) { throw new \blaze\lang\Exception('Invalid URL'); } $scheme = isset($parts['scheme']) ? $parts['scheme'] : null; $host = isset($parts['host']) ? $parts['host'] : null; $port = isset($parts['port']) ? $parts['port'] : null; $user = isset($parts['user']) ? $parts['user'] : null; $password = isset($parts['pass']) ? $parts['pass'] : null; $path = isset($parts['path']) ? $parts['path'] : null; $query = isset($parts['query']) ? $parts['query'] : null; $fragment = isset($parts['fragment']) ? $parts['fragment'] : null; return new URL($scheme, $user, $password, $host, $port, $path, $query, $fragment); }
/** * check if the literal address string has %nn appended * returns -1 if not, or the numeric value otherwise. * * %nn may also be a string that represents the displayName of * a currently available NetworkInterface. * @return int */ private static function checkNumericZone(\blaze\lang\String $s) { $percent = $s->indexOf('%'); $slen = $s->length(); $digit = null; $zone = 0; if ($percent == -1) { return -1; } for ($i = $percent + 1; $i < $slen; $i++) { $c = $s->charAt($i); if ($c == ']') { if ($i == $percent + 1) { /* empty per-cent field */ return -1; } break; } if (($digit = \baze\lang\Character::digit($c, 10)) < 0) { return -1; } $zone = $zone * 10 + $digit; } return $zone; }