tesseract  5.0.0-alpha-619-ge9db
tesseract::File Class Reference

#include <fileio.h>

Inheritance diagram for tesseract::File:
file

Static Public Member Functions

static FILE * OpenOrDie (const std::string &filename, const std::string &mode)
 
static FILE * Open (const std::string &filename, const std::string &mode)
 
static void WriteStringToFileOrDie (const std::string &str, const std::string &filename)
 
static bool Readable (const std::string &filename)
 
static bool ReadFileToString (const std::string &filename, std::string *out)
 
static std::string JoinPath (const std::string &prefix, const std::string &suffix)
 
static bool Delete (const char *pathname)
 
static bool DeleteMatchingFiles (const char *pattern)
 

Detailed Description

Definition at line 55 of file fileio.h.

Member Function Documentation

◆ Delete()

bool tesseract::File::Delete ( const char *  pathname)
static

Definition at line 104 of file fileio.cpp.

107  {
108  WIN32_FIND_DATA data;
109  BOOL result = TRUE;
110  HANDLE handle = FindFirstFile(pattern, &data);
111  bool all_deleted = true;
112  if (handle != INVALID_HANDLE_VALUE) {
113  for (; result; result = FindNextFile(handle, &data)) {
114  all_deleted &= File::Delete(data.cFileName);
115  }
116  FindClose(handle);

◆ DeleteMatchingFiles()

bool tesseract::File::DeleteMatchingFiles ( const char *  pattern)
static

Definition at line 133 of file fileio.cpp.

139  : stream_(stream) {
140 }
141 
142 InputBuffer::InputBuffer(FILE* stream, size_t)
143  : stream_(stream) {
144 }

◆ JoinPath()

std::string tesseract::File::JoinPath ( const std::string prefix,
const std::string suffix 
)
static

Definition at line 98 of file fileio.cpp.

98  {
99  tprintf("ERROR: Unable to delete file '%s$: %s\n", pathname,
100  strerror(errno));
101  return false;
102  }

◆ Open()

FILE * tesseract::File::Open ( const std::string filename,
const std::string mode 
)
static

Definition at line 54 of file fileio.cpp.

◆ OpenOrDie()

FILE * tesseract::File::OpenOrDie ( const std::string filename,
const std::string mode 
)
static

Definition at line 58 of file fileio.cpp.

59  {
60  tprintf("Unable to open '%s' for writing: %s\n",
61  filename.c_str(), strerror(errno));
62  return;
63  }
64  fputs(str.c_str(), stream);
65  ASSERT_HOST(fclose(stream) == 0);
66 }

◆ Readable()

bool tesseract::File::Readable ( const std::string filename)
static

Definition at line 80 of file fileio.cpp.

86  {
87  return (prefix.empty() || prefix[prefix.size() - 1] == '/')

◆ ReadFileToString()

bool tesseract::File::ReadFileToString ( const std::string filename,
std::string out 
)
static

Definition at line 89 of file fileio.cpp.

89  : prefix + "/" + suffix;
90 }
91 
92 bool File::Delete(const char* pathname) {
93 #if !defined(_WIN32) || defined(__MINGW32__)
94  const int status = unlink(pathname);
95 #else
96  const int status = _unlink(pathname);

◆ WriteStringToFileOrDie()

void tesseract::File::WriteStringToFileOrDie ( const std::string str,
const std::string filename 
)
static

Definition at line 68 of file fileio.cpp.

68  {
69  FILE* stream = fopen(filename.c_str(), "rb");
70  if (stream == nullptr) {
71  return false;
72  }
73  fclose(stream);
74  return true;
75 }
76 
77 bool File::ReadFileToString(const std::string& filename, std::string* out) {
78  FILE* stream = File::Open(filename.c_str(), "rb");

The documentation for this class was generated from the following files:
string
std::string string
Definition: equationdetect_test.cc:21
tesseract::File::Delete
static bool Delete(const char *pathname)
Definition: fileio.cpp:104
tesseract::InputBuffer::InputBuffer
InputBuffer(FILE *stream)
Definition: fileio.cpp:150
tesseract::File::Open
static FILE * Open(const std::string &filename, const std::string &mode)
Definition: fileio.cpp:54
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
BOOL
#define BOOL
Definition: capi.h:43
tesseract::File::ReadFileToString
static bool ReadFileToString(const std::string &filename, std::string *out)
Definition: fileio.cpp:89
TRUE
#define TRUE
Definition: capi.h:44
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34