-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
90 lines (73 loc) · 2.53 KB
/
common.cpp
File metadata and controls
90 lines (73 loc) · 2.53 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "common.hpp"
namespace basefw{
string GetKeyValue(const string &strSrc, string strKeyItem, string strEndKey, int &iStartPos)
{
std::string strStd = strSrc;
std::string strItems[10];
std::string::size_type iPos1 = 0;
std::string::size_type iPos2 = strKeyItem.find("\\", iPos1);
std::string::size_type i = 0;
for (i = 0; iPos2 != std::string::npos; i++)
{
strItems[i] = strKeyItem.substr(iPos1, iPos2 - iPos1);
iPos1 = iPos2 + 1;
iPos2 = strKeyItem.find("\\", iPos1);
}
strItems[i] = strKeyItem.substr(iPos1, strKeyItem.length() - iPos1);
std::string::size_type iBegin = 0;
std::string::size_type j = 0;
for (j = 0; j <= i; j++)
{
iBegin = strStd.find(strItems[j], iStartPos + iBegin) + strItems[j].length();
if (strItems[j].length() - 1 == iBegin)
{
return "";
}
}
std::string strEnds[10];
iPos1 = 0;
iPos2 = strEndKey.find("|", iPos1);
for (i = 0; iPos2 != std::string::npos; i++)
{
strEnds[i] = strEndKey.substr(iPos1, iPos2 - iPos1);
iPos1 = iPos2 + 1;
iPos2 = strEndKey.find("|", iPos1);
}
strEnds[i] = strEndKey.substr(iPos1, strEndKey.length() - iPos1);
strEnds[++i] = "\r\n";
strEnds[++i] = "\n";
std::string::size_type iEndPos = std::string::npos;
for (j = 0; j <= i; j++)
{
if (strEnds[j].empty())
{
iEndPos = strStd.length();
break;
}
iEndPos = strStd.find(strEnds[j], iBegin);
if (iEndPos != std::string::npos)
{
break;
}
}
if (iEndPos == std::string::npos)
{
iEndPos = strSrc.size();
}
iStartPos = iEndPos;
return strSrc.substr(iBegin, iEndPos - iBegin);
}
string GetKeyValue(const string &strSrc, string strKeyItem, string strEndKey)
{
int iPos = 0;
return GetKeyValue(strSrc, strKeyItem, strEndKey, iPos);
}
bool string2EndpointPara(const string &src, Endpoint &endpoint)
{
string strAddrAndPort = GetKeyValue(src, "http://", "/");
endpoint.strAddr = GetKeyValue(strAddrAndPort, "", ":");
endpoint.strPort = GetKeyValue(strAddrAndPort, ":", "");
endpoint.strOtherPara = GetKeyValue(src, strAddrAndPort, "");
return true;
}
}