Skip to content

Commit

Permalink
Merge pull request #6646 from cakephp/inflector-utf8
Browse files Browse the repository at this point in the history
Port the Inflector fixes from #6635 to 3.0
  • Loading branch information
ADmad committed May 27, 2015
2 parents 8dda329 + 64fef6a commit 3915efe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Utility/Inflector.php
Expand Up @@ -641,7 +641,11 @@ public static function humanize($string, $delimiter = '_')
$result = static::_cache($cacheKey, $string);

if ($result === false) {
$result = ucwords(str_replace($delimiter, ' ', $string));
$result = explode(' ', str_replace($delimiter, ' ', $string));
foreach ($result as &$word) {
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);
}
$result = implode(' ', $result);
static::_cache($cacheKey, $string, $result);
}

Expand All @@ -662,7 +666,7 @@ public static function delimit($string, $delimiter = '_')
$result = static::_cache($cacheKey, $string);

if ($result === false) {
$result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', $delimiter . '\\1', $string));
$result = mb_strtolower(preg_replace('/(?<=\\w)([A-Z])/', $delimiter . '\\1', $string));
static::_cache($cacheKey, $string, $result);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Utility/InflectorTest.php
Expand Up @@ -408,12 +408,14 @@ public function testUnderscore()
$this->assertSame('test_thing_extra', Inflector::underscore('TestThingExtra'));
$this->assertSame('test_thing_extra', Inflector::underscore('testThingExtra'));
$this->assertSame('test_this_thing', Inflector::underscore('test-this-thing'));
$this->assertSame(Inflector::underscore('testThingExtrå'), 'test_thing_extrå');

// Identical checks test the cache code path.
$this->assertSame('test_thing', Inflector::underscore('TestThing'));
$this->assertSame('test_thing', Inflector::underscore('testThing'));
$this->assertSame('test_thing_extra', Inflector::underscore('TestThingExtra'));
$this->assertSame('test_thing_extra', Inflector::underscore('testThingExtra'));
$this->assertSame(Inflector::underscore('testThingExtrå'), 'test_thing_extrå');

// Test stupid values
$this->assertSame('', Inflector::underscore(''));
Expand Down Expand Up @@ -514,6 +516,8 @@ public function testHumanization()
$this->assertEquals('File Systems', Inflector::humanize('file_systems'));
$this->assertSame('', Inflector::humanize(null));
$this->assertSame('', Inflector::humanize(false));
$this->assertSame(Inflector::humanize('hello_wörld'), 'Hello Wörld');
$this->assertSame(Inflector::humanize('福岡_city'), '福岡 City');
}

/**
Expand Down

0 comments on commit 3915efe

Please sign in to comment.