From aaf4950d4ffc6db1e9e8ce16f1a7559a94993b00 Mon Sep 17 00:00:00 2001 From: jfsimon Date: Tue, 10 Jul 2012 11:13:16 +0200 Subject: [PATCH] [Console] Implemented '<' escaping. --- .../Console/Formatter/OutputFormatter.php | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index 5cfadfc3514d..2f321ae5c3eb 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -23,12 +23,29 @@ class OutputFormatter implements OutputFormatterInterface /** * The pattern to phrase the format. */ - const FORMAT_PATTERN = '#<(/?)([a-z][a-z0-9_=;-]+)?>([^<]*)#is'; + const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>([^\\\\<]*)#is'; + + /** + * The escape sequence for LG char. + */ + const LG_CHAR_ESCAPING = '\\'; private $decorated; private $styles = array(); private $styleStack; + /** + * Escapes "<" special char in given text. + * + * @param string $text Text to escape + * + * @return string Escaped text + */ + public static function escape($text) + { + return preg_replace('/([^\\\\]?)" tag $this->styleStack->pop(); - return $this->applyStyle($this->styleStack->getCurrent(), $match[3]); + return $this->applyStyle($this->styleStack->getCurrent(), $match[4]); } // we got "<>" tag - return '<>'.$match[3]; + return '<>'.$match[4]; } - if (isset($this->styles[strtolower($match[2])])) { - $style = $this->styles[strtolower($match[2])]; + if (isset($this->styles[strtolower($match[3])])) { + $style = $this->styles[strtolower($match[3])]; } else { - $style = $this->createStyleFromString($match[2]); + $style = $this->createStyleFromString($match[3]); if (false === $style) { return $match[0]; } } - if ('/' === $match[1]) { + if ('/' === $match[2]) { $this->styleStack->pop($style); } else { $this->styleStack->push($style); } - return $this->applyStyle($this->styleStack->getCurrent(), $match[3]); + return $this->applyStyle($this->styleStack->getCurrent(), $match[4]); } /**