Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgStringUtil.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgStringUtil.cpp
00003     See SgStringUtil.h
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #include "SgSystem.h"
00008 #include "SgStringUtil.h"
00009 
00010 #include <cctype>
00011 #include <sstream>
00012 
00013 using namespace std;
00014 
00015 //----------------------------------------------------------------------------
00016 
00017 vector<string> SgStringUtil::SplitArguments(string s)
00018 {
00019     vector<string> result;
00020     bool escape = false;
00021     bool inString = false;
00022     ostringstream token;
00023     for (size_t i = 0; i < s.size(); ++i)
00024     {
00025         char c = s[i];
00026         if (c == '"' && ! escape)
00027         {
00028             if (inString)
00029             {
00030                 result.push_back(token.str());
00031                 token.str("");
00032             }
00033             inString = ! inString;
00034         }
00035         else if (isspace(c) && ! inString)
00036         {
00037             if (! token.str().empty())
00038             {
00039                 result.push_back(token.str());
00040                 token.str("");
00041             }
00042         }
00043         else
00044             token << c;
00045         escape = (c == '\\' && ! escape);
00046     }
00047             if (! token.str().empty())
00048         result.push_back(token.str());
00049     return result;
00050 }
00051 
00052 //----------------------------------------------------------------------------


17 Jun 2010 Doxygen 1.4.7