[Solar-svn] Revision 3260
pmjones at solarphp.com
pmjones at solarphp.com
Sun Jul 27 10:01:39 CDT 2008
Solar_Inflect: [ADD] New inflections based on dashes, not underscores.
Modified: trunk/Solar/Inflect.php
===================================================================
--- trunk/Solar/Inflect.php 2008-07-27 14:34:56 UTC (rev 3259)
+++ trunk/Solar/Inflect.php 2008-07-27 15:01:34 UTC (rev 3260)
@@ -284,6 +284,23 @@
/**
*
+ * Returns "foo-bar-baz" as "fooBarBaz".
+ *
+ * @param string $str The dashed word.
+ *
+ * @return string The word in camel-caps.
+ *
+ */
+ public function dashToCamel($str)
+ {
+ $str = ucwords(str_replace('-', ' ', $str));
+ $str = str_replace(' ', '', $str);
+ $str[0] = strtolower($str[0]);
+ return $str;
+ }
+
+ /**
+ *
* Returns "foo_bar_baz" as "FooBarBaz".
*
* @param string $str The underscore word.
@@ -300,6 +317,22 @@
/**
*
+ * Returns "foo-bar-baz" as "FooBarBaz".
+ *
+ * @param string $str The dashed word.
+ *
+ * @return string The word in studly-caps.
+ *
+ */
+ public function dashToStudly($str)
+ {
+ $str = $this->dashToCamel($str);
+ $str[0] = strtoupper($str[0]);
+ return $str;
+ }
+
+ /**
+ *
* Returns "camelCapsWord" and "CamelCapsWord" as "Camel_Caps_Word".
*
* @param string $str The camel-caps word.
@@ -316,6 +349,22 @@
/**
*
+ * Returns "camelCapsWord" and "CamelCapsWord" as "camel-caps-word".
+ *
+ * @param string $str The camel-caps word.
+ *
+ * @return string The word with dashes in place of camel caps.
+ *
+ */
+ public function camelToDash($str)
+ {
+ $str = preg_replace('/([a-z])([A-Z])/', '$1 $2', $str);
+ $str = str_replace(' ', '-', ucwords($str));
+ return $str;
+ }
+
+ /**
+ *
* Returns "Class_Name" as "Class/Name.php".
*
* @param string $str The class name.
More information about the Solar-svn
mailing list