【发布时间】:2020-11-22 00:10:00
【问题描述】:
但是,我尝试编写一个自动缩进器 - 它在向流中添加新字符时会跳过字符。我已经尝试调试它并验证 from_next 和 to_next 以及 from 和 to 工作正常。
当然我在规范中遗漏了一些东西,但这是我的代码,也许你能帮帮我:
virtual result_t do_out(state_type& state, const intern_type* from, const intern_type* from_end, const intern_type*& from_next,
extern_type* to, extern_type* to_end, extern_type*& to_next) const override
{
auto result = std::codecvt_base::noconv;
while (from < from_end && to < to_end)
{
if (getState(state).missingWhitespaces > 0u && *from != '\n')
{
while (getState(state).missingWhitespaces > 0u && to < to_end)
{
*to = ' ';
to++;
getState(state).missingWhitespaces--;
}
if (to < to_end)
{
result = std::codecvt_base::partial;
}
else
{
result = std::codecvt_base::partial;
break;
}
}
else
{
*to = *from;
if (*from == '\n')
{
getState(state).missingWhitespaces = tabSize * indentLevel;
}
to++;
from++;
}
}
from_next = from;
to_next = to;
return result;
};
状态对象也正常工作。问题只发生在函数调用之间。
编辑:将if (to < to_end) 之后的结果更改为std::codecvt_base::ok 也不能解决问题。
【问题讨论】:
-
这对我没有帮助,因为用户在某些 cmets 中遇到了问题。但是我发现了问题并写了一个答案。
标签: c++ filestream codec