FACT++  1.0
map< string, string > Tools::Split ( std::string &  opt,
bool  allow = false 
)

Splits a string into a filename and command line arguments, like:

file.txt arg1=argument1 arg2="argument 2" arg3="argument \"3""

'file.txt' will be returned on opt, the arguments will be returned in the returned map.

If the returned file name is empty, an error has occured: If the map is also empty the file name was empty, if the map has one entry then for this entry the equal sign was missing.

Definition at line 230 of file tools.cc.

References data, and i.

Referenced by FactGui::FactGui(), SkypeClient::HandleConnect(), SkypeClient::HandleDBusMessage(), DimLoggerCheck::Handler(), ConnectionGPS::ParseAnswer(), Readline::Process(), RemoteControl< Shell >::Process(), and StateMachineDimControl::StartScript().

231 {
232  using namespace boost;
233  typedef escaped_list_separator<char> separator;
234 
235  const string data(opt);
236 
237  const tokenizer<separator> tok(data, separator("\\", " ", "\"'"));
238 
239  auto it=tok.begin();
240  if (it==tok.end())
241  {
242  opt = "";
243  return map<string,string>();
244  }
245 
246  opt = string(*it).find_first_of('=')==string::npos ? *it++ : "";
247 
248  map<string,string> rc;
249 
250  int i=-1;
251 
252  for (; it!=tok.end(); it++)
253  {
254  if (it->empty())
255  continue;
256 
257  i++;
258 
259  const size_t pos = it->find_first_of('=');
260  if (pos==string::npos)
261  {
262  if (allow)
263  {
264  rc[to_string(i)] = *it;
265  continue;
266  }
267 
268  opt = "";
269  rc.clear();
270  rc[*it] = "";
271  return rc;
272  }
273 
274  rc[it->substr(0, pos)] = it->substr(pos+1);
275  }
276 
277  return rc;
278 }
int i
Definition: db_dim_client.c:21
float data[4 *1440]

+ Here is the caller graph for this function: