Chris@0: historyFile); Chris@0: if (!$history) { Chris@0: return array(); Chris@0: } Chris@0: Chris@0: // libedit doesn't seem to support non-unix line separators. Chris@0: $history = explode("\n", $history); Chris@0: Chris@0: // shift the history signature, ensure it's valid Chris@0: if (array_shift($history) !== '_HiStOrY_V2_') { Chris@0: return array(); Chris@0: } Chris@0: Chris@0: // decode the line Chris@0: $history = array_map(array($this, 'parseHistoryLine'), $history); Chris@0: // filter empty lines & comments Chris@0: return array_values(array_filter($history)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * From GNUReadline (readline/histfile.c & readline/histexpand.c): Chris@0: * lines starting with "\0" are comments or timestamps; Chris@0: * if "\0" is found in an entry, Chris@0: * everything from it until the next line is a comment. Chris@0: * Chris@0: * @param string $line The history line to parse Chris@0: * Chris@0: * @return string | null Chris@0: */ Chris@0: protected function parseHistoryLine($line) Chris@0: { Chris@0: // empty line, comment or timestamp Chris@0: if (!$line || $line[0] === "\0") { Chris@0: return; Chris@0: } Chris@0: // if "\0" is found in an entry, then Chris@0: // everything from it until the end of line is a comment. Chris@0: if (($pos = strpos($line, "\0")) !== false) { Chris@0: $line = substr($line, 0, $pos); Chris@0: } Chris@0: Chris@0: return ($line !== '') ? Str::unvis($line) : null; Chris@0: } Chris@0: }