mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-22 09:53:03 +08:00
Replace STRING::truncate_at() with resize().
This commit is contained in:
parent
e9a2fc0083
commit
d36adf3d40
@ -68,7 +68,7 @@ char* LTRResultIterator::GetUTF8Text(PageIteratorLevel level) const {
|
|||||||
res_it.forward();
|
res_it.forward();
|
||||||
eol = res_it.row() != res_it.prev_row();
|
eol = res_it.row() != res_it.prev_row();
|
||||||
} while (!eol);
|
} while (!eol);
|
||||||
text.truncate_at(text.length() - 1);
|
text.resize(text.length() - 1);
|
||||||
text += line_separator_;
|
text += line_separator_;
|
||||||
eop = res_it.block() != res_it.prev_block() ||
|
eop = res_it.block() != res_it.prev_block() ||
|
||||||
res_it.row()->row->para() != res_it.prev_row()->row->para();
|
res_it.row()->row->para() != res_it.prev_row()->row->para();
|
||||||
|
@ -84,7 +84,7 @@ void BlamerBundle::SetWordTruth(const UNICHARSET& unicharset,
|
|||||||
int total_length = 0;
|
int total_length = 0;
|
||||||
for (int i = 0; i < encoding.size(); total_length += lengths[i++]) {
|
for (int i = 0; i < encoding.size(); total_length += lengths[i++]) {
|
||||||
STRING uch(truth_str + total_length);
|
STRING uch(truth_str + total_length);
|
||||||
uch.truncate_at(lengths[i] - total_length);
|
uch.resize(lengths[i] - total_length);
|
||||||
UNICHAR_ID id = encoding[i];
|
UNICHAR_ID id = encoding[i];
|
||||||
if (id != INVALID_UNICHAR_ID) uch = unicharset.get_normed_unichar(id);
|
if (id != INVALID_UNICHAR_ID) uch = unicharset.get_normed_unichar(id);
|
||||||
truth_text_.push_back(uch);
|
truth_text_.push_back(uch);
|
||||||
|
@ -57,7 +57,7 @@ bool STRING::DeSerialize(bool swap, FILE* fp) {
|
|||||||
ReverseN(&len, sizeof(len));
|
ReverseN(&len, sizeof(len));
|
||||||
// Arbitrarily limit the number of characters to protect against bad data.
|
// Arbitrarily limit the number of characters to protect against bad data.
|
||||||
if (len > UINT16_MAX) return false;
|
if (len > UINT16_MAX) return false;
|
||||||
truncate_at(len);
|
resize(len);
|
||||||
return tesseract::DeSerialize(fp, data(), len);
|
return tesseract::DeSerialize(fp, data(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ bool STRING::DeSerialize(bool swap, FILE* fp) {
|
|||||||
bool STRING::DeSerialize(TFile* fp) {
|
bool STRING::DeSerialize(TFile* fp) {
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
if (!fp->DeSerialize(&len)) return false;
|
if (!fp->DeSerialize(&len)) return false;
|
||||||
truncate_at(len);
|
resize(len);
|
||||||
return fp->DeSerialize(data(), 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);
|
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) {
|
void STRING::split(const char c, std::vector<STRING> *splited) {
|
||||||
int start_index = 0;
|
int start_index = 0;
|
||||||
const int len = length();
|
const int len = length();
|
||||||
|
@ -75,8 +75,6 @@ class STRING : public std::string {
|
|||||||
|
|
||||||
TESS_API
|
TESS_API
|
||||||
void split(char c, std::vector<STRING>* splited);
|
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.
|
// Appends the given string and int (as a %d) to this.
|
||||||
// += cannot be used for ints as there as a char += operator that would
|
// += cannot be used for ints as there as a char += operator that would
|
||||||
|
@ -103,7 +103,7 @@ bool Classify::WriteTRFile(const char* filename) {
|
|||||||
tesseract::Serialize(fp, &tr_file_data_[0], tr_file_data_.length());
|
tesseract::Serialize(fp, &tr_file_data_[0], tr_file_data_.length());
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
tr_file_data_.truncate_at(0);
|
tr_file_data_.resize(0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ std::unique_ptr<MasterTrainer> LoadTrainingData(int argc, const char* const * ar
|
|||||||
if (FLAGS_load_images) {
|
if (FLAGS_load_images) {
|
||||||
STRING image_name = page_name;
|
STRING image_name = page_name;
|
||||||
// Chop off the tr and replace with tif. Extension must be tif!
|
// 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";
|
image_name += "tif";
|
||||||
trainer->LoadPageImages(image_name.c_str());
|
trainer->LoadPageImages(image_name.c_str());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user