[limb-svn] r5994 - 3.x/trunk/limb/core

svn at limb-project.com svn at limb-project.com
Fri Jun 15 14:54:41 MSD 2007


Author: pachanga
Date: 2007-06-15 14:54:41 +0400 (Fri, 15 Jun 2007)
New Revision: 5994
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5994

Modified:
   3.x/trunk/limb/core/common.inc.php
Log:
-- even more optimal lmb_under_scores implementation with preg_split

Modified: 3.x/trunk/limb/core/common.inc.php
===================================================================
--- 3.x/trunk/limb/core/common.inc.php	2007-06-14 11:53:29 UTC (rev 5993)
+++ 3.x/trunk/limb/core/common.inc.php	2007-06-15 10:54:41 UTC (rev 5994)
@@ -168,16 +168,11 @@
 
 function lmb_under_scores($str)
 {
-  $len = strlen($str);
+  $items = preg_split('~([A-Z][a-z0-9]+)~', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
   $res = '';
-  for($i=0;$i<$len;$i++)
-  {
-    if(ctype_upper($str{$i}))
-      $res .= (($i-1 > 0 && $str{$i-1} != '') ?  '_' : '') . strtolower($str{$i});
-    else
-      $res .= $str{$i};
-  }
-  return $res;
+  foreach($items as $item)
+    $res .= ($item == '_' ? '' : '_') . strtolower($item);
+  return substr($res, 1);
 }
 
 function lmb_humanize($str)



More information about the limb-svn mailing list