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