From d0cfe031944db0a944f2d504b75cae3116b4e603 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Sun, 26 May 2002 23:38:22 +0000 Subject: [PATCH] * un-indent description too --- pear/PEAR/Common.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php index 80f16b3c2b..d03b643d59 100644 --- a/pear/PEAR/Common.php +++ b/pear/PEAR/Common.php @@ -254,6 +254,26 @@ class PEAR_Common extends PEAR // }}} + // {{{ _unIndent() + + function _unIndent($str) + { + // remove leading newlines + $str = preg_replace('/^[\r\n]+/', '', $str); + // find whitespace at the beginning of the first line + $indent_len = strspn($str, " \t"); + $indent = substr($str, 0, $indent_len); + $data = ''; + // remove the same amount of whitespace from following lines + foreach (explode("\n", $str) as $line) { + if (substr($line, 0, $indent_len) == $indent) { + $data .= substr($line, $indent_len) . "\n"; + } + } + return $data; + } + + // }}} // {{{ _element_start() /** @@ -461,6 +481,7 @@ class PEAR_Common extends PEAR $this->pkginfo['summary'] = $data; break; case 'description': + $data = $this->_unIndent($this->cdata); $this->pkginfo['description'] = $data; break; case 'user': @@ -490,17 +511,7 @@ class PEAR_Common extends PEAR case 'notes': // try to "de-indent" release notes in case someone // has been over-indenting their xml ;-) - $data = preg_replace('/^[\r\n]+/', '', $this->cdata); - $indent_len = strspn($data, " \t"); - $indent = substr($data, 0, $indent_len); - $newdata = ''; - foreach (explode("\n", $data) as $line) { - print "indent_len=$indent_len\n"; - if (substr($line, 0, $indent_len) == $indent) { - $newdata .= substr($line, $indent_len) . "\n"; - } - } - $data = $newdata; + $data = $this->_unIndent($this->cdata); if ($this->in_changelog) { $this->current_release['release_notes'] = $data; } else { -- 2.40.0