adding File::prepare() for fixing line endings

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5899 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-10-25 03:10:31 +00:00
parent f57fc45d6f
commit 3b60dd5d5f
2 changed files with 18 additions and 7 deletions

View file

@ -434,14 +434,9 @@ class Shell extends Object {
uses('file');
}
$lineBreak = "\n";
if (substr(PHP_OS,0,3) == "WIN") {
$lineBreak = "\r\n";
}
$data = strtr($contents, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
if ($File = new File($path, true)) {
$File->write($contents);
$data = $File->prepare($contents);
$File->write($data);
$this->out(__("Wrote", true) ." {$path}");
return true;
} else {

View file

@ -199,6 +199,22 @@ class File extends Object {
}
return false;
}
/**
* Prepares a ascii string for writing
* fixes line endings
*
* @param string $data Data to prepare for writing.
* @return string
* @access public
*/
function prepare($data) {
$lineBreak = "\n";
if (substr(PHP_OS,0,3) == "WIN") {
$lineBreak = "\r\n";
}
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
}
/**
* Write given data to this File.
*