在jsoncpp中看到一段统一处理不同系统回车换行符的代码,防止忘记,记录下来。
std::string
StyledWriter::normalizeEOL( const std::string &text )
{
std::string normalized;
normalized.reserve( text.length() );
const char *begin = text.c_str();
const char *end = begin + text.length();
const char *current = begin;
while ( current != end )
{
char c = *current++;
if ( c == '\r' ) // mac or dos EOL
{
if ( *current == '\n' ) // convert dos EOL
++current;
normalized += '\n';
}
else // handle unix EOL & other char
normalized += c;
}
return normalized;
}
本文介绍了一段在JSONcpp中用于标准化不同操作系统下回车换行符的代码实现。该方法可以确保文本中的换行符被统一为标准格式,避免了因不同系统间换行符差异导致的问题。
1107

被折叠的 条评论
为什么被折叠?



