Skip to content
Permalink
Browse files

refs #6635 Inflector::underscore, humanize support multibyte string i…

…nputs
  • Loading branch information...
nojimage committed May 26, 2015
1 parent 8ebc9cd commit c6e4208bda27115d03148d4191c0d96baff8e61c
Showing with 12 additions and 2 deletions.
  1. +4 −0 lib/Cake/Test/Case/Utility/InflectorTest.php
  2. +8 −2 lib/Cake/Utility/Inflector.php
@@ -399,12 +399,14 @@ public function testInflectorUnderscore() {
$this->assertSame(Inflector::underscore('testThing'), 'test_thing');
$this->assertSame(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
$this->assertSame(Inflector::underscore('testThingExtra'), 'test_thing_extra');
$this->assertSame(Inflector::underscore('testThingExtrå'), 'test_thing_extrå');
// Identical checks test the cache code path.
$this->assertSame(Inflector::underscore('TestThing'), 'test_thing');
$this->assertSame(Inflector::underscore('testThing'), 'test_thing');
$this->assertSame(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
$this->assertSame(Inflector::underscore('testThingExtra'), 'test_thing_extra');
$this->assertSame(Inflector::underscore('testThingExtrå'), 'test_thing_extrå');
// Test stupid values
$this->assertSame(Inflector::underscore(''), '');
@@ -457,6 +459,8 @@ public function testHumanization() {
$this->assertEquals(Inflector::humanize('posts'), 'Posts');
$this->assertEquals(Inflector::humanize('posts_tags'), 'Posts Tags');
$this->assertEquals(Inflector::humanize('file_systems'), 'File Systems');
$this->assertEquals(Inflector::humanize('hello_wörld'), 'Hello Wörld');
$this->assertEquals(Inflector::humanize('福岡_city'), '福岡 City');
}
/**
@@ -479,7 +479,12 @@ public static function camelize($lowerCaseAndUnderscoredWord) {
*/
public static function underscore($camelCasedWord) {
if (!($result = self::_cache(__FUNCTION__, $camelCasedWord))) {
$result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
$underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord);
if (function_exists('mb_convert_case')) {
$result = mb_convert_case($underscoredWord, MB_CASE_LOWER, Configure::read('App.encoding'));
} else {
$result = strtolower($underscoredWord);
}
self::_cache(__FUNCTION__, $camelCasedWord, $result);
}
return $result;
@@ -495,8 +500,9 @@ public static function underscore($camelCasedWord) {
*/
public static function humanize($lowerCaseAndUnderscoredWord) {
if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
$lowerCaseAndUnderscoredWord = self::underscore($lowerCaseAndUnderscoredWord);
$result = str_replace('_', ' ', $lowerCaseAndUnderscoredWord);
if (function_exists('mb_convert_case') && Multibyte::checkMultibyte($result)) {
if (function_exists('mb_convert_case')) {
$result = mb_convert_case($result, MB_CASE_TITLE, Configure::read('App.encoding'));
} else {
$result = ucwords($result);

0 comments on commit c6e4208

Please sign in to comment.
You can’t perform that action at this time.