29 if (this->destinationFile.is_open())
31 this->destinationFile.close();
33 if (this->sourceFile.is_open())
35 this->sourceFile.close();
46 string &destination) : sourceFile(NULL), destinationFile(NULL),
47 bufferSize (0), stopRead(false)
49 if ((!source.empty() && !destination.empty()) && (source == destination))
51 cerr <<
"Input and Output files can not be same.\n";
52 cerr <<
"Input: " << source <<
"\nOutput: " << destination;
53 cerr <<
" passed" << endl;
58 sourceFile.open(source, ios::in | ios::binary);
59 if (sourceFile.fail())
61 cerr <<
"Unable to open " << source << endl;
62 cerr <<
"Error: " << strerror(errno) << endl;
66 if (!destination.empty())
68 destinationFile.open(destination, ios::out | ios::binary | ios::trunc);
69 if (destinationFile.fail())
71 cerr <<
"Unable to open " << destination << endl;
72 cerr <<
"Error: " << strerror(errno) << endl;
87 while (!this->stopRead)
103 if (sourceFile.eof() || cin.eof())
105 this->stopRead =
true;
108 if (sourceFile && sourceFile.is_open())
110 std::getline(sourceFile, input,
'\n');
114 std::getline(cin, input,
'\n');
128 this->
buffer.push_back(output);
144 if (destinationFile && destinationFile.is_open())
146 for (
size_t i = 0; i < this->
buffer.size(); i++)
149 buffer[i].toUTF8String(temp);
150 destinationFile << temp <<
"\n";
155 for (
size_t i = 0; i < this->
buffer.size(); i++)
158 buffer[i].toUTF8String(temp);
159 cout << temp <<
"\n";
174 bool parseCliOptions(
int argc,
char **argv,
string &input,
string &output)
176 boost::program_options::options_description desc(
"fo_unicode_clean " 177 ": recognized options");
180 "help,h",
"shows help" 184 boost::program_options::value<string>(),
189 boost::program_options::value<string>(),
194 boost::program_options::variables_map vm;
198 boost::program_options::store(
199 boost::program_options::command_line_parser(argc,
200 argv).options(desc).run(), vm);
202 if (vm.count(
"help") > 0)
204 cout << desc << endl;
205 cout <<
"If no input passed, read from STDIN." << endl;
206 cout <<
"If no output passed, print to STDOUT." << endl;
210 if (vm.count(
"input"))
212 input = vm[
"input"].as<
string>();
214 if (vm.count(
"output"))
216 output = vm[
"output"].as<
string>();
220 catch (boost::bad_any_cast&)
222 cout <<
"wrong parameter type" << endl;
223 cout << desc << endl;
226 catch (boost::program_options::error&)
228 cout <<
"wrong command line arguments" << endl;
229 cout << desc << endl;
234 int main(
int argc,
char **argv)
236 string input, output;
void flush()
Flush the buffers and reset the internal buffer.
const std::string dirtyRead()
void write(const icu::UnicodeString &output)
Write the string to file/stream.
FossologyUnicodeClean(std::string &source, std::string &destination)
bool parseCliOptions(int argc, char **argv, CliOptions &dest, std::vector< std::string > &fileNames, std::string &directoryToScan)
Parse the options sent by CLI to CliOptions object.
char buffer[2048]
The last thing received from the scheduler.
icu::UnicodeString recodeToUnicode(const std::string &input)
virtual ~FossologyUnicodeClean()