rewrite a stringstream converting the line ends
| 291 | |
| 292 | // rewrite a stringstream converting the line ends |
| 293 | void ASConsole::convertLineEnds(ostringstream &out, int lineEnd) |
| 294 | { |
| 295 | assert(lineEnd == LINEEND_WINDOWS || lineEnd == LINEEND_LINUX || lineEnd == LINEEND_MACOLD); |
| 296 | const string &inStr = out.str(); // avoids strange looking syntax |
| 297 | string outStr; // the converted ouput |
| 298 | int inLength = inStr.length(); |
| 299 | for (int pos = 0; pos < inLength; pos++) |
| 300 | { |
| 301 | if (inStr[pos] == '\r') |
| 302 | { |
| 303 | if (inStr[pos + 1] == '\n') |
| 304 | { |
| 305 | // CRLF |
| 306 | if (lineEnd == LINEEND_CR) |
| 307 | { |
| 308 | outStr += inStr[pos]; // Delete the LF |
| 309 | pos++; |
| 310 | continue; |
| 311 | } |
| 312 | else if (lineEnd == LINEEND_LF) |
| 313 | { |
| 314 | outStr += inStr[pos + 1]; // Delete the CR |
| 315 | pos++; |
| 316 | continue; |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | outStr += inStr[pos]; // Do not change |
| 321 | outStr += inStr[pos + 1]; |
| 322 | pos++; |
| 323 | continue; |
| 324 | } |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | // CR |
| 329 | if (lineEnd == LINEEND_CRLF) |
| 330 | { |
| 331 | outStr += inStr[pos]; // Insert the CR |
| 332 | outStr += '\n'; // Insert the LF |
| 333 | continue; |
| 334 | } |
| 335 | else if (lineEnd == LINEEND_LF) |
| 336 | { |
| 337 | outStr += '\n'; // Insert the LF |
| 338 | continue; |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | outStr += inStr[pos]; // Do not change |
| 343 | continue; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | else if (inStr[pos] == '\n') |
| 348 | { |
| 349 | // LF |
| 350 | if (lineEnd == LINEEND_CRLF) |
nothing calls this directly
no outgoing calls
no test coverage detected