From 4c906ee37ab3788cd8aee8f1fd5c249f37229c1d Mon Sep 17 00:00:00 2001 From: Yoann Peronneau Date: Mon, 26 Mar 2007 19:41:07 +0000 Subject: [PATCH] * add a function to parse the mrl line --- modules/gui/qt4/dialogs/open.cpp | 53 ++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/modules/gui/qt4/dialogs/open.cpp b/modules/gui/qt4/dialogs/open.cpp index 0d519a7903..a98bf9fbb3 100644 --- a/modules/gui/qt4/dialogs/open.cpp +++ b/modules/gui/qt4/dialogs/open.cpp @@ -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 #include @@ -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; +} -- 2.39.2