From 36956298ee60ea9b21ab8ce6fd237ab7fbf87141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Fri, 6 Aug 2010 00:25:44 +0200 Subject: [PATCH] Solution for the Allman/BSD style switch indentation, now check in allman style if the control sequence is Switch, and then add one additional indentation --- Beautifier.php | 11 +++++++++++ Beautifier/Filter/IndentStyles.filter.php | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/Beautifier.php b/Beautifier.php index afdd1bb..9148237 100755 --- a/Beautifier.php +++ b/Beautifier.php @@ -1819,5 +1819,16 @@ public function openBraceDontProcess() or ($this->isPreviousTokenConstant(T_STRING) and $this->getPreviousTokenConstant(2) == T_OBJECT_OPERATOR) or $this->getMode('double_quote'); } + + /** + * getLastSeq: Return the last sequence block opened and not closed + * + * @access public + * @return int + */ + public function getLastSeq() + { + return $this->aControlSeq[count($this->aControlSeq)-1]; + } } ?> diff --git a/Beautifier/Filter/IndentStyles.filter.php b/Beautifier/Filter/IndentStyles.filter.php index fa98c45..b11b32c 100755 --- a/Beautifier/Filter/IndentStyles.filter.php +++ b/Beautifier/Filter/IndentStyles.filter.php @@ -155,6 +155,9 @@ function t_open_brace_bsd($sTag) { $this->oBeaut->addNewLineIndent(); $this->oBeaut->add($sTag); + if ($this->oBeaut->getLastSeq() == T_SWITCH) { + $this->oBeaut->incIndent(); + } $this->oBeaut->incIndent(); $this->oBeaut->addNewLineIndent(); } @@ -173,6 +176,9 @@ function t_close_brace_bsd($sTag) } else { $this->oBeaut->removeWhitespace(); $this->oBeaut->decIndent(); + if ($this->oBeaut->getLastSeq() == T_SWITCH) { + $this->oBeaut->decIndent(); + } $this->oBeaut->addNewLineIndent(); $this->oBeaut->add($sTag); $this->oBeaut->addNewLineIndent();