Permalink
Browse files

Fixed Bug #13861: Now comments are correctly indented.

  • Loading branch information...
1 parent a597976 commit 0c87889369b0e4f78c0d949b090b749c84a2b2c4 @jespino jespino committed May 29, 2010
Showing with 50 additions and 1 deletion.
  1. +4 −0 Beautifier.php
  2. +21 −1 Beautifier/Filter/Default.filter.php
  3. +11 −0 Rakefile
  4. +14 −0 tests/Beautifier.phpt
View
@@ -563,6 +563,10 @@ public function getIndentNumber()
{
return $this->iIndentNumber;
}
+ public function getIndent()
+ {
+ return $this->iIndent;
+ }
public function getNewLine()
{
return $this->sNewLine;
@@ -233,8 +233,28 @@ function comment_large($sTag)
$this->oBeaut->addNewLineIndent();
} else {
$aLines = explode("\n", $sTag);
+
+ $allWithAsterisk=true;
+ for($x=1;$x<(count($aLines)-1);$x++) {
+ if (substr(trim($aLines[$x]),0,1)!="*") {
+ $allWithAsterisk=false;
+ }
+ }
+
foreach($aLines as $sLinea) {
- $this->oBeaut->add(trim($sLinea));
+ if (substr(trim($sLinea),0,2)=="/*") {
+ $this->oBeaut->add(trim($sLinea));
+ } elseif (substr(trim($sLinea),0,2)=="*/") {
+ $this->oBeaut->add(trim($sLinea));
+ } elseif ($allWithAsterisk) {
+ $this->oBeaut->add(" ".trim($sLinea));
+ } else {
+ if (trim(substr($sLinea,0,$this->oBeaut->getIndent()))=="") {
+ $this->oBeaut->add(substr($sLinea,$this->oBeaut->getIndent()));
+ } else {
+ $this->oBeaut->add(trim($sLinea));
+ }
+ }
$this->oBeaut->addNewLineIndent();
}
}
View
@@ -12,3 +12,14 @@ task :test do
}
puts "Passed:#{passed}, Failed:#{failed}"
end
+
+task :install do
+ system "pear install package2.xml"
+end
+
+task :uninstall do
+ system "pear uninstall PHP_Beautifier"
+end
+
+task :reinstall => [:uninstall, :install] do
+end
View
@@ -176,6 +176,13 @@
/*
Long comment 3
*/
+/*
+Indented
+ Comment
+ With some levels
+ Now
+ Works
+*/
?>
SCRIPT;
$sTextExpected = <<<SCRIPT
@@ -187,6 +194,13 @@ SCRIPT;
/*
Long comment 3
*/
+/*
+Indented
+ Comment
+ With some levels
+ Now
+ Works
+*/
?>
SCRIPT;
$sTextExpected = str_replace("\r\n", "\n", $sTextExpected);

0 comments on commit 0c87889

Please sign in to comment.