试图实现类似于CommandLineToArgV的东西:
template<typename InIter, typename OutIter>
inline InIter CmdLineToArgvWUnescape(InIter begin, InIter end, OutIter target)
{
if (std::distance(begin, end) < 2 || *begin != L'"')
{
// ""s are required
throw MalformedEscapedSequence();
}
++begin; //Skip "
std::size_t backslashCount = 0;
for(; begin != end; ++begin)
{
switch(*begin)
{
case L'\\':
backslashCount++;
break;
case L'"':
if (backslashCount)
{
std::fill_n(target, backslashCount / 2, L'\\');
*target++ = L'"';
backslashCount = 0;
}
else
{
return ++begin;
}
default:
if (backslashCount)
{
std::fill_n(target, backslashCount, L'\\');
backslashCount = 0;
}
*target++ = *begin;
}
}
throw MalformedEscapedSequence();
}发布于 2012-03-14 19:18:23
我的一个评论是添加一条关于它到底在做什么的评论。
即使在学习之后,我也不能百分之百地确定它的作用(我需要一些单元测试来感觉我理解它)。
我认为你想达到的目标是:
https://codereview.stackexchange.com/questions/10005
复制相似问题