}
/**
+ * Returns the common leading part of two strings.
+ *
+ * @param string $str1 A string.
+ * @param string $str2 Another string.
+ *
+ * @return string The start of $str1 and $str2 that is identical in both.
+ */
+ static public function common($str1, $str2)
+ {
+ for ($result = '', $i = 0;
+ isset($str1[$i]) && isset($str2[$i]) && $str1[$i] == $str2[$i];
+ $i++) {
+ $result .= $str1[$i];
+ }
+ return $result;
+ }
+
+ /**
* Returns true if the every character in the parameter is an alphabetic
* character.
*
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Util
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ */
+
+require_once 'Horde/Test/Autoload.php';
+
+/* Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
<?php
/**
+ * Require our basic test case definition
+ */
+require_once dirname(__FILE__) . '/Autoload.php';
+
+/**
* @author Jan Schneider <jan@horde.org>
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @category Horde
* @package Util
* @subpackage UnitTests
*/
-
class Horde_Util_StringTest extends PHPUnit_Framework_TestCase
{
public function testUpper()
,
Horde_String::wordwrap($string, 31, "\n", false, 'utf-8', true));
}
+
+ public function testCommon()
+ {
+ $this->assertEquals('', Horde_String::common('foo', 'bar'));
+ $this->assertEquals('foo', Horde_String::common('foobar', 'fooxyx'));
+ $this->assertEquals('foo', Horde_String::common('foo', 'foobar'));
+ }
}