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

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Mar 29 16:07:30 EDT 2008


Author: jondaley
Date: 2008-03-29 16:07:30 -0400 (Sat, 29 Mar 2008)
New Revision: 6279

Modified:
   plog/branches/lifetype-1.2/class/misc/glob.class.php
   plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php
Log:
marked myFnmatch as private/renamed it_myFnmatch.  documentation updates.  updated test case to explicitly test true/false/default - for the case when someone decides to change it some day, maybe we'll remember why the default was case-insensitive

Modified: plog/branches/lifetype-1.2/class/misc/glob.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/glob.class.php	2008-03-29 18:16:35 UTC (rev 6278)
+++ plog/branches/lifetype-1.2/class/misc/glob.class.php	2008-03-29 20:07:30 UTC (rev 6279)
@@ -65,6 +65,7 @@
          *
          * @param pattern The shell pattern.
          * @param file The filename we would like to match.
+         * @param casesensitive Whether the search should be case-sensitive or not
          * @return True if the file matches the pattern or false if not.
          * @static
          */
@@ -81,7 +82,7 @@
             }
             else {
                 // otherwise, use our own
-                return Glob::myFnmatch( $pattern, $file );
+                return Glob::_myFnmatch( $pattern, $file );
             }
         }
 
@@ -132,14 +133,17 @@
          * Based on a user-contributed code for the fnmatch php function here:
          * http://www.php.net/manual/en/function.fnmatch.php
  	 	 *
+         * Note, this function is case-sensitive (like the native fnmatch)
+         *
 		 * @static
+         * @private (call this->fnmatch instead)
          */
-        function myFnmatch( $pattern, $file )
+        function _myFnmatch( $pattern, $file )
         {
         	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))) {
+                    	if(Glob::_myFnmatch(substr($pattern, $i+1), substr($file, $c))) {
                         	return true;
                         }
                     }
@@ -155,7 +159,7 @@
                         	break;
                     }
                     foreach ($letter_set as $letter) {
-                    	if(Glob::myFnmatch($letter.substr($pattern, $c+1), substr($file, $i))) {
+                    	if(Glob::_myFnmatch($letter.substr($pattern, $c+1), substr($file, $i))) {
                         	return true;
                         }
                     }

Modified: 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	2008-03-29 18:16:35 UTC (rev 6278)
+++ plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php	2008-03-29 20:07:30 UTC (rev 6279)
@@ -13,18 +13,21 @@
 		function testmyFnMatch()
 		{
 			// incorrect match
-			$this->assertFalse( Glob::myFnMatch( "*.index.template.*", "index.template.php" ) );
+			$this->assertFalse( Glob::_myFnmatch( "*.index.template.*", "index.template.php" ) );
 
 			// valid match
-			$this->assertTrue( Glob::myFnMatch( "*index.template.*", "index.template.php" ) );		
+			$this->assertTrue( Glob::_myFnmatch( "*index.template.*", "index.template.php" ) );		
 		}
 
 		function testfnmatch()
 		{
-			// incorrect match
+			// case sensitive check => false
 			$this->assertFalse( Glob::fnmatch( "*index.template.PHP", "index.template.php", true ) );
 
-			// valid match
+			// case insensitive check => true
+			$this->assertTrue( Glob::fnmatch( "*index.template.PHP", "index.template.php", false ) );
+
+			// default is case-insensitive => true
 			$this->assertTrue( Glob::fnmatch( "*index.template.PHP", "index.template.php" ) );
 		}		
 	}



More information about the pLog-svn mailing list