function remove_dot_segments($path) { $result_segments = array(); while ($path) { if (_startswith($path, '../')) { $path = substr($path, 3); } else { if (_startswith($path, './')) { $path = substr($path, 2); } else { if (_startswith($path, '/./')) { $path = substr($path, 2); } else { if ($path == '/.') { $path = '/'; } else { if (_startswith($path, '/../')) { $path = substr($path, 3); if ($result_segments) { array_pop($result_segments); } } else { if ($path == '/..') { $path = '/'; if ($result_segments) { array_pop($result_segments); } } else { if ($path == '..' || $path == '.') { $path = ''; } else { $i = 0; if ($path[0] == '/') { $i = 1; } $i = strpos($path, '/', $i); if ($i === false) { $i = strlen($path); } $result_segments[] = substr($path, 0, $i); $path = substr($path, $i); } } } } } } } } return implode('', $result_segments); }
function Services_Yadis_XRI($xri) { if (!_startswith($xri, 'xri://')) { $xri = 'xri://' . $xri; } return $xri; }
private function _gen_usage() { $out = array(); $lines = explode("\n", trim($this->optspec)); $lines = array_reverse($lines); $first_syn = True; while (count($lines)) { $l = array_pop($lines); if ($l == '--') { break; } array_push($out, sprintf("%s: %s\n", $first_syn ? 'usage' : ' or', $l)); $first_syn = False; } array_push($out, "\n"); $last_was_option = False; $tty_width = _tty_width(); while (count($lines)) { $l = array_pop($lines); if (_startswith($l, ' ')) { array_push($out, sprintf("%s%s\n", $last_was_option ? "\n" : '', ltrim($l))); $last_was_option = False; } elseif ($l) { list($flags, $extra) = explode(' ', $l . ' ', 2); $extra = trim($extra); if (_endswith($flags, '=')) { $flags = substr($flags, 0, -1); $has_parm = 1; } else { $has_parm = 0; } $g = array(); $gr = preg_match('/\\[([^\\]]*)\\]$/', $extra, $g); if ($gr) { $defval = _intify($g[1]); } else { $defval = Null; } $flagl = explode(',', $flags); $flagl_nice = array(); list($flag_main, $invert_main) = _remove_negative_kv($flagl[0], False); $this->_defaults[$flag_main] = _invert($defval, $invert_main); foreach ($flagl as $_f) { list($f, $invert) = _remove_negative_kv($_f, 0); $this->_aliases[$f] = array($flag_main, $invert_main xor $invert); $this->_hasparms[$f] = $has_parm; if ($f == '#') { $this->_shortopts .= '0123456789'; array_push($flagl_nice, '-#'); } elseif (strlen($f) == 1) { $this->_shortopts .= $f . ($has_parm ? ':' : ''); array_push($flagl_nice, '-' . $f); } else { $f_nice = preg_replace('/\\W/', '_', $f); $this->_aliases[$f_nice] = array($flag_main, $invert_main xor $invert); array_push($this->_longopts, $f . ($has_parm ? '=' : '')); array_push($this->_longopts, 'no-' . $f); array_push($flagl_nice, '--' . $_f); } } $flags_nice = implode(', ', $flagl_nice); if ($has_parm) { $flags_nice .= ' ...'; } $prefix = sprintf(' %-20s ', $flags_nice); // wordwrap doesn't offer a feature similar to "subsequent_indent", // so the text will wrap to the beginning of the line. We could // implement this to make the usage string look nicer, but it // would probably imply too much code for what it's worth. $argtext = wordwrap($prefix . $extra, $tty_width); array_push($out, $argtext . "\n"); $last_was_option = True; } else { array_push($out, "\n"); $last_was_option = False; } } return rtrim(implode('', $out)) . "\n"; }