mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 20:59:36 +08:00
fileio: Replace assert with tprintf() and exit(1)
Assertions are good for programming errors, but not for wrong user input. The new code no longer needs File::ReadFileToStringOrDie, so remove that method. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
d093ed40cc
commit
6ec1a0a09b
@ -80,12 +80,6 @@ bool File::ReadFileToString(const string& filename, string* out) {
|
||||
return in.CloseFile();
|
||||
}
|
||||
|
||||
void File::ReadFileToStringOrDie(const string& filename, string* out) {
|
||||
ASSERT_HOST_MSG(ReadFileToString(filename, out),
|
||||
"Failed to read file: %s\n", filename.c_str());
|
||||
}
|
||||
|
||||
|
||||
string File::JoinPath(const string& prefix, const string& suffix) {
|
||||
return (!prefix.size() || prefix[prefix.size() - 1] == '/') ?
|
||||
prefix + suffix : prefix + "/" + suffix;
|
||||
|
@ -42,7 +42,6 @@ class File {
|
||||
// Return true if the file 'filename' is readable.
|
||||
static bool Readable(const string& filename);
|
||||
|
||||
static void ReadFileToStringOrDie(const string& filename, string* out);
|
||||
static bool ReadFileToString(const string& filename, string* out);
|
||||
|
||||
// Helper methods
|
||||
|
@ -499,7 +499,10 @@ int main(int argc, char** argv) {
|
||||
|
||||
string src_utf8;
|
||||
// This c_str is NOT redundant!
|
||||
File::ReadFileToStringOrDie(FLAGS_text.c_str(), &src_utf8);
|
||||
if (!File::ReadFileToString(FLAGS_text.c_str(), &src_utf8)) {
|
||||
tprintf("Failed to read file: %s\n", FLAGS_text.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Remove the unicode mark if present.
|
||||
if (strncmp(src_utf8.c_str(), "\xef\xbb\xbf", 3) == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user