Skip to content

Commit

Permalink
Remove old code for string class (no longer needed) (#1354)
Browse files Browse the repository at this point in the history
* Remove old code for string class (no longer needed)

Signed-off-by: Stefan Weil <sw@weilnetz.de>

* Add std namespace to string class

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil authored and zdenop committed Mar 3, 2018
1 parent 9035217 commit 068d43d
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 244 deletions.
2 changes: 1 addition & 1 deletion ccstruct/ratngs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ WERD_CHOICE::WERD_CHOICE(const char *src_string,
: unicharset_(&unicharset){
GenericVector<UNICHAR_ID> encoding;
GenericVector<char> lengths;
string cleaned = unicharset.CleanupString(src_string);
std::string cleaned = unicharset.CleanupString(src_string);
if (unicharset.encode_string(cleaned.c_str(), true, &encoding, &lengths,
NULL)) {
lengths.push_back('\0');
Expand Down
6 changes: 0 additions & 6 deletions ccutil/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@
#define SIGNED signed
#endif

// Fix to map between google use of string without std and everywhere else.
#ifdef USE_STD_NAMESPACE
#include <string>
using std::string;
#endif

#if defined(_WIN32) || defined(__CYGWIN__)
#ifndef M_PI
#define M_PI 3.14159265358979323846
Expand Down
8 changes: 4 additions & 4 deletions ccutil/tessdatamanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ bool TessdataManager::GetComponent(TessdataType type, TFile *fp) const {
}

// Returns the current version string.
string TessdataManager::VersionString() const {
return string(&entries_[TESSDATA_VERSION][0],
entries_[TESSDATA_VERSION].size());
std::string TessdataManager::VersionString() const {
return std::string(&entries_[TESSDATA_VERSION][0],
entries_[TESSDATA_VERSION].size());
}

// Sets the version string to the given v_str.
void TessdataManager::SetVersionString(const string &v_str) {
void TessdataManager::SetVersionString(const std::string &v_str) {
entries_[TESSDATA_VERSION].resize_no_init(v_str.size());
memcpy(&entries_[TESSDATA_VERSION][0], v_str.data(), v_str.size());
}
Expand Down
4 changes: 2 additions & 2 deletions ccutil/tessdatamanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class TessdataManager {
bool GetComponent(TessdataType type, TFile *fp) const;

// Returns the current version string.
string VersionString() const;
std::string VersionString() const;
// Sets the version string to the given v_str.
void SetVersionString(const string &v_str);
void SetVersionString(const std::string &v_str);

// Returns true if the base Tesseract components are present.
bool IsBaseAvailable() const {
Expand Down
4 changes: 2 additions & 2 deletions ccutil/unichar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ std::vector<char32> UNICHAR::UTF8ToUTF32(const char* utf8_str) {
}

// Returns an empty string if the input contains an invalid unicode.
string UNICHAR::UTF32ToUTF8(const std::vector<char32>& str32) {
string utf8_str;
std::string UNICHAR::UTF32ToUTF8(const std::vector<char32>& str32) {
std::string utf8_str;
for (char32 ch : str32) {
UNICHAR uni_ch(ch);
int step;
Expand Down
2 changes: 1 addition & 1 deletion ccutil/unicharcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET& unicharset, int null_id,
RecodedCharID code;
// Convert to unicodes.
std::vector<char32> unicodes;
string cleaned;
std::string cleaned;
if (u < unicharset.size())
cleaned = UNICHARSET::CleanupString(unicharset.id_to_unichar(u));
if (u < unicharset.size() &&
Expand Down
14 changes: 7 additions & 7 deletions ccutil/unicharset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void UNICHARSET::reserve(int unichars_number) {

UNICHAR_ID
UNICHARSET::unichar_to_id(const char* const unichar_repr) const {
string cleaned =
std::string cleaned =
old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
return ids.contains(cleaned.data(), cleaned.size())
? ids.unichar_to_id(cleaned.data(), cleaned.size())
Expand All @@ -215,7 +215,7 @@ UNICHARSET::unichar_to_id(const char* const unichar_repr) const {
UNICHAR_ID UNICHARSET::unichar_to_id(const char* const unichar_repr,
int length) const {
assert(length > 0 && length <= UNICHAR_LEN);
string cleaned(unichar_repr, length);
std::string cleaned(unichar_repr, length);
if (!old_style_included_) cleaned = CleanupString(unichar_repr, length);
return ids.contains(cleaned.data(), cleaned.size())
? ids.unichar_to_id(cleaned.data(), cleaned.size())
Expand Down Expand Up @@ -623,7 +623,7 @@ char UNICHARSET::get_chartype(UNICHAR_ID id) const {
void UNICHARSET::unichar_insert(const char* const unichar_repr,
OldUncleanUnichars old_style) {
if (old_style == OldUncleanUnichars::kTrue) old_style_included_ = true;
string cleaned =
std::string cleaned =
old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
if (!cleaned.empty() && !ids.contains(cleaned.data(), cleaned.size())) {
const char* str = cleaned.c_str();
Expand Down Expand Up @@ -666,7 +666,7 @@ void UNICHARSET::unichar_insert(const char* const unichar_repr,
}

bool UNICHARSET::contains_unichar(const char* const unichar_repr) const {
string cleaned =
std::string cleaned =
old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
return ids.contains(cleaned.data(), cleaned.size());
}
Expand All @@ -676,7 +676,7 @@ bool UNICHARSET::contains_unichar(const char* const unichar_repr,
if (length == 0) {
return false;
}
string cleaned(unichar_repr, length);
std::string cleaned(unichar_repr, length);
if (!old_style_included_) cleaned = CleanupString(unichar_repr, length);
return ids.contains(cleaned.data(), cleaned.size());
}
Expand Down Expand Up @@ -1115,8 +1115,8 @@ int UNICHARSET::get_script_id_from_name(const char* script_name) const {
// Removes/replaces content that belongs in rendered text, but not in the
// unicharset.
/* static */
string UNICHARSET::CleanupString(const char* utf8_str, int length) {
string result;
std::string UNICHARSET::CleanupString(const char* utf8_str, int length) {
std::string result;
result.reserve(length);
char ch;
while ((ch = *utf8_str) != '\0' && --length >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion lstm/lstmtrainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ bool LSTMTrainer::EncodeString(const STRING& str, const UNICHARSET& unicharset,
GenericVector<int> internal_labels;
labels->truncate(0);
if (!simple_text) labels->push_back(null_char);
string cleaned = unicharset.CleanupString(str.string());
std::string cleaned = unicharset.CleanupString(str.string());
if (unicharset.encode_string(cleaned.c_str(), true, &internal_labels, NULL,
&err_index)) {
bool success = true;
Expand Down
2 changes: 1 addition & 1 deletion lstm/lstmtrainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LSTMTrainer : public LSTMRecognizer {
// Initializes the character set encode/decode mechanism directly from a
// previously setup traineddata containing dawgs, UNICHARSET and
// UnicharCompress. Note: Call before InitNetwork!
void InitCharSet(const string& traineddata_path) {
void InitCharSet(const std::string& traineddata_path) {
ASSERT_HOST(mgr_.Init(traineddata_path.c_str()));
InitCharSet();
}
Expand Down
10 changes: 5 additions & 5 deletions training/boxchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,16 @@ void BoxChar::RotateBoxes(float rotation, int xcenter, int ycenter,

const int kMaxLineLength = 1024;
/* static */
void BoxChar::WriteTesseractBoxFile(const string& filename, int height,
void BoxChar::WriteTesseractBoxFile(const std::string& filename, int height,
const std::vector<BoxChar*>& boxes) {
string output = GetTesseractBoxStr(height, boxes);
std::string output = GetTesseractBoxStr(height, boxes);
File::WriteStringToFileOrDie(output, filename);
}

/* static */
string BoxChar::GetTesseractBoxStr(int height,
const std::vector<BoxChar*>& boxes) {
string output;
std::string BoxChar::GetTesseractBoxStr(int height,
const std::vector<BoxChar*>& boxes) {
std::string output;
char buffer[kMaxLineLength];
for (size_t i = 0; i < boxes.size(); ++i) {
const Box* box = boxes[i]->box_;
Expand Down
12 changes: 6 additions & 6 deletions training/boxchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BoxChar {
~BoxChar();

// Accessors.
const string& ch() const { return ch_; }
const std::string& ch() const { return ch_; }
const Box* box() const { return box_; }
const int& page() const { return page_; }
void set_rtl_index(int index) { rtl_index_ = index; }
Expand All @@ -51,7 +51,7 @@ class BoxChar {

void set_page(int page) { page_ = page; }

string* mutable_ch() { return &ch_; }
std::string* mutable_ch() { return &ch_; }
Box* mutable_box() { return box_; }

// Sort function for sorting by left edge of box. Note that this will not
Expand Down Expand Up @@ -102,15 +102,15 @@ class BoxChar {

// Create a tesseract box file from the vector of boxes. The image height
// is needed to convert to tesseract coordinates.
static void WriteTesseractBoxFile(const string& name, int height,
static void WriteTesseractBoxFile(const std::string& name, int height,
const std::vector<BoxChar*>& boxes);
// Gets the tesseract box file as a string from the vector of boxes.
// The image height is needed to convert to tesseract coordinates.
static string GetTesseractBoxStr(int height,
const std::vector<BoxChar*>& boxes);
static std::string GetTesseractBoxStr(int height,
const std::vector<BoxChar*>& boxes);

private:
string ch_;
std::string ch_;
Box* box_;
int page_;
// If the box is an RTL character, contains the original position in the
Expand Down
20 changes: 10 additions & 10 deletions training/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ namespace tesseract {
///////////////////////////////////////////////////////////////////////////////
// File::
///////////////////////////////////////////////////////////////////////////////
FILE* File::Open(const string& filename, const string& mode) {
FILE* File::Open(const std::string& filename, const std::string& mode) {
return fopen(filename.c_str(), mode.c_str());
}

FILE* File::OpenOrDie(const string& filename,
const string& mode) {
FILE* File::OpenOrDie(const std::string& filename,
const std::string& mode) {
FILE* stream = fopen(filename.c_str(), mode.c_str());
if (stream == nullptr) {
tprintf("Unable to open '%s' in mode '%s'\n", filename.c_str(),
Expand All @@ -49,8 +49,8 @@ FILE* File::OpenOrDie(const string& filename,
return stream;
}

void File::WriteStringToFileOrDie(const string& str,
const string& filename) {
void File::WriteStringToFileOrDie(const std::string& str,
const std::string& filename) {
FILE* stream = fopen(filename.c_str(), "wb");
if (stream == nullptr) {
tprintf("Unable to open '%s' for writing\n", filename.c_str());
Expand All @@ -60,7 +60,7 @@ void File::WriteStringToFileOrDie(const string& str,
ASSERT_HOST(fclose(stream) == 0);
}

bool File::Readable(const string& filename) {
bool File::Readable(const std::string& filename) {
FILE* stream = fopen(filename.c_str(), "rb");
if (stream == nullptr) {
return false;
Expand All @@ -69,7 +69,7 @@ bool File::Readable(const string& filename) {
return true;
}

bool File::ReadFileToString(const string& filename, string* out) {
bool File::ReadFileToString(const std::string& filename, std::string* out) {
FILE* stream = File::Open(filename.c_str(), "rb");
if (stream == nullptr) return false;
InputBuffer in(stream);
Expand All @@ -78,7 +78,7 @@ bool File::ReadFileToString(const string& filename, string* out) {
return in.CloseFile();
}

string File::JoinPath(const string& prefix, const string& suffix) {
std::string File::JoinPath(const std::string& prefix, const std::string& suffix) {
return (prefix.empty() || prefix[prefix.size() - 1] == '/')
? prefix + suffix
: prefix + "/" + suffix;
Expand Down Expand Up @@ -145,7 +145,7 @@ InputBuffer::~InputBuffer() {
}
}

bool InputBuffer::Read(string* out) {
bool InputBuffer::Read(std::string* out) {
char buf[BUFSIZ + 1];
int l;
while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
Expand Down Expand Up @@ -183,7 +183,7 @@ OutputBuffer::~OutputBuffer() {
}
}

void OutputBuffer::WriteString(const string& str) {
void OutputBuffer::WriteString(const std::string& str) {
fputs(str.c_str(), stream_);
}

Expand Down
16 changes: 8 additions & 8 deletions training/fileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ class File {
public:
// Try to open the file 'filename' in mode 'mode'.
// Stop the program if it cannot open it.
static FILE* OpenOrDie(const string& filename, const string& mode);
static FILE* Open(const string& filename, const string& mode);
static FILE* OpenOrDie(const std::string& filename, const std::string& mode);
static FILE* Open(const std::string& filename, const std::string& mode);

// Try to open the file 'filename' and to write 'str' in it.
// Stop the program if it fails.
static void WriteStringToFileOrDie(const string& str, const string& filename);
static void WriteStringToFileOrDie(const std::string& str, const std::string& filename);

// Return true if the file 'filename' is readable.
static bool Readable(const string& filename);
static bool Readable(const std::string& filename);

static bool ReadFileToString(const string& filename, string* out);
static bool ReadFileToString(const std::string& filename, std::string* out);

// Helper methods

// Concatenate file paths removing any extra intervening '/' symbols.
static string JoinPath(const string& prefix, const string& suffix);
static std::string JoinPath(const std::string& prefix, const std::string& suffix);
// Delete a filename or all filenames matching a glob pattern.
static bool Delete(const char* pathname);
static bool DeleteMatchingFiles(const char* pattern);
Expand All @@ -63,7 +63,7 @@ class InputBuffer {
// Read data until end-of-file.
// The data is stored in '*out'.
// Return false if an error occurs, true otherwise.
bool Read(string* out);
bool Read(std::string* out);

// Close the FILE* used by InputBuffer.
// Return false if an error occurs, true otherwise.
Expand All @@ -84,7 +84,7 @@ class OutputBuffer {
~OutputBuffer();

// Write string 'str' to the open FILE*.
void WriteString(const string& str);
void WriteString(const std::string& str);

// Close the FILE* used by InputBuffer.
// Return false if an error occurs, true otherwise.
Expand Down
Loading

0 comments on commit 068d43d

Please sign in to comment.