}
/**
+ * Returns a string with the first letter of each word capitalized if it is
+ * alphabetic.
+ *
+ * Sentences are splitted into words at whitestrings.
+ *
+ * @param string $string The string to be capitalized.
+ * @param boolean $locale If true the string will be converted based on a
+ * given charset, locale independent else.
+ * @param string $charset The charset to use, defaults to current charset.
+ *
+ * @return string The capitalized string.
+ */
+ static public function ucwords($string, $locale = false, $charset = null)
+ {
+ $words = preg_split('/(\s+)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
+ for ($i = 0, $c = count($words); $i < $c; $i += 2) {
+ $words[$i] = Horde_String::ucfirst($words[$i], $locale, $charset);
+ }
+ return implode('', $words);
+ }
+
+ /**
* Returns part of a string.
*
* @param string $string The string to be converted.
);
}
+ public function testUcwords()
+ {
+ $this->assertEquals(
+ 'Integer Inside',
+ Horde_String::ucwords('integer inside', true, 'us-ascii')
+ );
+ $this->assertEquals(
+ 'Integer Inside',
+ Horde_String::ucwords('integer inside', true, 'Big5')
+ );
+ $this->assertEquals(
+ 'İnteger İnside',
+ Horde_String::convertCharset(
+ Horde_String::ucwords('integer inside', true, 'iso-8859-9'),
+ 'iso-8859-9', 'utf-8')
+ );
+ }
+
public function testUcfirstTurkish()
{
if (!setlocale(LC_ALL, 'tr_TR')) {