#include <iostream>
#include <string>
std::string boundary="----DDDD-YYYY-ZZZZ-$$$$";
std::string first_boundary="--"+boundary+"\r\n\r\n";
std::string next_boundary="\r\n\r\n--"+boundary+"\r\n\r\n";
std::string last_boundary="\r\n\r\n--"+boundary+"--\r\n\r\n";
int main()
{
int cnt = 0;
std::string context = first_boundary + "11111111111111111" + next_boundary + "222222222222222" + last_boundary;
auto iterHead = context.begin();
auto iterTail = context.begin();
std::size_t iterTailPos = context.rfind(*context.begin(), context.size() - 7);
for (iterTail += iterTailPos ;context.end() != iterHead && context.end() != iterTail + 6 ; ++iterHead, ++iterTail)
{
if (*iterHead == *iterTail)
{
++cnt;
}
else
{
iterTailPos = context.rfind(*context.begin(), iterTailPos-1);
if (0 >= iterTailPos)
{
break;
}
else
{
iterHead = context.begin();
iterTail = context.begin() + iterTailPos;
continue;
}
}
}
std::cout << "boundary["<< iterTailPos << "," << context.size() - 6 << "]:" << context.substr(iterTailPos, context.size() - 6) << std::endl;
std::cout << "cnt:" << cnt << "," << context.size() - 6 - iterTailPos << std::endl;
return 0;
}