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