From ed53c61d49f51ca4e77278e033d1eb69990c1fc7 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 28 Jan 2010 13:55:13 -0700 Subject: [PATCH] Add Horde_String::abbreviate(). --- framework/Util/lib/Horde/String.php | 16 ++++++++++++++++ framework/Util/package.xml | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/framework/Util/lib/Horde/String.php b/framework/Util/lib/Horde/String.php index 719efce1d..4e13ee2c9 100644 --- a/framework/Util/lib/Horde/String.php +++ b/framework/Util/lib/Horde/String.php @@ -606,6 +606,22 @@ class Horde_String } /** + * Return an abbreviated string, with characters in the middle of the + * excesively long string replaced by '...'. + * + * @param string $text The original string. + * @param integer $length The length at which to abbreviate. + * + * @return string The abbreviated string, if longer than $length. + */ + static public function abbreviate($text, $length = 20) + { + return (self::length($text) > $length) + ? self::substr($text, 0, round(($length - 3) / 2)) . '...' . self::substr($text, (($length - 3) / 2) * -1) + : $text; + } + + /** * Returns true if the every character in the parameter is an alphabetic * character. * diff --git a/framework/Util/package.xml b/framework/Util/package.xml index 595c00e86..8afed384d 100644 --- a/framework/Util/package.xml +++ b/framework/Util/package.xml @@ -29,7 +29,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - + * Added Horde_Util::abbreviate(). * Removed Horde_Array::combine() and Horde_Util::hmac(). * Initial Horde 4 package. -- 2.11.0