Esempio n. 1
0
void process_name_value_string(const std::string& str, const boost::function<void (const std::string&, const std::string&)>& func)
{
  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
  tokenizer tokens(str, boost::char_separator<char>(",", "", boost::drop_empty_tokens));

  for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i)
  {
    std::string lhs, rhs;
    split_string_at(*i, '=', &lhs, &rhs);
    func(lhs, rhs);
  }
}
Esempio n. 2
0
void
ParamList::parse_string(const std::string& str)
{
  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
  tokenizer tokens(str, boost::char_separator<char>(",", ""));

  for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i)
  {
    std::string lhs;
    std::string rhs;

    split_string_at(*i, '=', &lhs, &rhs);

    m_params[lhs] = rhs;
  }
}
Esempio n. 3
0
void process_name_value_string(const std::string& str, const boost::function<void (const std::string&, const std::string&)>& func)
{
  int quote_count = 0;
  std::string res;
  for(std::string::size_type i = 0; i < str.size(); ++i)
  {
    if (str[i] == '[')
    {
      quote_count += 1;
    }
    else if (str[i] == ']')
    {
      quote_count -= 1;
      if (quote_count < 0)
      {
        raise_exception(std::runtime_error, "unexpected ']' at " << i);
      }
    }
    else if (str[i] == '\\')
    {
      i += 1;
      if (i < str.size())
      {
        res += str[i+1];
      }
      else
      {
        res += '\\';
      }
    }
    else if (str[i] == ',')
    {
      if (quote_count == 0)
      {
        if (!res.empty())
        {
          std::string lhs, rhs;
          split_string_at(res, '=', &lhs, &rhs);
          func(lhs, rhs);

          res.clear();
        }
      }
      else
      {
        res += str[i];
      }
    }
    else
    {
      res += str[i];
    }
  }

  if (quote_count != 0)
  {
    raise_exception(std::runtime_error, "unclosed '['");
  }

  if (!res.empty())
  {
    std::string lhs, rhs;
    split_string_at(res, '=', &lhs, &rhs);
    func(lhs, rhs);
  }
}