Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Created February 22, 2012 22:49
Show Gist options
  • Save proudlygeek/1888108 to your computer and use it in GitHub Desktop.
Save proudlygeek/1888108 to your computer and use it in GitHub Desktop.
decamelize
<?php
function decamelize($string) {
$matches = array();
preg_match("/.*(?=([A-Z].*))/", $string, $matches);
return $matches;
}
<?php
require_once 'decamelize.php';
class TestDecamelize extends PHPUnit_Framework_TestCase
{
public function testOneCamel()
{
$rs = decamelize("camelCase");
$this->assertEquals($rs[0], "camel");
$this->assertEquals($rs[1], "Case");
}
public function testTwoCamel()
{
$rs = decamelize("camelCaseAgain");
$this->assertEquals($rs, array(
"camelCase",
"Again"
));
}
public function testOneThousandCamel()
{
$camelString = "camel";
for ($i = 0; $i < 999; $i++) {
$camelString .= "Case";
}
$rs = decamelize($camelString . "Case");
$this->assertEquals(2, count($rs));
$this->assertEquals($rs, array(
$camelString,
"Case"
));
}
}
@liuggio
Copy link

liuggio commented Feb 23, 2012

Cool !!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment