Replace STRING::truncate_at() with resize().

This commit is contained in:
Egor Pugin 2021-03-10 14:40:28 +03:00
parent e9a2fc0083
commit d36adf3d40
6 changed files with 6 additions and 12 deletions

View File

@ -68,7 +68,7 @@ char* LTRResultIterator::GetUTF8Text(PageIteratorLevel level) const {
res_it.forward();
eol = res_it.row() != res_it.prev_row();
} while (!eol);
text.truncate_at(text.length() - 1);
text.resize(text.length() - 1);
text += line_separator_;
eop = res_it.block() != res_it.prev_block() ||
res_it.row()->row->para() != res_it.prev_row()->row->para();

View File

@ -84,7 +84,7 @@ void BlamerBundle::SetWordTruth(const UNICHARSET& unicharset,
int total_length = 0;
for (int i = 0; i < encoding.size(); total_length += lengths[i++]) {
STRING uch(truth_str + total_length);
uch.truncate_at(lengths[i] - total_length);
uch.resize(lengths[i] - total_length);
UNICHAR_ID id = encoding[i];
if (id != INVALID_UNICHAR_ID) uch = unicharset.get_normed_unichar(id);
truth_text_.push_back(uch);

View File

@ -57,7 +57,7 @@ bool STRING::DeSerialize(bool swap, FILE* fp) {
ReverseN(&len, sizeof(len));
// Arbitrarily limit the number of characters to protect against bad data.
if (len > UINT16_MAX) return false;
truncate_at(len);
resize(len);
return tesseract::DeSerialize(fp, data(), len);
}
@ -66,7 +66,7 @@ bool STRING::DeSerialize(bool swap, FILE* fp) {
bool STRING::DeSerialize(TFile* fp) {
uint32_t len;
if (!fp->DeSerialize(&len)) return false;
truncate_at(len);
resize(len);
return fp->DeSerialize(data(), len);
}
@ -81,10 +81,6 @@ bool STRING::contains(const char c) const {
return (c != '\0') && (strchr (c_str(), c) != nullptr);
}
void STRING::truncate_at(int32_t index) {
resize(index);
}
void STRING::split(const char c, std::vector<STRING> *splited) {
int start_index = 0;
const int len = length();

View File

@ -75,8 +75,6 @@ class STRING : public std::string {
TESS_API
void split(char c, std::vector<STRING>* splited);
TESS_API
void truncate_at(int32_t index);
// Appends the given string and int (as a %d) to this.
// += cannot be used for ints as there as a char += operator that would

View File

@ -103,7 +103,7 @@ bool Classify::WriteTRFile(const char* filename) {
tesseract::Serialize(fp, &tr_file_data_[0], tr_file_data_.length());
fclose(fp);
}
tr_file_data_.truncate_at(0);
tr_file_data_.resize(0);
return result;
}

View File

@ -265,7 +265,7 @@ std::unique_ptr<MasterTrainer> LoadTrainingData(int argc, const char* const * ar
if (FLAGS_load_images) {
STRING image_name = page_name;
// Chop off the tr and replace with tif. Extension must be tif!
image_name.truncate_at(image_name.length() - 2);
image_name.resize(image_name.length() - 2);
image_name += "tif";
trainer->LoadPageImages(image_name.c_str());
}