#include "commandlineparser.h"

namespace cryptrav
{

namespace CommandLineParser
{


int            parse(QString commandLine, QStringList* pListTokens)
{
 int           iStart, iEnd;


 if (pListTokens == NULL)
     return (-1);


 pListTokens -> clear();

 commandLine = commandLine.trimmed();
 commandLine.append(" ");

 iStart = 0;
 iEnd = 0;

 while (iEnd >= 0)
  {
   if (commandLine.at(iStart) != '"')
    {
     iEnd = commandLine.indexOf(" ", iStart);

     if (iEnd > iStart)
      {
       (*pListTokens) << commandLine.mid(iStart, iEnd - iStart);
       iStart = iEnd;
      }
       else
        iStart++;

    }
     else
    {
     iEnd = commandLine.indexOf('"', iStart + 1);

     if (iEnd != (-1))
      {
       (*pListTokens) << commandLine.mid(iStart + 1, iEnd - iStart - 1);
       iStart = iEnd + 1;
      }

    }

  }

 return 0;
}


} // namespace "CommandLineParser"

} // namespace "cryptrav"
