Can you make this parsing key value pairs snippet better
I have created the following code snippet for parsing name value
pairs. Is this ideal?
-------------------------------------------------------------------------------------
typedef std::map < std::string, std::string > MapNameValT ;
void parseNameValPairs(const std::string & sInp, MapNameValT &
mapOut,
char cNameValDelim, char cFieldDelim)
{
std::istringstream iss(sInp);
std::string sName, sVal;
while( std::getline(iss, sName, cNameValDelim) )
{
std::getline(iss, sVal, cFieldDelim);
mapOut[sName] = sVal;
}
}
-------------------------------------------------------------------------------------
The above code passed all of the below tests:
("8=FIX.4.1,9=302,35=8,49=INET,56=WED2R8,11=,43=N,", '=', ',')); //
Tag 11 is empty
("8=FIX.4.1,9=302,35=8,49=INET,56=WED2R8,11=,43=N", '=', ',')); //
No delim at end
("8=FIX.4.1=9=302=35=8=49=INET=56=WED2R8=11==43=N", '=', '=')); //
Same delim for field and for name/value
("tname^ANO^Aoid^A7.a^Aouser^Adiwakar^Atif^ADAY^A", '\001',
'\001')); // \001 is delim
The ^A in last test case is '\001'