]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/cmdline.cpp
Correct weak ref usage which triggered an assert
[wxWidgets.git] / src / common / cmdline.cpp
index 63ee43c1a82c3498481d9f7bec6930608e8d84dc..6f3b1860e5c552707b74a9e39b7909cabdb25067 100644 (file)
@@ -1255,62 +1255,47 @@ wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline)
 
     bool isInsideQuotes = false;
 
+    const wxString::const_iterator end = cmdline.end();
     wxString::const_iterator p = cmdline.begin();
 
     for ( ;; )
     {
         // skip white space
-        while ( p != cmdline.end() && (*p == _T(' ') || *p == _T('\t')) )
+        while ( p != end && (*p == ' ' || *p == '\t') )
             ++p;
 
         // anything left?
-        if ( p == cmdline.end() )
+        if ( p == end )
             break;
 
         // parse this parameter
-        bool endParam = false;
         bool lastBS = false;
-        for ( arg.clear(); !endParam; p++ )
+        for ( arg.clear(); p != end; ++p )
         {
-            switch ( (*p).GetValue() )
+            const wxChar ch = *p;
+            if ( ch == '"' )
             {
-                case _T('"'):
-                    if ( !lastBS )
-                    {
-                        isInsideQuotes = !isInsideQuotes;
-
-                        // don't put quote in arg
-                        continue;
-                    }
-                    //else: quote has no special meaning but the backslash
-                    //      still remains -- makes no sense but this is what
-                    //      Windows does
-                    break;
-
-                case _T(' '):
-                case _T('\t'):
-                    // backslash does *not* quote the space, only quotes do
-                    if ( isInsideQuotes )
-                    {
-                        // skip assignment below
-                        break;
-                    }
-                    // fall through
-
-                case _T('\0'):
-                    endParam = true;
+                if ( !lastBS )
+                {
+                    isInsideQuotes = !isInsideQuotes;
 
-                    break;
+                    // don't put quote in arg
+                    continue;
+                }
+                //else: quote has no special meaning but the backslash
+                //      still remains -- makes no sense but this is what
+                //      Windows does
             }
-
-            if ( endParam )
+            // note that backslash does *not* quote the space, only quotes do
+            else if ( !isInsideQuotes && (ch == ' ' || ch == '\t') )
             {
+                ++p;    // skip this space anyhow
                 break;
             }
 
-            lastBS = *p == _T('\\');
+            lastBS = ch == '\\';
 
-            arg += *p;
+            arg += ch;
         }
 
         args.push_back(arg);