18 if (this->destinationFile.is_open())
20 this->destinationFile.close();
22 if (this->sourceFile.is_open())
24 this->sourceFile.close();
35 string &destination) : sourceFile(NULL), destinationFile(NULL),
36 bufferSize (0), stopRead(false)
38 if ((!source.empty() && !destination.empty()) && (source == destination))
40 cerr <<
"Input and Output files can not be same.\n";
41 cerr <<
"Input: " << source <<
"\nOutput: " << destination;
42 cerr <<
" passed" << endl;
47 sourceFile.open(source, ios::in | ios::binary);
48 if (sourceFile.fail())
50 cerr <<
"Unable to open " << source << endl;
51 cerr <<
"Error: " << strerror(errno) << endl;
55 if (!destination.empty())
57 destinationFile.open(destination, ios::out | ios::binary | ios::trunc);
58 if (destinationFile.fail())
60 cerr <<
"Unable to open " << destination << endl;
61 cerr <<
"Error: " << strerror(errno) << endl;
76 while (!this->stopRead)
92 if (sourceFile.eof() || cin.eof())
94 this->stopRead =
true;
97 if (sourceFile && sourceFile.is_open())
99 std::getline(sourceFile, input,
'\n');
103 std::getline(cin, input,
'\n');
117 this->buffer.push_back(output);
133 if (destinationFile && destinationFile.is_open())
135 for (
size_t i = 0; i < this->buffer.size(); i++)
138 buffer[i].toUTF8String(temp);
139 destinationFile << temp <<
"\n";
144 for (
size_t i = 0; i < this->buffer.size(); i++)
147 buffer[i].toUTF8String(temp);
148 cout << temp <<
"\n";
163 bool parseCliOptions(
int argc,
char **argv,
string &input,
string &output)
165 boost::program_options::options_description desc(
"fo_unicode_clean "
166 ": recognized options");
169 "help,h",
"shows help"
173 boost::program_options::value<string>(),
178 boost::program_options::value<string>(),
183 boost::program_options::variables_map vm;
187 boost::program_options::store(
188 boost::program_options::command_line_parser(argc,
189 argv).options(desc).run(), vm);
191 if (vm.count(
"help") > 0)
193 cout << desc << endl;
194 cout <<
"If no input passed, read from STDIN." << endl;
195 cout <<
"If no output passed, print to STDOUT." << endl;
199 if (vm.count(
"input"))
201 input = vm[
"input"].as<
string>();
203 if (vm.count(
"output"))
205 output = vm[
"output"].as<
string>();
209 catch (boost::bad_any_cast&)
211 cout <<
"wrong parameter type" << endl;
212 cout << desc << endl;
215 catch (boost::program_options::error&)
217 cout <<
"wrong command line arguments" << endl;
218 cout << desc << endl;
223 int main(
int argc,
char **argv)
225 string input, output;
bool parseCliOptions(int argc, char **argv, CompatibilityCliOptions &dest, std::string &types, std::string &rules, string &jFile, string &mainLicense)
Parse the options sent by CLI to CliOptions object.
FossologyUnicodeClean(std::string &source, std::string &destination)
const std::string dirtyRead()
void flush()
Flush the buffers and reset the internal buffer.
virtual ~FossologyUnicodeClean()
void write(const icu::UnicodeString &output)
Write the string to file/stream.
icu::UnicodeString recodeToUnicode(const std::string &input)