]> git.sesse.net Git - vlc/commitdiff
* add a function to parse the mrl line
authorYoann Peronneau <yoann@videolan.org>
Mon, 26 Mar 2007 19:41:07 +0000 (19:41 +0000)
committerYoann Peronneau <yoann@videolan.org>
Mon, 26 Mar 2007 19:41:07 +0000 (19:41 +0000)
modules/gui/qt4/dialogs/open.cpp

index 0d519a790304d8e26fd83f339dba7f10be91cbb8..a98bf9fbb3b6684df7c350de85b8588a3f491d9e 100644 (file)
@@ -1,6 +1,6 @@
 /*****************************************************************************
  * open.cpp : Advanced open dialog
- ****************************************************************************
+ *****************************************************************************
  * Copyright (C) 2006 the VideoLAN team
  * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
  *
@@ -18,7 +18,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
 
 #include <QTabWidget>
 #include <QGridLayout>
@@ -205,3 +206,51 @@ void OpenDialog::newMethod(QString method)
         ui.cacheSpinBox->setValue(i_value);
     }
 }
+
+QStringList SeparateEntries( QString entries )
+{
+    bool b_quotes_mode = false;
+
+    QStringList entries_array;
+    QString entry;
+
+    int index = 0;
+    while( index < entries.size() )
+    {
+        int delim_pos = entries.indexOf( QRegExp( "\\s+" ), index );
+        if( delim_pos < 0 ) delim_pos = entries.size() - 1;
+        entry += entries.mid( index, delim_pos );
+        index = delim_pos + 1;
+
+        if( entry.isEmpty() ) continue;
+
+        if( !b_quotes_mode && entry.endsWith( "\"" ) )
+        {
+            /* Enters quotes mode */
+            entry.truncate( entry.size() - 1 );
+            b_quotes_mode = true;
+        }
+        else if( b_quotes_mode && entry.endsWith( "\"" ) )
+        {
+            /* Finished the quotes mode */
+            entry.truncate( entry.size() - 1 );
+            b_quotes_mode = false;
+        }
+        else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
+        {
+            /* we found a non-quoted standalone string */
+            if( index < entries.size() ||
+                entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
+                entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
+                entry.truncate( entry.size() - 1 );
+            if( !entry.isEmpty() ) entries_array.append( entry );
+            entry = "";
+        }
+        else
+        {;}
+    }
+
+    if( !entry.isEmpty() ) entries_array.append( entry );
+
+    return entries_array;
+}