/** * Split a corpus of text into lines. This function splits on "\n", "\r\n", or * a mixture of any of them. * * NOTE: This function does not treat "\r" on its own as a newline because none * of SVN, Git or Mercurial do on any OS. * * @param $corpus string Block of text to be split into lines. * @param $retainEndings bool If true, retain line endings in result strings. * * @return array List of lines. * @group util * * @deprecated */ function phutil_split_lines($corpus, $retainEndings = true) { return \Packaged\Helpers\Strings::splitLines($corpus, $retainEndings); }
public function testSplitLines() { $retain_cases = ["" => [""], "x" => ["x"], "x\n" => ["x\n"], "\n" => ["\n"], "\n\n\n" => ["\n", "\n", "\n"], "\r\n" => ["\r\n"], "x\r\ny\n" => ["x\r\n", "y\n"], "x\ry\nz\r\n" => ["x\ry\n", "z\r\n"], "x\ry\nz\r\n\n" => ["x\ry\n", "z\r\n", "\n"]]; foreach ($retain_cases as $input => $expect) { $this->assertEquals($expect, Strings::splitLines($input, $retainEndings = true), "(Retained) " . addcslashes($input, "\r\n\\")); } $discard_cases = ["" => [""], "x" => ["x"], "x\n" => ["x"], "\n" => [""], "\n\n\n" => ["", "", ""], "\r\n" => [""], "x\r\ny\n" => ["x", "y"], "x\ry\nz\r\n" => ["x\ry", "z"], "x\ry\nz\r\n\n" => ["x\ry", "z", ""]]; foreach ($discard_cases as $input => $expect) { $this->assertEquals($expect, Strings::splitLines($input, $retainEndings = false), "(Discarded) " . addcslashes($input, "\r\n\\")); } }