MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ConvertFileStreams

Function ConvertFileStreams

src/tools/CommandLineMain.cpp:468–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466}
467
468void 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
509void ConvertFile(std::string fileName) {
510 FILE* fin = OpenFileUtf8(fileName, "rb");

Callers 1

ConvertFileFunction · 0.85

Calls 7

ReadLineFunction · 0.85
ConvertLineByModeFunction · 0.85
DurationToMillisecondsFunction · 0.85
ConvertStreamFunction · 0.85
emptyMethod · 0.45
pop_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected