[pLog-svn] r4775 - in plog/branches/lifetype-1.2/class: misc test/tests test/tests/misc

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Feb 18 16:09:52 EST 2007


Author: oscar
Date: 2007-02-18 16:09:52 -0500 (Sun, 18 Feb 2007)
New Revision: 4775

Added:
   plog/branches/lifetype-1.2/class/test/tests/misc/
   plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php
Modified:
   plog/branches/lifetype-1.2/class/misc/glob.class.php
Log:
Minor code optimization.


Modified: plog/branches/lifetype-1.2/class/misc/glob.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/glob.class.php	2007-02-18 20:52:26 UTC (rev 4774)
+++ plog/branches/lifetype-1.2/class/misc/glob.class.php	2007-02-18 21:09:52 UTC (rev 4775)
@@ -126,12 +126,12 @@
          *
          * Based on a user-contributed code for the fnmatch php function here:
          * http://www.php.net/manual/en/function.fnmatch.php
+ 	 	 *
+		 * @static
          */
         function myFnmatch( $pattern, $file )
         {
-
-
-        	for($i=0; $i<strlen($pattern); $i++) {
+        	for($i=0,$len = strlen($pattern); $i<$len; $i++) {
             	if($pattern[$i] == "*") {
                 	for($c=$i; $c<max(strlen($pattern), strlen($file)); $c++) {
                     	if(Glob::myFnmatch(substr($pattern, $i+1), substr($file, $c))) {
@@ -142,7 +142,7 @@
                 }
                 if($pattern[$i] == "[") {
                 	$letter_set = array();
-                    for($c=$i+1; $c<strlen($pattern); $c++) {
+                    for($c=$i+1, $len2 = strlen($pattern); $c<$len2; $c++) {
                     	if($pattern[$c] != "]") {
                         	array_push($letter_set, $pattern[$c]);
                         }

Added: plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php	2007-02-18 21:09:52 UTC (rev 4775)
@@ -0,0 +1,22 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/misc/glob.class.php" );	
+
+	/**
+	 * \ingroup Test
+	 *
+	 * Test cases for the Glob class.
+	 */
+	class Glob_Test extends LifeTypeTestCase
+	{
+		function testmyFnMatch()
+		{
+			// incorrect match
+			$this->assertFalse( Glob::myFnMatch( "*.index.template.*", "index.template.php" ));
+			
+			// valid match
+			$this->assertTrue( Glob::myFnMatch( "*index.template.*", "index.template.php" ));			
+		}		
+	}
+?>
\ No newline at end of file



More information about the pLog-svn mailing list