不同平台回车换行的统一处理

来源:互联网 发布:sql select 新表 编辑:程序博客网 时间:2024/04/30 15:01

在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;}

原创粉丝点击