Permalink
Browse files

Renaming ucfirstEach to ucfirst

  • Loading branch information...
1 parent bf84cca commit 431e71b3e97b3fc15721cae1ed4c71e8854a8060 @chdemko committed Nov 24, 2011
@@ -203,11 +203,11 @@ public function __construct($form = null)
$parts = JString::splitCamelCase(get_called_class());
if ($parts[0] == 'J')
{
- $this->type = JString::ucfirstEach($parts[count($parts) - 1], '_');
+ $this->type = JString::ucfirst($parts[count($parts) - 1], '_');
}
else
{
- $this->type = JString::ucfirstEach($parts[0], '_') . JString::ucfirstEach($parts[count($parts) - 1], '_');
+ $this->type = JString::ucfirst($parts[0], '_') . JString::ucfirst($parts[count($parts) - 1], '_');
}
}
}
@@ -178,7 +178,7 @@ protected static function loadClass($entity, $type)
$prefix = 'J';
}
- $class = JString::ucfirstEach($prefix, '_') . 'Form' . JString::ucfirstEach($entity, '_') . JString::ucfirstEach($type, '_');
+ $class = JString::ucfirst($prefix, '_') . 'Form' . JString::ucfirst($entity, '_') . JString::ucfirst($type, '_');
if (class_exists($class))
{
@@ -86,26 +86,6 @@ public static function splitCamelCase($string)
return preg_split('/(?<=[^A-Z_])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][^A-Z_])/x', $string);
}
- /**
- * ucfirst each words
- *
- * @param string $string The source string.
- * @param string $delimiter The words delimiter
- * @param string $new_delimiter The new words delimiter (null means equal to $delimiter)
- *
- * @return string The string with all words ucfirst.
- *
- * @since 11.3
- */
- public static function ucfirstEach($string, $delimiter = ' ', $new_delimiter = null)
- {
- if ($new_delimiter === null)
- {
- $new_delimiter = $delimiter;
- }
- return implode($new_delimiter, array_map('ucfirst', explode($delimiter, $string)));
- }
-
/**
* Increments a trailing number in a string.
*
@@ -680,19 +660,34 @@ public static function trim($str, $charlist = false)
/**
* UTF-8 aware alternative to ucfirst
- * Make a string's first character uppercase
+ * Make a string's first character uppercase or all words' first character uppercase
*
- * @param string $str String to be processed
+ * @param string $str String to be processed
+ * @param string $delimiter The words delimiter (null means do not split the string)
+ * @param string $newDelimiter The new words delimiter (null means equal to $delimiter)
*
- * @return string String with first character as upper case (if applicable)
+ * @return string If $delimiter is null, return the string with first character as upper case (if applicable)
+ * else consider the string of words separated by the delimiter, apply the ucfirst to each words
+ * and return the string with the new delimiter
*
* @see http://www.php.net/ucfirst
* @since 11.1
*/
- public static function ucfirst($str)
+ public static function ucfirst($str, $delimiter = null, $newDelimiter = null)
{
jimport('phputf8.ucfirst');
- return utf8_ucfirst($str);
+ if ($delimiter === null)
+ {
+ return utf8_ucfirst($str);
+ }
+ else
+ {
+ if ($newDelimiter === null)
+ {
+ $newDelimiter = $delimiter;
+ }
+ return implode($newDelimiter, array_map('utf8_ucfirst', explode($delimiter, $str)));
+ }
}
/**
@@ -32,16 +32,6 @@ public function getSplitCamelCaseData()
return JStringTest_DataSet::$splitCamelCase;
}
- /**
- * @return array
- *
- * @since 11.3
- */
- public function getUcfirstEachData()
- {
- return JStringTest_DataSet::$ucfirstEach;
- }
-
/**
* @return array
*
@@ -286,20 +276,6 @@ public function testSplitCamelCase($string, $expected)
);
}
- /**
- * @return void
- *
- * @dataProvider getUcfirstEachData
- * @since 11.3
- */
- public function testUcfirstEach($string, $delimiter, $new_delimiter, $expected)
- {
- $this->assertThat(
- JString::ucfirstEach($string, $delimiter, $new_delimiter),
- $this->equalTo($expected)
- );
- }
-
/**
* @return void
*
@@ -579,9 +555,9 @@ public function testTrim($string, $charlist, $expect)
* @dataProvider getUcfirstData
* @since 11.2
*/
- public function testUcfirst($string, $expect)
+ public function testUcfirst($string, $delimiter, $newDelimiter, $expect)
{
- $actual = JString::ucfirst($string);
+ $actual = JString::ucfirst($string, $delimiter, $newDelimiter);
$this->assertEquals($expect, $actual);
}
@@ -28,21 +28,6 @@ class JStringTest_DataSet
array('JohnFitzgerald_Kennedy', array('John', 'Fitzgerald_Kennedy')),
);
- /**
- * Tests for JString::ucfirstEach.
- *
- * Each element contains $string, $delimiter, $new_delimiter, $expect
- *
- * @var array
- * @since 11.3
- */
- static public $ucfirstEach = array(
- // string, expected
- array('dr jekill and mister hyde', ' ', null, 'Dr Jekill And Mister Hyde'),
- array('dr jekill and mister hyde', ' ', '_', 'Dr_Jekill_And_Mister_Hyde'),
- array('dr jekill and mister hyde', ' ', '', 'DrJekillAndMisterHyde'),
- );
-
/**
* Tests for JString::increment.
*
@@ -299,9 +284,12 @@ class JStringTest_DataSet
* @since 11.2
*/
static public $ucfirstTests = array (
- array('george', 'George'),
- array('мога', 'Мога'),
- array('ψυχοφθόρα', 'Ψυχοφθόρα')
+ array('george', null, null, 'George'),
+ array('мога', null, null, 'Мога'),
+ array('ψυχοφθόρα', null, null, 'Ψυχοφθόρα'),
+ array('dr jekill and mister hyde', ' ', null, 'Dr Jekill And Mister Hyde'),
+ array('dr jekill and mister hyde', ' ', '_', 'Dr_Jekill_And_Mister_Hyde'),
+ array('dr jekill and mister hyde', ' ', '', 'DrJekillAndMisterHyde'),
);
/**

0 comments on commit 431e71b

Please sign in to comment.