Skip to content

Commit 068d43d

Browse files
stweilzdenop
authored andcommitted
Remove old code for string class (no longer needed) (#1354)
* Remove old code for string class (no longer needed) Signed-off-by: Stefan Weil <[email protected]> * Add std namespace to string class Signed-off-by: Stefan Weil <[email protected]>
1 parent 9035217 commit 068d43d

28 files changed

+238
-244
lines changed

ccstruct/ratngs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ WERD_CHOICE::WERD_CHOICE(const char *src_string,
201201
: unicharset_(&unicharset){
202202
GenericVector<UNICHAR_ID> encoding;
203203
GenericVector<char> lengths;
204-
string cleaned = unicharset.CleanupString(src_string);
204+
std::string cleaned = unicharset.CleanupString(src_string);
205205
if (unicharset.encode_string(cleaned.c_str(), true, &encoding, &lengths,
206206
NULL)) {
207207
lengths.push_back('\0');

ccutil/platform.h

-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@
5353
#define SIGNED signed
5454
#endif
5555

56-
// Fix to map between google use of string without std and everywhere else.
57-
#ifdef USE_STD_NAMESPACE
58-
#include <string>
59-
using std::string;
60-
#endif
61-
6256
#if defined(_WIN32) || defined(__CYGWIN__)
6357
#ifndef M_PI
6458
#define M_PI 3.14159265358979323846

ccutil/tessdatamanager.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ bool TessdataManager::GetComponent(TessdataType type, TFile *fp) const {
172172
}
173173

174174
// Returns the current version string.
175-
string TessdataManager::VersionString() const {
176-
return string(&entries_[TESSDATA_VERSION][0],
177-
entries_[TESSDATA_VERSION].size());
175+
std::string TessdataManager::VersionString() const {
176+
return std::string(&entries_[TESSDATA_VERSION][0],
177+
entries_[TESSDATA_VERSION].size());
178178
}
179179

180180
// Sets the version string to the given v_str.
181-
void TessdataManager::SetVersionString(const string &v_str) {
181+
void TessdataManager::SetVersionString(const std::string &v_str) {
182182
entries_[TESSDATA_VERSION].resize_no_init(v_str.size());
183183
memcpy(&entries_[TESSDATA_VERSION][0], v_str.data(), v_str.size());
184184
}

ccutil/tessdatamanager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ class TessdataManager {
178178
bool GetComponent(TessdataType type, TFile *fp) const;
179179

180180
// Returns the current version string.
181-
string VersionString() const;
181+
std::string VersionString() const;
182182
// Sets the version string to the given v_str.
183-
void SetVersionString(const string &v_str);
183+
void SetVersionString(const std::string &v_str);
184184

185185
// Returns true if the base Tesseract components are present.
186186
bool IsBaseAvailable() const {

ccutil/unichar.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ std::vector<char32> UNICHAR::UTF8ToUTF32(const char* utf8_str) {
227227
}
228228

229229
// Returns an empty string if the input contains an invalid unicode.
230-
string UNICHAR::UTF32ToUTF8(const std::vector<char32>& str32) {
231-
string utf8_str;
230+
std::string UNICHAR::UTF32ToUTF8(const std::vector<char32>& str32) {
231+
std::string utf8_str;
232232
for (char32 ch : str32) {
233233
UNICHAR uni_ch(ch);
234234
int step;

ccutil/unicharcompress.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET& unicharset, int null_id,
133133
RecodedCharID code;
134134
// Convert to unicodes.
135135
std::vector<char32> unicodes;
136-
string cleaned;
136+
std::string cleaned;
137137
if (u < unicharset.size())
138138
cleaned = UNICHARSET::CleanupString(unicharset.id_to_unichar(u));
139139
if (u < unicharset.size() &&

ccutil/unicharset.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void UNICHARSET::reserve(int unichars_number) {
205205

206206
UNICHAR_ID
207207
UNICHARSET::unichar_to_id(const char* const unichar_repr) const {
208-
string cleaned =
208+
std::string cleaned =
209209
old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
210210
return ids.contains(cleaned.data(), cleaned.size())
211211
? ids.unichar_to_id(cleaned.data(), cleaned.size())
@@ -215,7 +215,7 @@ UNICHARSET::unichar_to_id(const char* const unichar_repr) const {
215215
UNICHAR_ID UNICHARSET::unichar_to_id(const char* const unichar_repr,
216216
int length) const {
217217
assert(length > 0 && length <= UNICHAR_LEN);
218-
string cleaned(unichar_repr, length);
218+
std::string cleaned(unichar_repr, length);
219219
if (!old_style_included_) cleaned = CleanupString(unichar_repr, length);
220220
return ids.contains(cleaned.data(), cleaned.size())
221221
? ids.unichar_to_id(cleaned.data(), cleaned.size())
@@ -623,7 +623,7 @@ char UNICHARSET::get_chartype(UNICHAR_ID id) const {
623623
void UNICHARSET::unichar_insert(const char* const unichar_repr,
624624
OldUncleanUnichars old_style) {
625625
if (old_style == OldUncleanUnichars::kTrue) old_style_included_ = true;
626-
string cleaned =
626+
std::string cleaned =
627627
old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
628628
if (!cleaned.empty() && !ids.contains(cleaned.data(), cleaned.size())) {
629629
const char* str = cleaned.c_str();
@@ -666,7 +666,7 @@ void UNICHARSET::unichar_insert(const char* const unichar_repr,
666666
}
667667

668668
bool UNICHARSET::contains_unichar(const char* const unichar_repr) const {
669-
string cleaned =
669+
std::string cleaned =
670670
old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
671671
return ids.contains(cleaned.data(), cleaned.size());
672672
}
@@ -676,7 +676,7 @@ bool UNICHARSET::contains_unichar(const char* const unichar_repr,
676676
if (length == 0) {
677677
return false;
678678
}
679-
string cleaned(unichar_repr, length);
679+
std::string cleaned(unichar_repr, length);
680680
if (!old_style_included_) cleaned = CleanupString(unichar_repr, length);
681681
return ids.contains(cleaned.data(), cleaned.size());
682682
}
@@ -1115,8 +1115,8 @@ int UNICHARSET::get_script_id_from_name(const char* script_name) const {
11151115
// Removes/replaces content that belongs in rendered text, but not in the
11161116
// unicharset.
11171117
/* static */
1118-
string UNICHARSET::CleanupString(const char* utf8_str, int length) {
1119-
string result;
1118+
std::string UNICHARSET::CleanupString(const char* utf8_str, int length) {
1119+
std::string result;
11201120
result.reserve(length);
11211121
char ch;
11221122
while ((ch = *utf8_str) != '\0' && --length >= 0) {

lstm/lstmtrainer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ bool LSTMTrainer::EncodeString(const STRING& str, const UNICHARSET& unicharset,
756756
GenericVector<int> internal_labels;
757757
labels->truncate(0);
758758
if (!simple_text) labels->push_back(null_char);
759-
string cleaned = unicharset.CleanupString(str.string());
759+
std::string cleaned = unicharset.CleanupString(str.string());
760760
if (unicharset.encode_string(cleaned.c_str(), true, &internal_labels, NULL,
761761
&err_index)) {
762762
bool success = true;

lstm/lstmtrainer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class LSTMTrainer : public LSTMRecognizer {
106106
// Initializes the character set encode/decode mechanism directly from a
107107
// previously setup traineddata containing dawgs, UNICHARSET and
108108
// UnicharCompress. Note: Call before InitNetwork!
109-
void InitCharSet(const string& traineddata_path) {
109+
void InitCharSet(const std::string& traineddata_path) {
110110
ASSERT_HOST(mgr_.Init(traineddata_path.c_str()));
111111
InitCharSet();
112112
}

training/boxchar.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,16 @@ void BoxChar::RotateBoxes(float rotation, int xcenter, int ycenter,
318318

319319
const int kMaxLineLength = 1024;
320320
/* static */
321-
void BoxChar::WriteTesseractBoxFile(const string& filename, int height,
321+
void BoxChar::WriteTesseractBoxFile(const std::string& filename, int height,
322322
const std::vector<BoxChar*>& boxes) {
323-
string output = GetTesseractBoxStr(height, boxes);
323+
std::string output = GetTesseractBoxStr(height, boxes);
324324
File::WriteStringToFileOrDie(output, filename);
325325
}
326326

327327
/* static */
328-
string BoxChar::GetTesseractBoxStr(int height,
329-
const std::vector<BoxChar*>& boxes) {
330-
string output;
328+
std::string BoxChar::GetTesseractBoxStr(int height,
329+
const std::vector<BoxChar*>& boxes) {
330+
std::string output;
331331
char buffer[kMaxLineLength];
332332
for (size_t i = 0; i < boxes.size(); ++i) {
333333
const Box* box = boxes[i]->box_;

training/boxchar.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BoxChar {
4040
~BoxChar();
4141

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

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

54-
string* mutable_ch() { return &ch_; }
54+
std::string* mutable_ch() { return &ch_; }
5555
Box* mutable_box() { return box_; }
5656

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

103103
// Create a tesseract box file from the vector of boxes. The image height
104104
// is needed to convert to tesseract coordinates.
105-
static void WriteTesseractBoxFile(const string& name, int height,
105+
static void WriteTesseractBoxFile(const std::string& name, int height,
106106
const std::vector<BoxChar*>& boxes);
107107
// Gets the tesseract box file as a string from the vector of boxes.
108108
// The image height is needed to convert to tesseract coordinates.
109-
static string GetTesseractBoxStr(int height,
110-
const std::vector<BoxChar*>& boxes);
109+
static std::string GetTesseractBoxStr(int height,
110+
const std::vector<BoxChar*>& boxes);
111111

112112
private:
113-
string ch_;
113+
std::string ch_;
114114
Box* box_;
115115
int page_;
116116
// If the box is an RTL character, contains the original position in the

training/fileio.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ namespace tesseract {
3535
///////////////////////////////////////////////////////////////////////////////
3636
// File::
3737
///////////////////////////////////////////////////////////////////////////////
38-
FILE* File::Open(const string& filename, const string& mode) {
38+
FILE* File::Open(const std::string& filename, const std::string& mode) {
3939
return fopen(filename.c_str(), mode.c_str());
4040
}
4141

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

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

63-
bool File::Readable(const string& filename) {
63+
bool File::Readable(const std::string& filename) {
6464
FILE* stream = fopen(filename.c_str(), "rb");
6565
if (stream == nullptr) {
6666
return false;
@@ -69,7 +69,7 @@ bool File::Readable(const string& filename) {
6969
return true;
7070
}
7171

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

81-
string File::JoinPath(const string& prefix, const string& suffix) {
81+
std::string File::JoinPath(const std::string& prefix, const std::string& suffix) {
8282
return (prefix.empty() || prefix[prefix.size() - 1] == '/')
8383
? prefix + suffix
8484
: prefix + "/" + suffix;
@@ -145,7 +145,7 @@ InputBuffer::~InputBuffer() {
145145
}
146146
}
147147

148-
bool InputBuffer::Read(string* out) {
148+
bool InputBuffer::Read(std::string* out) {
149149
char buf[BUFSIZ + 1];
150150
int l;
151151
while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
@@ -183,7 +183,7 @@ OutputBuffer::~OutputBuffer() {
183183
}
184184
}
185185

186-
void OutputBuffer::WriteString(const string& str) {
186+
void OutputBuffer::WriteString(const std::string& str) {
187187
fputs(str.c_str(), stream_);
188188
}
189189

training/fileio.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ class File {
3030
public:
3131
// Try to open the file 'filename' in mode 'mode'.
3232
// Stop the program if it cannot open it.
33-
static FILE* OpenOrDie(const string& filename, const string& mode);
34-
static FILE* Open(const string& filename, const string& mode);
33+
static FILE* OpenOrDie(const std::string& filename, const std::string& mode);
34+
static FILE* Open(const std::string& filename, const std::string& mode);
3535

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

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

43-
static bool ReadFileToString(const string& filename, string* out);
43+
static bool ReadFileToString(const std::string& filename, std::string* out);
4444

4545
// Helper methods
4646

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

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

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

8989
// Close the FILE* used by InputBuffer.
9090
// Return false if an error occurs, true otherwise.

0 commit comments

Comments
 (0)