mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-21 17:13:09 +08:00
Remove unused parts of class STRING
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
576c09bf31
commit
57920174dc
@ -18,14 +18,8 @@
|
||||
|
||||
#include "strngs.h"
|
||||
|
||||
#include "errcode.h" // for ASSERT_HOST
|
||||
|
||||
#include "helpers.h" // for ReverseN
|
||||
#include "serialis.h" // for TFile
|
||||
|
||||
#include <cassert> // for assert
|
||||
#include <locale> // for std::locale::classic
|
||||
#include <sstream> // for std::stringstream
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
@ -46,69 +40,4 @@ const std::vector<std::string> split(const std::string &s, char c) {
|
||||
return v;
|
||||
}
|
||||
|
||||
// TODO(rays) Change all callers to use TFile and remove the old functions.
|
||||
// Writes to the given file. Returns false in case of error.
|
||||
bool STRING::Serialize(FILE *fp) const {
|
||||
uint32_t len = length();
|
||||
return tesseract::Serialize(fp, &len) && tesseract::Serialize(fp, c_str(), len);
|
||||
}
|
||||
|
||||
// Writes to the given file. Returns false in case of error.
|
||||
bool STRING::Serialize(TFile *fp) const {
|
||||
uint32_t len = length();
|
||||
return fp->Serialize(&len) && fp->Serialize(c_str(), len);
|
||||
}
|
||||
|
||||
// Reads from the given file. Returns false in case of error.
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
bool STRING::DeSerialize(bool swap, FILE *fp) {
|
||||
uint32_t len;
|
||||
if (!tesseract::DeSerialize(fp, &len))
|
||||
return false;
|
||||
if (swap)
|
||||
ReverseN(&len, sizeof(len));
|
||||
// Arbitrarily limit the number of characters to protect against bad data.
|
||||
if (len > UINT16_MAX)
|
||||
return false;
|
||||
resize(len);
|
||||
return tesseract::DeSerialize(fp, data(), len);
|
||||
}
|
||||
|
||||
// Reads from the given file. Returns false in case of error.
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
bool STRING::DeSerialize(TFile *fp) {
|
||||
uint32_t len;
|
||||
if (!fp->DeSerialize(&len))
|
||||
return false;
|
||||
resize(len);
|
||||
return fp->DeSerialize(data(), len);
|
||||
}
|
||||
|
||||
// As DeSerialize, but only seeks past the data - hence a static method.
|
||||
bool STRING::SkipDeSerialize(TFile *fp) {
|
||||
uint32_t len;
|
||||
if (!fp->DeSerialize(&len))
|
||||
return false;
|
||||
return fp->Skip(len);
|
||||
}
|
||||
|
||||
void STRING::split(const char c, std::vector<STRING> *splited) {
|
||||
int start_index = 0;
|
||||
const int len = length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
if ((*this)[i] == c) {
|
||||
if (i != start_index) {
|
||||
(*this)[i] = '\0';
|
||||
splited->push_back(STRING(c_str() + start_index, i - start_index));
|
||||
(*this)[i] = c;
|
||||
}
|
||||
start_index = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (len != start_index) {
|
||||
splited->push_back(STRING(c_str() + start_index, len - start_index));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace tesseract
|
||||
|
@ -19,45 +19,19 @@
|
||||
#ifndef STRNGS_H
|
||||
#define STRNGS_H
|
||||
|
||||
#include <tesseract/export.h> // for TESS_API
|
||||
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint32_t
|
||||
#include <cstdio> // for FILE
|
||||
#include <cstring> // for strncpy
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
class TFile;
|
||||
|
||||
class STRING : public std::string {
|
||||
public:
|
||||
using std::string::string;
|
||||
STRING(const std::string &s) : std::string(s) {}
|
||||
STRING(const char *s) : std::string(s ? s : "") {}
|
||||
|
||||
// Writes to the given file. Returns false in case of error.
|
||||
TESS_API
|
||||
bool Serialize(FILE *fp) const;
|
||||
// Reads from the given file. Returns false in case of error.
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
TESS_API
|
||||
bool DeSerialize(bool swap, FILE *fp);
|
||||
// Writes to the given file. Returns false in case of error.
|
||||
TESS_API
|
||||
bool Serialize(tesseract::TFile *fp) const;
|
||||
// Reads from the given file. Returns false in case of error.
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
TESS_API
|
||||
bool DeSerialize(tesseract::TFile *fp);
|
||||
// As DeSerialize, but only seeks past the data - hence a static method.
|
||||
TESS_API
|
||||
static bool SkipDeSerialize(tesseract::TFile *fp);
|
||||
|
||||
TESS_API
|
||||
void split(char c, std::vector<STRING> *splited);
|
||||
STRING() {
|
||||
}
|
||||
STRING(const std::string &s) : std::string(s) {
|
||||
}
|
||||
STRING(const char *s) : std::string(s ? s : "") {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace tesseract.
|
||||
|
Loading…
Reference in New Issue
Block a user