stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far...@apache.org
Subject svn commit: r647222 - /stdcxx/trunk/tests/src/fnmatch.cpp
Date Fri, 11 Apr 2008 16:49:17 GMT
Author: faridz
Date: Fri Apr 11 09:49:14 2008
New Revision: 647222

URL: http://svn.apache.org/viewvc?rev=647222&view=rev
Log:
2008-04-11 Farid Zaripov <farid_zaripov@epam.com>

	* tests/src/fnmatch.cpp (rw_fnmatch): Added checking *next for 0 before incrementing
	next in case '?'. Slightly optimized codeand added some _RWSTD_ASSERT's.

Modified:
    stdcxx/trunk/tests/src/fnmatch.cpp

Modified: stdcxx/trunk/tests/src/fnmatch.cpp
URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/fnmatch.cpp?rev=647222&r1=647221&r2=647222&view=diff
==============================================================================
--- stdcxx/trunk/tests/src/fnmatch.cpp (original)
+++ stdcxx/trunk/tests/src/fnmatch.cpp Fri Apr 11 09:49:14 2008
@@ -126,32 +126,35 @@
 _TEST_EXPORT int
 rw_fnmatch (const char *pattern, const char *string, int arg)
 {
+    _RWSTD_ASSERT (pattern);
+    _RWSTD_ASSERT (string);
+
     const char *next = string;
 
     bool esc = false;
 
     for (const char *pc = pattern; ; ++pc) {
 
-        switch (*pc) {
+        switch (const char c = *pc) {
         case '\0':
-            return *pc == *next ? 0 : 1;
+            return !!*next;
 
         case '\\':
-            if (0 == pc - pattern || !esc)
-                esc = true;
-            else {
-                if (*pc != *next)
+            if (esc) {
+                if (c != *next)
                     return 1;
 
                 esc = false;
                 ++next;
             }
+            else
+                esc = true;
                 
             break;
 
         case '*':
             if (esc) {
-                if (*pc != *next)
+                if (c != *next)
                     return 1;
 
                 esc = false;
@@ -174,17 +177,22 @@
             break;
 
         case '?':
-            if (esc && *pc != *next)
-                return 1;
+            if (esc) {
+                if (c != *next)
+                    return 1;
 
-            esc = false;
+                esc = false;
+            }
+
+            if ('\0' == *next)
+                return 1;
 
             ++next;
             break;
 
         case '[':
             if (esc) {
-                if (*pc != *next)
+                if (c != *next)
                     return 1;
 
                 esc = false;
@@ -202,7 +210,7 @@
             break;
             
         default:
-            if (*pc != *next)
+            if (c != *next)
                 return 1;
 
             esc = false;
@@ -216,7 +224,7 @@
             // of the pattern in all asterisks
             if (!esc)
                 while ('*' == *++pc);
-            return *pc != '\0';
+            return !!*pc;
         }
     }
 



Mime
View raw message