Skip to content

Instantly share code, notes, and snippets.

@javagg
Created September 27, 2012 07:36
Show Gist options
  • Select an option

  • Save javagg/3792700 to your computer and use it in GitHub Desktop.

Select an option

Save javagg/3792700 to your computer and use it in GitHub Desktop.
parse connection string
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost::lambda;
int main()
{
string connection = "protocal=tcp;ip=asp-sim2-front1.financial-trading-platform.com;port=26213;userid=888888;password=888888;brokerid=4070";
typedef boost::split_iterator<string::iterator> string_split_iterator;
for (string_split_iterator it = boost::make_split_iterator(connection, boost::first_finder(";", boost::is_iequal())); it!=string_split_iterator();
++it) {
cout << boost::copy_range<std::string>(*it) << endl;
}
std::vector<std::string> parts;
std::map<std::string, std::string> params;
boost::split(parts, connection, boost::is_any_of(";"), boost::token_compress_on);
for (typename std::vector<std::string>::iterator it = parts.begin(); it != parts.end(); it++) {
std::vector<std::string> v;
boost::split(v, *it, boost::is_any_of("="));
params[v[0]] = v[1];
}
cout << params.size() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment