list stPacketParam CConfig ParseParams string params namespace alg boo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
list<stPacketParam> CConfig::ParseParams(string params)
{
namespace alg = boost::algorithm;
list<stPacketParam> result;
list<string> parlist;
alg::split(parlist, params, alg::is_any_of(",;/") || alg::is_space(), alg::token_compress_on);
for each (string &s in parlist)
{
if (s.empty())
continue;
list<string> p;
alg::split(p, s, alg::is_any_of(":"));
string sname = p.front(), stype = p.back();
size_t size = 0;
if (p.size() != 2 || sname.empty() || sname.empty())
{
Log(formatstr("Params parsing error: bad args (%1%).") % s, LOGOUTPUT_FILE);
break;
}
PacketParamType type = ConvertParamType(stype);
if (type == PPT_UNKNOWN)
{
Log(formatstr("Params parsing error: unknown type (%1%).") % s, LOGOUTPUT_FILE);
break;
}
if (type == PPT_ARRAY)
{
string sz = StringCutFrom(sname, "=");
if (sz.empty() || !alg::all(sz, alg::is_digit))
{
Log(formatstr("Params parsing error: bad array size (%1%).") % s, LOGOUTPUT_FILE);
break;
}
size = stoi(sz);
sname = StringCutTo(sname, "=", false);
}
stPacketParam param;
param._name = sname;
param._size = size;
param._type = type;
result.push_back(param);
}
return result;
}