| 466 | } |
| 467 | |
| 468 | void ConvertFileStreams(FILE* fin, FILE* fout) { |
| 469 | try { |
| 470 | if (outputMode == OutputMode::Segmentation || |
| 471 | outputMode == OutputMode::Inspect) { |
| 472 | // Inspect/segmentation modes process line by line using std::getline to |
| 473 | // handle arbitrarily long lines. |
| 474 | bool isFirstLine = true; |
| 475 | std::string line; |
| 476 | while (ReadLine(fin, &line)) { |
| 477 | if (!line.empty() && line.back() == '\r') { |
| 478 | line.pop_back(); |
| 479 | } |
| 480 | measurement.inputBytes += line.size(); |
| 481 | if (!isFirstLine) { |
| 482 | fputs("\n", fout); |
| 483 | } else { |
| 484 | isFirstLine = false; |
| 485 | } |
| 486 | const std::string& output = ConvertLineByMode(line); |
| 487 | measurement.outputBytes += output.size(); |
| 488 | const auto writeStart = std::chrono::steady_clock::now(); |
| 489 | fputs(output.c_str(), fout); |
| 490 | if (!noFlush) { |
| 491 | fflush(fout); |
| 492 | } |
| 493 | measurement.writeMs += DurationToMilliseconds( |
| 494 | std::chrono::steady_clock::now() - writeStart); |
| 495 | } |
| 496 | } else { |
| 497 | ConvertStream(fin, fout); |
| 498 | } |
| 499 | } catch (...) { |
| 500 | fclose(fin); |
| 501 | fclose(fout); |
| 502 | throw; |
| 503 | } |
| 504 | |
| 505 | fclose(fin); |
| 506 | fclose(fout); |
| 507 | } |
| 508 | |
| 509 | void ConvertFile(std::string fileName) { |
| 510 | FILE* fin = OpenFileUtf8(fileName, "rb"); |
no test coverage detected