Merge pull request #3351 from stweil/master

Modernize code using clang-tidy
This commit is contained in:
Egor Pugin 2021-03-22 00:43:47 +03:00 committed by GitHub
commit 205cd32184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
93 changed files with 596 additions and 646 deletions

View File

@ -1329,7 +1329,7 @@ size_t TessBaseAPI::GetNumberOfTables()
std::tuple<int,int,int,int> TessBaseAPI::GetTableBoundingBox(unsigned i)
{
const std::vector<TessTable>& t = constUniqueInstance<std::vector<TessTable>>();
const auto &t = constUniqueInstance<std::vector<TessTable>>();
if(i >= t.size())
return std::tuple<int,int,int,int>(0, 0, 0, 0);
@ -1344,7 +1344,7 @@ std::tuple<int,int,int,int> TessBaseAPI::GetTableBoundingBox(unsigned i)
std::vector<std::tuple<int,int,int,int>> TessBaseAPI::GetTableRows(unsigned i)
{
const std::vector<TessTable>& t = constUniqueInstance<std::vector<TessTable>>();
const auto &t = constUniqueInstance<std::vector<TessTable>>();
if(i >= t.size())
return std::vector<std::tuple<int,int,int,int>>();
@ -1362,7 +1362,7 @@ std::vector<std::tuple<int,int,int,int>> TessBaseAPI::GetTableRows(unsigned i)
std::vector<std::tuple<int,int,int,int> > TessBaseAPI::GetTableCols(unsigned i)
{
const std::vector<TessTable>& t = constUniqueInstance<std::vector<TessTable>>();
const auto &t = constUniqueInstance<std::vector<TessTable>>();
if(i >= t.size())
return std::vector<std::tuple<int,int,int,int>>();

View File

@ -205,8 +205,8 @@ int TessBaseAPIInit4(TessBaseAPI *handle, const char *datapath, const char *lang
std::vector<std::string> varValues;
if (vars_vec != nullptr && vars_values != nullptr) {
for (size_t i = 0; i < vars_vec_size; i++) {
varNames.push_back(vars_vec[i]);
varValues.push_back(vars_values[i]);
varNames.emplace_back(vars_vec[i]);
varValues.emplace_back(vars_values[i]);
}
}

View File

@ -385,8 +385,8 @@ bool Tesseract::ResegmentCharBox(PAGE_RES *page_res, const TBOX *prev_box, const
}
tprintf("\n");
tprintf("Correct text = [[ ");
for (auto &correct_text : word_res->correct_text) {
tprintf("%s ", correct_text.c_str());
for (auto &it : word_res->correct_text) {
tprintf("%s ", it.c_str());
}
tprintf("]]\n");
}
@ -578,7 +578,7 @@ bool Tesseract::FindSegmentation(const std::vector<UNICHAR_ID> &target_text, WER
}
word_res->correct_text.clear();
for (auto &text : target_text) {
word_res->correct_text.push_back(unicharset.id_to_unichar(text));
word_res->correct_text.emplace_back(unicharset.id_to_unichar(text));
}
return true;
}

View File

@ -134,8 +134,8 @@ int EquationDetect::LabelSpecialText(TO_BLOCK *to_block) {
std::vector<BLOBNBOX_LIST *> blob_lists;
blob_lists.push_back(&(to_block->blobs));
blob_lists.push_back(&(to_block->large_blobs));
for (int i = 0; i < blob_lists.size(); ++i) {
BLOBNBOX_IT bbox_it(blob_lists[i]);
for (auto &blob_list : blob_lists) {
BLOBNBOX_IT bbox_it(blob_list);
for (bbox_it.mark_cycle_pt(); !bbox_it.cycled_list(); bbox_it.forward()) {
bbox_it.data()->set_special_text_type(BSTT_NONE);
}
@ -227,8 +227,8 @@ BlobSpecialTextType EquationDetect::EstimateTypeForUnichar(const UNICHARSET &uni
if (ids_to_exclude.empty()) {
static const char *kCharsToEx[] = {"'", "`", "\"", "\\", ",", ".",
"", "", "", "", "", ""};
for (auto i = 0; i < countof(kCharsToEx); i++) {
ids_to_exclude.push_back(unicharset.unichar_to_id(kCharsToEx[i]));
for (auto &i : kCharsToEx) {
ids_to_exclude.push_back(unicharset.unichar_to_id(i));
}
std::sort(ids_to_exclude.begin(), ids_to_exclude.end());
}
@ -248,8 +248,8 @@ BlobSpecialTextType EquationDetect::EstimateTypeForUnichar(const UNICHARSET &uni
void EquationDetect::IdentifySpecialText() {
// Set configuration for Tesseract::AdaptiveClassifier.
equ_tesseract_.tess_cn_matching.set_value(1); // turn it on
equ_tesseract_.tess_bn_matching.set_value(0);
equ_tesseract_.tess_cn_matching.set_value(true); // turn it on
equ_tesseract_.tess_bn_matching.set_value(false);
// Set the multiplier to zero for lang_tesseract_ to improve the accuracy.
const int classify_class_pruner = lang_tesseract_->classify_class_pruner_multiplier;
@ -379,16 +379,16 @@ int EquationDetect::FindEquationParts(ColPartitionGrid *part_grid, ColPartitionS
// Pass 3: expand block equation seeds.
while (!cp_seeds_.empty()) {
std::vector<ColPartition *> seeds_expanded;
for (int i = 0; i < cp_seeds_.size(); ++i) {
if (ExpandSeed(cp_seeds_[i])) {
for (auto &cp_seed : cp_seeds_) {
if (ExpandSeed(cp_seed)) {
// If this seed is expanded, then we add it into seeds_expanded. Note
// this seed has been removed from part_grid_ if it is expanded.
seeds_expanded.push_back(cp_seeds_[i]);
seeds_expanded.push_back(cp_seed);
}
}
// Add seeds_expanded back into part_grid_ and reset cp_seeds_.
for (int i = 0; i < seeds_expanded.size(); ++i) {
InsertPartAfterAbsorb(seeds_expanded[i]);
for (auto &i : seeds_expanded) {
InsertPartAfterAbsorb(i);
}
cp_seeds_ = seeds_expanded;
}
@ -423,9 +423,9 @@ void EquationDetect::MergePartsByLocation() {
// Merge parts_to_merge with part, and remove them from part_grid_.
part_grid_->RemoveBBox(part);
for (int i = 0; i < parts_to_merge.size(); ++i) {
ASSERT_HOST(parts_to_merge[i] != nullptr && parts_to_merge[i] != part);
part->Absorb(parts_to_merge[i], nullptr);
for (auto &i : parts_to_merge) {
ASSERT_HOST(i != nullptr && i != part);
part->Absorb(i, nullptr);
}
gsearch.RepositionIterator();
@ -437,8 +437,8 @@ void EquationDetect::MergePartsByLocation() {
}
// Re-insert parts_updated into part_grid_.
for (int i = 0; i < parts_updated.size(); ++i) {
InsertPartAfterAbsorb(parts_updated[i]);
for (auto &i : parts_updated) {
InsertPartAfterAbsorb(i);
}
}
}
@ -561,23 +561,23 @@ void EquationDetect::IdentifySeedParts() {
foreground_density_th = 0.8 * texts_foreground_density[texts_foreground_density.size() / 2];
}
for (int i = 0; i < seeds1.size(); ++i) {
const TBOX &box = seeds1[i]->bounding_box();
if (CheckSeedFgDensity(foreground_density_th, seeds1[i]) &&
!(IsLeftIndented(IsIndented(seeds1[i])) &&
for (auto &i : seeds1) {
const TBOX &box = i->bounding_box();
if (CheckSeedFgDensity(foreground_density_th, i) &&
!(IsLeftIndented(IsIndented(i)) &&
CountAlignment(indented_texts_left, box.left()) >= kLeftIndentAlignmentCountTh)) {
// Mark as PT_EQUATION type.
seeds1[i]->set_type(PT_EQUATION);
cp_seeds_.push_back(seeds1[i]);
i->set_type(PT_EQUATION);
cp_seeds_.push_back(i);
} else { // Mark as PT_INLINE_EQUATION type.
seeds1[i]->set_type(PT_INLINE_EQUATION);
i->set_type(PT_INLINE_EQUATION);
}
}
for (int i = 0; i < seeds2.size(); ++i) {
if (CheckForSeed2(indented_texts_left, foreground_density_th, seeds2[i])) {
seeds2[i]->set_type(PT_EQUATION);
cp_seeds_.push_back(seeds2[i]);
for (auto &i : seeds2) {
if (CheckForSeed2(indented_texts_left, foreground_density_th, i)) {
i->set_type(PT_EQUATION);
cp_seeds_.push_back(i);
}
}
}
@ -602,8 +602,8 @@ bool EquationDetect::CheckSeedFgDensity(const float density_th, ColPartition *pa
std::vector<TBOX> sub_boxes;
SplitCPHorLite(part, &sub_boxes);
float parts_passed = 0.0;
for (int i = 0; i < sub_boxes.size(); ++i) {
const float density = ComputeForegroundDensity(sub_boxes[i]);
for (auto &sub_boxe : sub_boxes) {
const float density = ComputeForegroundDensity(sub_boxe);
if (density < density_th) {
parts_passed++;
}
@ -777,8 +777,7 @@ void EquationDetect::IdentifyInlinePartsHorizontal() {
search.SetUniqueMode(true);
// The center x coordinate of the cp_super_bbox_.
const int cps_cx = cps_super_bbox_->left() + cps_super_bbox_->width() / 2;
for (int i = 0; i < cp_seeds_.size(); ++i) {
ColPartition *part = cp_seeds_[i];
for (auto part : cp_seeds_) {
const TBOX &part_box(part->bounding_box());
const int left_margin = part_box.left() - cps_super_bbox_->left(),
right_margin = cps_super_bbox_->right() - part_box.right();
@ -879,8 +878,7 @@ void EquationDetect::IdentifyInlinePartsVertical(const bool top_to_bottom,
}
std::vector<ColPartition *> new_seeds;
for (int i = 0; i < cp_seeds_.size(); ++i) {
ColPartition *part = cp_seeds_[i];
for (auto part : cp_seeds_) {
// If we sort cp_seeds_ from top to bottom, then for each cp_seeds_, we look
// for its top neighbors, so that if two/more inline regions are connected
// to each other, then we will identify the top one, and then use it to
@ -1057,14 +1055,13 @@ bool EquationDetect::ExpandSeed(ColPartition *seed) {
// from part_grid_ as its bounding box is going to expand. Then we add it
// back after it absorbs all parts_to_merge partitions.
part_grid_->RemoveBBox(seed);
for (int i = 0; i < parts_to_merge.size(); ++i) {
ColPartition *part = parts_to_merge[i];
for (auto part : parts_to_merge) {
if (part->type() == PT_EQUATION) {
// If part is in cp_seeds_, then we mark it as nullptr so that we won't
// process it again.
for (int j = 0; j < cp_seeds_.size(); ++j) {
if (part == cp_seeds_[j]) {
cp_seeds_[j] = nullptr;
for (auto &cp_seed : cp_seeds_) {
if (part == cp_seed) {
cp_seed = nullptr;
break;
}
}
@ -1199,15 +1196,15 @@ void EquationDetect::ExpandSeedVertical(const bool search_bottom, ColPartition *
// seed: ****************** | part: **********
// skipped: xxx | skipped: xxx
// part: ********** | seed: ***********
for (int i = 0; i < parts.size(); i++) {
const TBOX &part_box(parts[i]->bounding_box());
for (auto &part : parts) {
const TBOX &part_box(part->bounding_box());
if ((search_bottom && part_box.top() <= skipped_max_bottom) ||
(!search_bottom && part_box.bottom() >= skipped_min_top)) {
continue;
}
// Add parts[i] into parts_to_merge, and delete it from part_grid_.
parts_to_merge->push_back(parts[i]);
part_grid_->RemoveBBox(parts[i]);
parts_to_merge->push_back(part);
part_grid_->RemoveBBox(part);
}
}
@ -1272,24 +1269,24 @@ void EquationDetect::ProcessMathBlockSatelliteParts() {
}
// Iterate every text_parts and check if it is a math block satellite.
for (int i = 0; i < text_parts.size(); ++i) {
const TBOX &text_box(text_parts[i]->bounding_box());
for (auto &text_part : text_parts) {
const TBOX &text_box(text_part->bounding_box());
if (text_box.height() > med_height) {
continue;
}
std::vector<ColPartition *> math_blocks;
if (!IsMathBlockSatellite(text_parts[i], &math_blocks)) {
if (!IsMathBlockSatellite(text_part, &math_blocks)) {
continue;
}
// Found. merge text_parts[i] with math_blocks.
part_grid_->RemoveBBox(text_parts[i]);
text_parts[i]->set_type(PT_EQUATION);
for (int j = 0; j < math_blocks.size(); ++j) {
part_grid_->RemoveBBox(math_blocks[j]);
text_parts[i]->Absorb(math_blocks[j], nullptr);
part_grid_->RemoveBBox(text_part);
text_part->set_type(PT_EQUATION);
for (auto &math_block : math_blocks) {
part_grid_->RemoveBBox(math_block);
text_part->Absorb(math_block, nullptr);
}
InsertPartAfterAbsorb(text_parts[i]);
InsertPartAfterAbsorb(text_part);
}
}

View File

@ -38,13 +38,13 @@ struct BlobData {
void Tesseract::PrerecAllWordsPar(const std::vector<WordData> &words) {
// Prepare all the blobs.
std::vector<BlobData> blobs;
for (size_t w = 0; w < words.size(); ++w) {
if (words[w].word->ratings != nullptr && words[w].word->ratings->get(0, 0) == nullptr) {
for (int s = 0; s < words[w].lang_words.size(); ++s) {
for (const auto &w : words) {
if (w.word->ratings != nullptr && w.word->ratings->get(0, 0) == nullptr) {
for (int s = 0; s < w.lang_words.size(); ++s) {
Tesseract *sub = s < sub_langs_.size() ? sub_langs_[s] : this;
const WERD_RES &word = *words[w].lang_words[s];
const WERD_RES &word = *w.lang_words[s];
for (int b = 0; b < word.chopped_word->NumBlobs(); ++b) {
blobs.push_back(BlobData(b, sub, word));
blobs.emplace_back(b, sub, word);
}
}
}
@ -54,15 +54,13 @@ void Tesseract::PrerecAllWordsPar(const std::vector<WordData> &words) {
#ifdef _OPENMP
# pragma omp parallel for num_threads(10)
#endif // _OPENMP
for (size_t b = 0; b < blobs.size(); ++b) {
*blobs[b].choices =
blobs[b].tesseract->classify_blob(blobs[b].blob, "par", ScrollView::WHITE, nullptr);
for (auto &blob : blobs) {
*blob.choices = blob.tesseract->classify_blob(blob.blob, "par", ScrollView::WHITE, nullptr);
}
} else {
// TODO(AMD) parallelize this.
for (size_t b = 0; b < blobs.size(); ++b) {
*blobs[b].choices =
blobs[b].tesseract->classify_blob(blobs[b].blob, "par", ScrollView::WHITE, nullptr);
for (auto &blob : blobs) {
*blob.choices = blob.tesseract->classify_blob(blob.blob, "par", ScrollView::WHITE, nullptr);
}
}
}

View File

@ -97,8 +97,8 @@ static void PrintTable(const std::vector<std::vector<std::string>> &rows, const
int num_columns = row.size();
for (int c = 0; c < num_columns; c++) {
int num_unicodes = 0;
for (int i = 0; i < row[c].size(); i++) {
if ((row[c][i] & 0xC0) != 0x80)
for (char i : row[c]) {
if ((i & 0xC0) != 0x80)
num_unicodes++;
}
if (c >= max_col_widths.size()) {
@ -111,15 +111,15 @@ static void PrintTable(const std::vector<std::vector<std::string>> &rows, const
}
std::vector<std::string> col_width_patterns;
for (int c = 0; c < max_col_widths.size(); c++) {
col_width_patterns.push_back(std::string("%-") + std::to_string(max_col_widths[c]) + "s");
for (int max_col_width : max_col_widths) {
col_width_patterns.push_back(std::string("%-") + std::to_string(max_col_width) + "s");
}
for (int r = 0; r < rows.size(); r++) {
for (int c = 0; c < rows[r].size(); c++) {
for (const auto &row : rows) {
for (int c = 0; c < row.size(); c++) {
if (c > 0)
tprintf("%s", colsep);
tprintf(col_width_patterns[c].c_str(), rows[r][c].c_str());
tprintf(col_width_patterns[c].c_str(), row[c].c_str());
}
tprintf("\n");
}
@ -135,7 +135,7 @@ static std::string RtlEmbed(const std::string &word, bool rtlify) {
static void PrintDetectorState(const ParagraphTheory &theory,
const std::vector<RowScratchRegisters> &rows) {
std::vector<std::vector<std::string>> output;
output.push_back(std::vector<std::string>());
output.emplace_back();
output.back().push_back("#row");
output.back().push_back("space");
output.back().push_back("..");
@ -145,12 +145,12 @@ static void PrintDetectorState(const ParagraphTheory &theory,
output.back().push_back("text");
for (int i = 0; i < rows.size(); i++) {
output.push_back(std::vector<std::string>());
output.emplace_back();
std::vector<std::string> &row = output.back();
const RowInfo &ri = *rows[i].ri_;
row.push_back(std::to_string(i));
row.push_back(std::to_string(ri.average_interword_space));
row.push_back(ri.has_leaders ? ".." : " ");
row.emplace_back(ri.has_leaders ? ".." : " ");
row.push_back(RtlEmbed(ri.lword_text, !ri.ltr) + "[" + std::to_string(ri.lword_box.width()) +
(ri.lword_likely_starts_idea ? "S" : "s") +
(ri.lword_likely_ends_idea ? "E" : "e") +
@ -491,30 +491,30 @@ void RightWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd,
// =============== Implementation of RowScratchRegisters =====================
/* static */
void RowScratchRegisters::AppendDebugHeaderFields(std::vector<std::string> &header) {
header.push_back("[lmarg,lind;rind,rmarg]");
header.push_back("model");
header.emplace_back("[lmarg,lind;rind,rmarg]");
header.emplace_back("model");
}
void RowScratchRegisters::AppendDebugInfo(const ParagraphTheory &theory,
std::vector<std::string> &dbg) const {
char s[30];
snprintf(s, sizeof(s), "[%3d,%3d;%3d,%3d]", lmargin_, lindent_, rindent_, rmargin_);
dbg.push_back(s);
dbg.emplace_back(s);
std::string model_string;
model_string += static_cast<char>(GetLineType());
model_string += ":";
int model_numbers = 0;
for (int h = 0; h < hypotheses_.size(); h++) {
if (hypotheses_[h].model == nullptr)
for (const auto &hypothese : hypotheses_) {
if (hypothese.model == nullptr)
continue;
if (model_numbers > 0)
model_string += ",";
if (StrongModel(hypotheses_[h].model)) {
model_string += std::to_string(1 + theory.IndexOf(hypotheses_[h].model));
} else if (hypotheses_[h].model == kCrownLeft) {
if (StrongModel(hypothese.model)) {
model_string += std::to_string(1 + theory.IndexOf(hypothese.model));
} else if (hypothese.model == kCrownLeft) {
model_string += "CrL";
} else if (hypotheses_[h].model == kCrownRight) {
} else if (hypothese.model == kCrownRight) {
model_string += "CrR";
}
model_numbers++;
@ -538,8 +538,8 @@ LineType RowScratchRegisters::GetLineType() const {
return LT_UNKNOWN;
bool has_start = false;
bool has_body = false;
for (int i = 0; i < hypotheses_.size(); i++) {
switch (hypotheses_[i].ty) {
for (const auto &hypothese : hypotheses_) {
switch (hypothese.ty) {
case LT_START:
has_start = true;
break;
@ -547,7 +547,7 @@ LineType RowScratchRegisters::GetLineType() const {
has_body = true;
break;
default:
tprintf("Encountered bad value in hypothesis list: %c\n", hypotheses_[i].ty);
tprintf("Encountered bad value in hypothesis list: %c\n", hypothese.ty);
break;
}
}
@ -561,10 +561,10 @@ LineType RowScratchRegisters::GetLineType(const ParagraphModel *model) const {
return LT_UNKNOWN;
bool has_start = false;
bool has_body = false;
for (int i = 0; i < hypotheses_.size(); i++) {
if (hypotheses_[i].model != model)
for (const auto &hypothese : hypotheses_) {
if (hypothese.model != model)
continue;
switch (hypotheses_[i].ty) {
switch (hypothese.ty) {
case LT_START:
has_start = true;
break;
@ -572,7 +572,7 @@ LineType RowScratchRegisters::GetLineType(const ParagraphModel *model) const {
has_body = true;
break;
default:
tprintf("Encountered bad value in hypothesis list: %c\n", hypotheses_[i].ty);
tprintf("Encountered bad value in hypothesis list: %c\n", hypothese.ty);
break;
}
}
@ -618,23 +618,23 @@ void RowScratchRegisters::AddBodyLine(const ParagraphModel *model) {
}
void RowScratchRegisters::StartHypotheses(SetOfModels *models) const {
for (int h = 0; h < hypotheses_.size(); h++) {
if (hypotheses_[h].ty == LT_START && StrongModel(hypotheses_[h].model))
push_back_new(*models, hypotheses_[h].model);
for (const auto &hypothese : hypotheses_) {
if (hypothese.ty == LT_START && StrongModel(hypothese.model))
push_back_new(*models, hypothese.model);
}
}
void RowScratchRegisters::StrongHypotheses(SetOfModels *models) const {
for (int h = 0; h < hypotheses_.size(); h++) {
if (StrongModel(hypotheses_[h].model))
push_back_new(*models, hypotheses_[h].model);
for (const auto &hypothese : hypotheses_) {
if (StrongModel(hypothese.model))
push_back_new(*models, hypothese.model);
}
}
void RowScratchRegisters::NonNullHypotheses(SetOfModels *models) const {
for (int h = 0; h < hypotheses_.size(); h++) {
if (hypotheses_[h].model != nullptr)
push_back_new(*models, hypotheses_[h].model);
for (const auto &hypothese : hypotheses_) {
if (hypothese.model != nullptr)
push_back_new(*models, hypothese.model);
}
}
@ -1344,12 +1344,12 @@ void ParagraphModelSmearer::CalculateOpenModels(int row_start, int row_end) {
// Which models survive the transition from row to row + 1?
SetOfModels still_open;
for (int m = 0; m < opened.size(); m++) {
if (ValidFirstLine(rows_, row, opened[m]) || ValidBodyLine(rows_, row, opened[m])) {
for (auto &m : opened) {
if (ValidFirstLine(rows_, row, m) || ValidBodyLine(rows_, row, m)) {
// This is basic filtering; we check likely paragraph starty-ness down
// below in Smear() -- you know, whether the first word would have fit
// and such.
push_back_new(still_open, opened[m]);
push_back_new(still_open, m);
}
}
OpenModels(row + 1) = still_open;
@ -1375,8 +1375,8 @@ void ParagraphModelSmearer::Smear() {
// "first" word in a row would fit at the "end" of the previous row.
bool left_align_open = false;
bool right_align_open = false;
for (int m = 0; m < OpenModels(i).size(); m++) {
switch (OpenModels(i)[m]->justification()) {
for (auto &m : OpenModels(i)) {
switch (m->justification()) {
case JUSTIFICATION_LEFT:
left_align_open = true;
break;
@ -1423,8 +1423,7 @@ void ParagraphModelSmearer::Smear() {
} else {
theory_->NonCenteredModels(&last_line_models);
}
for (int m = 0; m < last_line_models.size(); m++) {
const ParagraphModel *model = last_line_models[m];
for (auto model : last_line_models) {
if (ValidBodyLine(rows_, i, model))
row.AddBodyLine(model);
}
@ -1438,9 +1437,9 @@ void ParagraphModelSmearer::Smear() {
(row.GetLineType() == LT_START && !row.UniqueStartHypothesis())) {
SetOfModels all_models;
theory_->NonCenteredModels(&all_models);
for (int m = 0; m < all_models.size(); m++) {
if (ValidFirstLine(rows_, i, all_models[m])) {
row.AddStartLine(all_models[m]);
for (auto &all_model : all_models) {
if (ValidFirstLine(rows_, i, all_model)) {
row.AddStartLine(all_model);
}
}
}
@ -1460,8 +1459,8 @@ void ParagraphModelSmearer::Smear() {
static void DiscardUnusedModels(const std::vector<RowScratchRegisters> &rows,
ParagraphTheory *theory) {
SetOfModels used_models;
for (int i = 0; i < rows.size(); i++) {
rows[i].StrongHypotheses(&used_models);
for (const auto &row : rows) {
row.StrongHypotheses(&used_models);
}
theory->DiscardUnusedModels(used_models);
}
@ -2102,14 +2101,14 @@ static bool RowIsStranded(const std::vector<RowScratchRegisters> &rows, int row)
SetOfModels row_models;
rows[row].StrongHypotheses(&row_models);
for (int m = 0; m < row_models.size(); m++) {
for (auto &row_model : row_models) {
bool all_starts = rows[row].GetLineType();
int run_length = 1;
bool continues = true;
for (int i = row - 1; i >= 0 && continues; i--) {
SetOfModels models;
rows[i].NonNullHypotheses(&models);
switch (rows[i].GetLineType(row_models[m])) {
switch (rows[i].GetLineType(row_model)) {
case LT_START:
run_length++;
break;
@ -2127,7 +2126,7 @@ static bool RowIsStranded(const std::vector<RowScratchRegisters> &rows, int row)
for (int i = row + 1; i < rows.size() && continues; i++) {
SetOfModels models;
rows[i].NonNullHypotheses(&models);
switch (rows[i].GetLineType(row_models[m])) {
switch (rows[i].GetLineType(row_model)) {
case LT_START:
run_length++;
break;
@ -2195,8 +2194,8 @@ static void LeftoverSegments(const std::vector<RowScratchRegisters> &rows,
}
}
// Convert inclusive intervals to half-open intervals.
for (int i = 0; i < to_fix->size(); i++) {
(*to_fix)[i].end = (*to_fix)[i].end + 1;
for (auto &i : *to_fix) {
i.end = i.end + 1;
}
}
@ -2488,7 +2487,7 @@ void DetectParagraphs(int debug_level, bool after_text_recognition,
if (!row.PageResIt()->row())
continue; // empty row.
row.PageResIt()->row()->row->set_para(nullptr);
row_infos.push_back(RowInfo());
row_infos.emplace_back();
RowInfo &ri = row_infos.back();
InitializeRowInfo(after_text_recognition, row, &ri);
} while (!row.IsAtFinalElement(RIL_BLOCK, RIL_TEXTLINE) && row.Next(RIL_TEXTLINE));

View File

@ -76,14 +76,10 @@ inline bool StrongModel(const ParagraphModel *model) {
struct LineHypothesis {
LineHypothesis() : ty(LT_UNKNOWN), model(nullptr) {}
LineHypothesis(LineType line_type, const ParagraphModel *m) : ty(line_type), model(m) {}
LineHypothesis(const LineHypothesis &other) : ty(other.ty), model(other.model) {}
LineHypothesis(const LineHypothesis &other) = default;
// Copy assignment operator.
LineHypothesis &operator=(const LineHypothesis &other) {
ty = other.ty;
model = other.model;
return *this;
}
LineHypothesis &operator=(const LineHypothesis &other) = default;
bool operator==(const LineHypothesis &other) const {
return ty == other.ty && model == other.model;

View File

@ -912,14 +912,14 @@ void Tesseract::blob_feature_display(PAGE_RES *page_res, const TBOX &selection_b
// Display baseline features.
ScrollView *bl_win = CreateFeatureSpaceWindow("BL Features", 512, 0);
ClearFeatureSpaceWindow(baseline, bl_win);
for (int f = 0; f < bl_features.size(); ++f)
RenderIntFeature(bl_win, &bl_features[f], ScrollView::GREEN);
for (auto &bl_feature : bl_features)
RenderIntFeature(bl_win, &bl_feature, ScrollView::GREEN);
bl_win->Update();
// Display cn features.
ScrollView *cn_win = CreateFeatureSpaceWindow("CN Features", 512, 0);
ClearFeatureSpaceWindow(character, cn_win);
for (int f = 0; f < cn_features.size(); ++f)
RenderIntFeature(cn_win, &cn_features[f], ScrollView::GREEN);
for (auto &cn_feature : cn_features)
RenderIntFeature(cn_win, &cn_feature, ScrollView::GREEN);
cn_win->Update();
it->DeleteCurrentWord();

View File

@ -36,9 +36,9 @@ const int16_t kMaxBoxEdgeDiff = 2;
FILE *Tesseract::init_recog_training(const char *filename) {
if (tessedit_ambigs_training) {
tessedit_tess_adaption_mode.set_value(0); // turn off adaption
tessedit_enable_doc_dict.set_value(0); // turn off document dictionary
tessedit_enable_doc_dict.set_value(false); // turn off document dictionary
// Explore all segmentations.
getDict().stopper_no_acceptable_choices.set_value(1);
getDict().stopper_no_acceptable_choices.set_value(true);
}
std::string output_fname = filename;

View File

@ -221,8 +221,8 @@ void ResultIterator::CalculateBlobOrder(std::vector<int> *blob_indices) const {
}
static void PrintScriptDirs(const std::vector<StrongScriptDirection> &dirs) {
for (int i = 0; i < dirs.size(); i++) {
switch (dirs[i]) {
for (auto dir : dirs) {
switch (dir) {
case DIR_NEUTRAL:
tprintf("N ");
break;
@ -669,8 +669,8 @@ void ResultIterator::AppendUTF8WordText(std::string *text) const {
std::vector<int> blob_order;
CalculateBlobOrder(&blob_order);
for (int i = 0; i < blob_order.size(); i++) {
*text += it_->word()->BestUTF8(blob_order[i], false);
for (int i : blob_order) {
*text += it_->word()->BestUTF8(i, false);
}
AppendSuffixMarks(text);
}
@ -689,8 +689,8 @@ void ResultIterator::IterateAndAppendUTF8TextlineText(std::string *text) {
PrintScriptDirs(dirs);
tprintf("Logical textline order [%p/P=%s]: ", it_->row(),
current_paragraph_is_ltr_ ? "ltr" : "rtl");
for (int i = 0; i < textline_order.size(); i++) {
tprintf("%d ", textline_order[i]);
for (int i : textline_order) {
tprintf("%d ", i);
}
tprintf("\n");
}

View File

@ -36,8 +36,8 @@ void Tesseract::tess_segment_pass_n(int pass_n, WERD_RES *word) {
if (word->word->flag(W_DONT_CHOP)) {
saved_enable_assoc = wordrec_enable_assoc;
saved_chop_enable = chop_enable;
wordrec_enable_assoc.set_value(0);
chop_enable.set_value(0);
wordrec_enable_assoc.set_value(false);
chop_enable.set_value(false);
}
if (pass_n == 1)
set_pass1();

View File

@ -230,8 +230,8 @@ bool Tesseract::init_tesseract_lang_data(const std::string &arg0, const std::str
// Helper returns true if the given string is in the vector of strings.
static bool IsStrInList(const std::string &str, const std::vector<std::string> &str_list) {
for (int i = 0; i < str_list.size(); ++i) {
if (str_list[i] == str)
for (const auto &i : str_list) {
if (i == str)
return true;
}
return false;
@ -341,15 +341,14 @@ int Tesseract::init_tesseract(const std::string &arg0, const std::string &textba
// tessedit_use_primary_params_model is set,
// otherwise use default language model weights.
if (tessedit_use_primary_params_model) {
for (int s = 0; s < sub_langs_.size(); ++s) {
sub_langs_[s]->language_model_->getParamsModel().Copy(
this->language_model_->getParamsModel());
for (auto &sub_lang : sub_langs_) {
sub_lang->language_model_->getParamsModel().Copy(this->language_model_->getParamsModel());
}
tprintf("Using params model of the primary language\n");
} else {
this->language_model_->getParamsModel().Clear();
for (int s = 0; s < sub_langs_.size(); ++s) {
sub_langs_[s]->language_model_->getParamsModel().Clear();
for (auto &sub_lang : sub_langs_) {
sub_lang->language_model_->getParamsModel().Clear();
}
}
}
@ -424,13 +423,13 @@ void Tesseract::SetupUniversalFontIds() {
// Create the universal ID table.
CollectFonts(get_fontinfo_table(), &all_fonts);
for (int i = 0; i < sub_langs_.size(); ++i) {
CollectFonts(sub_langs_[i]->get_fontinfo_table(), &all_fonts);
for (auto &sub_lang : sub_langs_) {
CollectFonts(sub_lang->get_fontinfo_table(), &all_fonts);
}
// Assign ids from the table to each font table.
AssignIds(all_fonts, &get_fontinfo_table());
for (int i = 0; i < sub_langs_.size(); ++i) {
AssignIds(all_fonts, &sub_langs_[i]->get_fontinfo_table());
for (auto &sub_lang : sub_langs_) {
AssignIds(all_fonts, &sub_lang->get_fontinfo_table());
}
font_table_size_ = all_fonts.size();
}

View File

@ -450,8 +450,8 @@ void Tesseract::Clear() {
reskew_ = FCOORD(1.0f, 0.0f);
splitter_.Clear();
scaled_factor_ = -1;
for (int i = 0; i < sub_langs_.size(); ++i)
sub_langs_[i]->Clear();
for (auto &sub_lang : sub_langs_)
sub_lang->Clear();
}
#ifndef DISABLED_LEGACY_ENGINE
@ -464,8 +464,8 @@ void Tesseract::SetEquationDetect(EquationDetect *detector) {
// Clear all memory of adaption for this and all subclassifiers.
void Tesseract::ResetAdaptiveClassifier() {
ResetAdaptiveClassifierInternal();
for (int i = 0; i < sub_langs_.size(); ++i) {
sub_langs_[i]->ResetAdaptiveClassifierInternal();
for (auto &sub_lang : sub_langs_) {
sub_lang->ResetAdaptiveClassifierInternal();
}
}
@ -474,8 +474,8 @@ void Tesseract::ResetAdaptiveClassifier() {
// Clear the document dictionary for this and all subclassifiers.
void Tesseract::ResetDocumentDictionary() {
getDict().ResetDocumentDictionary();
for (int i = 0; i < sub_langs_.size(); ++i) {
sub_langs_[i]->getDict().ResetDocumentDictionary();
for (auto &sub_lang : sub_langs_) {
sub_lang->getDict().ResetDocumentDictionary();
}
}
@ -491,12 +491,12 @@ void Tesseract::SetBlackAndWhitelist() {
tessedit_char_unblacklist.c_str());
}
// Black and white lists should apply to all loaded classifiers.
for (int i = 0; i < sub_langs_.size(); ++i) {
sub_langs_[i]->unicharset.set_black_and_whitelist(tessedit_char_blacklist.c_str(),
tessedit_char_whitelist.c_str(),
tessedit_char_unblacklist.c_str());
if (sub_langs_[i]->lstm_recognizer_) {
UNICHARSET &lstm_unicharset = sub_langs_[i]->lstm_recognizer_->GetUnicharset();
for (auto &sub_lang : sub_langs_) {
sub_lang->unicharset.set_black_and_whitelist(tessedit_char_blacklist.c_str(),
tessedit_char_whitelist.c_str(),
tessedit_char_unblacklist.c_str());
if (sub_lang->lstm_recognizer_) {
UNICHARSET &lstm_unicharset = sub_lang->lstm_recognizer_->GetUnicharset();
lstm_unicharset.set_black_and_whitelist(tessedit_char_blacklist.c_str(),
tessedit_char_whitelist.c_str(),
tessedit_char_unblacklist.c_str());
@ -511,13 +511,13 @@ void Tesseract::PrepareForPageseg() {
// Find the max splitter strategy over all langs.
auto max_pageseg_strategy = static_cast<ShiroRekhaSplitter::SplitStrategy>(
static_cast<int32_t>(pageseg_devanagari_split_strategy));
for (int i = 0; i < sub_langs_.size(); ++i) {
for (auto &sub_lang : sub_langs_) {
auto pageseg_strategy = static_cast<ShiroRekhaSplitter::SplitStrategy>(
static_cast<int32_t>(sub_langs_[i]->pageseg_devanagari_split_strategy));
static_cast<int32_t>(sub_lang->pageseg_devanagari_split_strategy));
if (pageseg_strategy > max_pageseg_strategy)
max_pageseg_strategy = pageseg_strategy;
pixDestroy(&sub_langs_[i]->pix_binary_);
sub_langs_[i]->pix_binary_ = pixClone(pix_binary());
pixDestroy(&sub_lang->pix_binary_);
sub_lang->pix_binary_ = pixClone(pix_binary());
}
// Perform shiro-rekha (top-line) splitting and replace the current image by
// the newly split image.
@ -539,9 +539,9 @@ void Tesseract::PrepareForTessOCR(BLOCK_LIST *block_list, Tesseract *osd_tess, O
// Find the max splitter strategy over all langs.
auto max_ocr_strategy = static_cast<ShiroRekhaSplitter::SplitStrategy>(
static_cast<int32_t>(ocr_devanagari_split_strategy));
for (int i = 0; i < sub_langs_.size(); ++i) {
for (auto &sub_lang : sub_langs_) {
auto ocr_strategy = static_cast<ShiroRekhaSplitter::SplitStrategy>(
static_cast<int32_t>(sub_langs_[i]->ocr_devanagari_split_strategy));
static_cast<int32_t>(sub_lang->ocr_devanagari_split_strategy));
if (ocr_strategy > max_ocr_strategy)
max_ocr_strategy = ocr_strategy;
}

View File

@ -289,7 +289,7 @@ struct BlamerBundle {
private:
// Copy assignment operator (currently unused, therefore private).
BlamerBundle &operator=(const BlamerBundle &other);
BlamerBundle &operator=(const BlamerBundle &other) = delete;
void SetBlame(IncorrectResultReason irr, const std::string &msg, const WERD_CHOICE *choice,
bool debug) {
incorrect_result_reason_ = irr;

View File

@ -784,8 +784,7 @@ void TWERD::BLNormalize(const BLOCK *block, const ROW *row, Pix *pix, bool inver
} else {
input_y_offset = row->base_line(word_middle) + baseline_shift;
}
for (int b = 0; b < blobs.size(); ++b) {
TBLOB *blob = blobs[b];
for (auto blob : blobs) {
TBOX blob_box = blob->bounding_box();
float mid_x = (blob_box.left() + blob_box.right()) / 2.0f;
float baseline = input_y_offset;
@ -817,8 +816,8 @@ void TWERD::BLNormalize(const BLOCK *block, const ROW *row, Pix *pix, bool inver
void TWERD::CopyFrom(const TWERD &src) {
Clear();
latin_script = src.latin_script;
for (int b = 0; b < src.blobs.size(); ++b) {
auto *new_blob = new TBLOB(*src.blobs[b]);
for (auto blob : src.blobs) {
auto *new_blob = new TBLOB(*blob);
blobs.push_back(new_blob);
}
}
@ -833,15 +832,15 @@ void TWERD::Clear() {
// Recomputes the bounding boxes of the blobs.
void TWERD::ComputeBoundingBoxes() {
for (int b = 0; b < blobs.size(); ++b) {
blobs[b]->ComputeBoundingBoxes();
for (auto &blob : blobs) {
blob->ComputeBoundingBoxes();
}
}
TBOX TWERD::bounding_box() const {
TBOX result;
for (int b = 0; b < blobs.size(); ++b) {
TBOX box = blobs[b]->bounding_box();
for (auto blob : blobs) {
TBOX box = blob->bounding_box();
result += box;
}
return result;
@ -879,8 +878,8 @@ void TWERD::MergeBlobs(int start, int end) {
#ifndef GRAPHICS_DISABLED
void TWERD::plot(ScrollView *window) {
ScrollView::Color color = WERD::NextColor(ScrollView::BLACK);
for (int b = 0; b < blobs.size(); ++b) {
blobs[b]->plot(window, color, ScrollView::BROWN);
for (auto &blob : blobs) {
blob->plot(window, color, ScrollView::BROWN);
color = WERD::NextColor(color);
}
}

View File

@ -94,11 +94,11 @@ bool ReadMemBoxes(int target_page, bool skip_blanks, const char *box_data, bool
if (lines.empty())
return false;
int num_boxes = 0;
for (int i = 0; i < lines.size(); ++i) {
for (auto &line : lines) {
int page = 0;
std::string utf8_str;
TBOX box;
if (!ParseBoxFileStr(lines[i].c_str(), &page, utf8_str, &box)) {
if (!ParseBoxFileStr(line.c_str(), &page, utf8_str, &box)) {
if (continue_on_failure)
continue;
else

View File

@ -243,7 +243,7 @@ void C_OUTLINE::FakeOutline(const TBOX &box, C_OUTLINE_LIST *outlines) {
// as there is no outline, just a bounding box, but it works nicely.
CRACKEDGE start;
start.pos = box.topleft();
C_OUTLINE *outline = new C_OUTLINE(&start, box.topleft(), box.botright(), 0);
auto *outline = new C_OUTLINE(&start, box.topleft(), box.botright(), 0);
ol_it.add_to_end(outline);
}

View File

@ -48,14 +48,14 @@ void DetLineFit::Clear() {
// Add a new point. Takes a copy - the pt doesn't need to stay in scope.
void DetLineFit::Add(const ICOORD &pt) {
pts_.push_back(PointWidth(pt, 0));
pts_.emplace_back(pt, 0);
}
// Associates a half-width with the given point if a point overlaps the
// previous point by more than half the width, and its distance is further
// than the previous point, then the more distant point is ignored in the
// distance calculation. Useful for ignoring i dots and other diacritics.
void DetLineFit::Add(const ICOORD &pt, int halfwidth) {
pts_.push_back(PointWidth(pt, halfwidth));
pts_.emplace_back(pt, halfwidth);
}
// Fits a line to the points, ignoring the skip_first initial points and the
@ -150,8 +150,8 @@ double DetLineFit::ConstrainedFit(const FCOORD &direction, double min_dist, doub
}
// Center distances on the fitted point.
double dist_origin = direction * *line_pt;
for (int i = 0; i < distances_.size(); ++i) {
distances_[i].key() -= dist_origin;
for (auto &distance : distances_) {
distance.key() -= dist_origin;
}
return sqrt(EvaluateLineFit());
}
@ -268,7 +268,7 @@ void DetLineFit::ComputeDistances(const ICOORD &start, const ICOORD &end) {
separation < line_length * pts_[i - 1].halfwidth)
continue;
}
distances_.push_back(DistPointPair(dist, pts_[i].pt));
distances_.emplace_back(dist, pts_[i].pt);
prev_abs_dist = abs_dist;
prev_dot = dot;
}
@ -282,12 +282,12 @@ void DetLineFit::ComputeConstrainedDistances(const FCOORD &direction, double min
distances_.clear();
square_length_ = direction.sqlength();
// Compute the distance of each point from the line.
for (int i = 0; i < pts_.size(); ++i) {
FCOORD pt_vector = pts_[i].pt;
for (auto &pt : pts_) {
FCOORD pt_vector = pt.pt;
// Compute |line_vector||pt_vector|sin(angle between)
double dist = direction * pt_vector;
if (min_dist <= dist && dist <= max_dist)
distances_.push_back(DistPointPair(dist, pts_[i].pt));
distances_.emplace_back(dist, pt.pt);
}
}

View File

@ -45,7 +45,7 @@ FontInfoTable::FontInfoTable() {
set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
}
FontInfoTable::~FontInfoTable() {}
FontInfoTable::~FontInfoTable() = default;
// Writes to the given file. Returns false in case of error.
bool FontInfoTable::Serialize(FILE *fp) const {
@ -63,8 +63,8 @@ bool FontInfoTable::DeSerialize(TFile *fp) {
bool FontInfoTable::SetContainsFontProperties(int font_id,
const std::vector<ScoredFont> &font_set) const {
uint32_t properties = at(font_id).properties;
for (int f = 0; f < font_set.size(); ++f) {
if (at(font_set[f].fontinfo_id).properties == properties)
for (auto f : font_set) {
if (at(f.fontinfo_id).properties == properties)
return true;
}
return false;

View File

@ -73,7 +73,7 @@ ImageData *ImageData::Build(const char *name, int page_number, const char *lang,
}
image_data->transcription_ = truth_text;
// If we have no boxes, the transcription is in the 0th box_texts_.
image_data->box_texts_.push_back(truth_text);
image_data->box_texts_.emplace_back(truth_text);
// We will create a box for the whole image on PreScale, to save unpacking
// the image now.
} else if (truth_text != nullptr && truth_text[0] != '\0' &&
@ -220,8 +220,7 @@ Pix *ImageData::PreScale(int target_height, int max_height, float *scale_factor,
if (boxes != nullptr) {
// Get the boxes.
boxes->clear();
for (int b = 0; b < boxes_.size(); ++b) {
TBOX box = boxes_[b];
for (auto box : boxes_) {
box.scale(im_factor);
boxes->push_back(box);
}
@ -572,8 +571,7 @@ bool DocumentCache::LoadDocuments(const std::vector<std::string> &filenames,
// determines which DocumentDatas are held entirely in memory.
if (cache_strategy_ == CS_ROUND_ROBIN)
fair_share_memory = max_memory_ / filenames.size();
for (int arg = 0; arg < filenames.size(); ++arg) {
std::string filename = filenames[arg];
for (auto filename : filenames) {
auto *document = new DocumentData(filename);
document->SetDocument(filename.c_str(), fair_share_memory, reader);
AddToCache(document);

View File

@ -652,7 +652,7 @@ struct MATRIX_COORD {
// Default constructor required by GenericHeap.
MATRIX_COORD() : col(0), row(0) {}
MATRIX_COORD(int c, int r) : col(c), row(r) {}
~MATRIX_COORD() {}
~MATRIX_COORD() = default;
bool Valid(const MATRIX &m) const {
return 0 <= col && col < m.dimension() && col <= row && row < col + m.bandwidth() &&

View File

@ -147,7 +147,7 @@ public:
private:
// Copy constructor (currently unused, therefore private).
ROW(const ROW &source);
ROW(const ROW &source) = delete;
int32_t kerning; // inter char gap
int32_t spacing; // inter word gap

View File

@ -832,7 +832,7 @@ void WERD_RES::CloneChoppedToRebuild() {
correct_text.reserve(word_len);
for (int i = 0; i < word_len; ++i) {
best_state.push_back(1);
correct_text.push_back(std::string(""));
correct_text.emplace_back("");
}
}
@ -917,7 +917,7 @@ void WERD_RES::BestChoiceToCorrectText() {
for (int i = 0; i < best_choice->length(); ++i) {
UNICHAR_ID choice_id = best_choice->unichar_id(i);
const char *blob_choice = uch_set->id_to_unichar(choice_id);
correct_text.push_back(std::string(blob_choice));
correct_text.emplace_back(blob_choice);
}
}
@ -1215,8 +1215,7 @@ WERD_RES *PAGE_RES_IT::InsertSimpleCloneWord(const WERD_RES &clone_res, WERD *ne
static void ComputeBlobEnds(const WERD_RES &word, const TBOX &clip_box,
C_BLOB_LIST *next_word_blobs, std::vector<int> *blob_ends) {
C_BLOB_IT blob_it(word.word->cblob_list());
for (int i = 0; i < word.best_state.size(); ++i) {
int length = word.best_state[i];
for (int length : word.best_state) {
// Get the bounding box of the fake blobs
TBOX blob_box = blob_it.data()->bounding_box();
blob_it.forward();

View File

@ -134,7 +134,7 @@ public:
// Starts a new hypothesis list.
// Should be called at the beginning of a new run of the segmentation search.
void StartHypothesisList() {
hyp_list_vec.push_back(ParamsTrainingHypothesisList());
hyp_list_vec.emplace_back();
}
// Adds a new ParamsTrainingHypothesis to the current hypothesis list
// and returns the reference to the newly added entry.

View File

@ -264,8 +264,7 @@ void WERD_CHOICE::init(const char *src_string, const char *src_lengths, float sr
/**
* WERD_CHOICE::~WERD_CHOICE
*/
WERD_CHOICE::~WERD_CHOICE() {
}
WERD_CHOICE::~WERD_CHOICE() = default;
const char *WERD_CHOICE::permuter_name() const {
return kPermuterTypeNames[permuter_];

View File

@ -18,6 +18,8 @@
#include "rejctmap.h"
#include <memory>
#include "params.h"
namespace tesseract {
@ -219,7 +221,7 @@ REJMAP &REJMAP::operator=(const REJMAP &source) {
}
void REJMAP::initialise(int16_t length) {
ptr.reset(new REJ[length]);
ptr = std::make_unique<REJ[]>(length);
len = length;
}

View File

@ -124,12 +124,8 @@ public:
flags2 = source.flags2;
}
REJ &operator=( // assign REJ
const REJ &source) { // from this
flags1 = source.flags1;
flags2 = source.flags2;
return *this;
}
REJ &operator=( // assign REJ
const REJ &source) = default;
bool flag(REJ_FLAGS rej_flag) {
if (rej_flag < 16)

View File

@ -132,8 +132,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambi
ambigs_for_adaption_[test_unichar_ids[i]] = new UnicharIdVector();
}
adaption_ambigs_entry = ambigs_for_adaption_[test_unichar_ids[i]];
for (int r = 0; r < encoding.size(); ++r) {
UNICHAR_ID id_to_insert = encoding[r];
for (int id_to_insert : encoding) {
ASSERT_HOST(id_to_insert != INVALID_UNICHAR_ID);
// Add the new unichar id to adaption_ambigs_entry (only if the
// vector does not already contain it) keeping it in sorted order.

View File

@ -245,7 +245,7 @@ public:
private:
// Don't use the following constructor.
ELIST2_ITERATOR();
ELIST2_ITERATOR() = delete;
};
/***********************************************************************

View File

@ -111,9 +111,9 @@ void IndexMapBiDi::SetMap(int sparse_index, bool mapped) {
// in the forward map to the compact space.
void IndexMapBiDi::Setup() {
int compact_size = 0;
for (int i = 0; i < sparse_map_.size(); ++i) {
if (sparse_map_[i] >= 0) {
sparse_map_[i] = compact_size++;
for (int &i : sparse_map_) {
if (i >= 0) {
i = compact_size++;
}
}
compact_map_.clear();
@ -171,9 +171,9 @@ bool IndexMapBiDi::Merge(int compact_index1, int compact_index2) {
void IndexMapBiDi::CompleteMerges() {
// Ensure each sparse_map_entry contains a master compact_map_ index.
int compact_size = 0;
for (int i = 0; i < sparse_map_.size(); ++i) {
int compact_index = MasterCompactIndex(sparse_map_[i]);
sparse_map_[i] = compact_index;
for (int &i : sparse_map_) {
int compact_index = MasterCompactIndex(i);
i = compact_index;
if (compact_index >= compact_size)
compact_size = compact_index + 1;
}
@ -198,9 +198,9 @@ void IndexMapBiDi::CompleteMerges() {
}
compact_map_.resize(compact_size);
// Now modify the entries in the sparse map to point to the new locations.
for (int i = 0; i < sparse_map_.size(); ++i) {
if (sparse_map_[i] >= 0) {
sparse_map_[i] = tmp_compact_map[sparse_map_[i]];
for (int &i : sparse_map_) {
if (i >= 0) {
i = tmp_compact_map[i];
}
}
}

View File

@ -166,21 +166,21 @@ void ParamUtils::PrintParams(FILE *fp, const ParamsVectors *member_params) {
stream.imbue(std::locale::classic());
for (int v = 0; v < num_iterations; ++v) {
const ParamsVectors *vec = (v == 0) ? GlobalParams() : member_params;
for (int i = 0; i < vec->int_params.size(); ++i) {
stream << vec->int_params[i]->name_str() << '\t' << (int32_t)(*vec->int_params[i]) << '\t'
<< vec->int_params[i]->info_str() << '\n';
for (auto int_param : vec->int_params) {
stream << int_param->name_str() << '\t' << (int32_t)(*int_param) << '\t'
<< int_param->info_str() << '\n';
}
for (int i = 0; i < vec->bool_params.size(); ++i) {
stream << vec->bool_params[i]->name_str() << '\t' << bool(*vec->bool_params[i]) << '\t'
<< vec->bool_params[i]->info_str() << '\n';
for (auto bool_param : vec->bool_params) {
stream << bool_param->name_str() << '\t' << bool(*bool_param) << '\t'
<< bool_param->info_str() << '\n';
}
for (int i = 0; i < vec->string_params.size(); ++i) {
stream << vec->string_params[i]->name_str() << '\t' << vec->string_params[i]->c_str() << '\t'
<< vec->string_params[i]->info_str() << '\n';
for (auto string_param : vec->string_params) {
stream << string_param->name_str() << '\t' << string_param->c_str() << '\t'
<< string_param->info_str() << '\n';
}
for (int i = 0; i < vec->double_params.size(); ++i) {
stream << vec->double_params[i]->name_str() << '\t' << (double)(*vec->double_params[i])
<< '\t' << vec->double_params[i]->info_str() << '\n';
for (auto double_param : vec->double_params) {
stream << double_param->name_str() << '\t' << (double)(*double_param) << '\t'
<< double_param->info_str() << '\n';
}
}
fprintf(fp, "%s", stream.str().c_str());
@ -198,11 +198,11 @@ void ParamUtils::ResetToDefaults(ParamsVectors *member_params) {
for (i = 0; i < vec->bool_params.size(); ++i) {
vec->bool_params[i]->ResetToDefault();
}
for (int i = 0; i < vec->string_params.size(); ++i) {
vec->string_params[i]->ResetToDefault();
for (auto &string_param : vec->string_params) {
string_param->ResetToDefault();
}
for (int i = 0; i < vec->double_params.size(); ++i) {
vec->double_params[i]->ResetToDefault();
for (auto &double_param : vec->double_params) {
double_param->ResetToDefault();
}
}
}

View File

@ -247,8 +247,7 @@ void UnicharCompress::DefragmentCodeValues(int encoded_null) {
ComputeCodeRange();
std::vector<int> offsets(code_range_);
// Find which codes are used
for (int c = 0; c < encoder_.size(); ++c) {
const RecodedCharID &code = encoder_[c];
for (auto &code : encoder_) {
for (int i = 0; i < code.length(); ++i) {
offsets[code(i)] = 1;
}
@ -270,8 +269,8 @@ void UnicharCompress::DefragmentCodeValues(int encoded_null) {
offsets[encoded_null] = offsets.size() + offsets.back() - encoded_null;
}
// Now apply the offsets.
for (int c = 0; c < encoder_.size(); ++c) {
RecodedCharID *code = &encoder_[c];
for (auto &c : encoder_) {
RecodedCharID *code = &c;
for (int i = 0; i < code->length(); ++i) {
int value = (*code)(i);
code->Set(i, value + offsets[value]);
@ -366,8 +365,7 @@ bool UnicharCompress::DecomposeHangul(int unicode, int *leading, int *vowel, int
// Computes the value of code_range_ from the encoder_.
void UnicharCompress::ComputeCodeRange() {
code_range_ = -1;
for (int c = 0; c < encoder_.size(); ++c) {
const RecodedCharID &code = encoder_[c];
for (auto &code : encoder_) {
for (int i = 0; i < code.length(); ++i) {
if (code(i) > code_range_)
code_range_ = code(i);

View File

@ -1056,8 +1056,8 @@ void Classify::MasterMatcher(INT_TEMPLATES templates, int16_t num_features,
int top = blob_box.top();
int bottom = blob_box.bottom();
UnicharRating int_result;
for (int c = 0; c < results.size(); c++) {
CLASS_ID class_id = results[c].Class;
for (auto result : results) {
CLASS_ID class_id = result.Class;
BIT_VECTOR protos = classes != nullptr ? classes[class_id]->PermProtos : AllProtosOn;
BIT_VECTOR configs = classes != nullptr ? classes[class_id]->PermConfigs : AllConfigsOn;
@ -1065,7 +1065,7 @@ void Classify::MasterMatcher(INT_TEMPLATES templates, int16_t num_features,
im_.Match(ClassForClassId(templates, class_id), protos, configs, num_features, features,
&int_result, classify_adapt_feature_threshold, debug, matcher_debug_separate_windows);
bool is_debug = matcher_debug_level >= 2 || classify_debug_level > 1;
ExpandShapesAndApplyCorrections(classes, is_debug, class_id, bottom, top, results[c].Rating,
ExpandShapesAndApplyCorrections(classes, is_debug, class_id, bottom, top, result.Rating,
final_results->BlobLength, matcher_multiplier, norm_factors,
&int_result, final_results);
}
@ -1084,16 +1084,14 @@ void Classify::ExpandShapesAndApplyCorrections(ADAPT_CLASS *classes, bool debug,
if (classes != nullptr) {
// Adapted result. Convert configs to fontinfo_ids.
int_result->adapted = true;
for (int f = 0; f < int_result->fonts.size(); ++f) {
int_result->fonts[f].fontinfo_id =
GetFontinfoId(classes[class_id], int_result->fonts[f].fontinfo_id);
for (auto &font : int_result->fonts) {
font.fontinfo_id = GetFontinfoId(classes[class_id], font.fontinfo_id);
}
} else {
// Pre-trained result. Map fonts using font_sets_.
int_result->adapted = false;
for (int f = 0; f < int_result->fonts.size(); ++f) {
int_result->fonts[f].fontinfo_id =
ClassAndConfigIDToFontOrShapeID(class_id, int_result->fonts[f].fontinfo_id);
for (auto &font : int_result->fonts) {
font.fontinfo_id = ClassAndConfigIDToFontOrShapeID(class_id, font.fontinfo_id);
}
if (shape_table_ != nullptr) {
// Two possible cases:
@ -1121,9 +1119,8 @@ void Classify::ExpandShapesAndApplyCorrections(ADAPT_CLASS *classes, bool debug,
mapped_results[r].unichar_id = unichar_id;
mapped_results[r].fonts.clear();
}
for (int i = 0; i < shape[c].font_ids.size(); ++i) {
mapped_results[r].fonts.push_back(
ScoredFont(shape[c].font_ids[i], int_result->fonts[f].score));
for (int font_id : shape[c].font_ids) {
mapped_results[r].fonts.emplace_back(font_id, int_result->fonts[f].score);
}
}
}
@ -1298,8 +1295,8 @@ int Classify::CharNormTrainingSample(bool pruner_only, int keep_this, const Trai
matcher_debug_flags, classify_integer_matcher_multiplier, blob_box,
adapt_results->CPResults, adapt_results);
// Convert master matcher results to output format.
for (unsigned i = 0; i < adapt_results->match.size(); i++) {
results->push_back(adapt_results->match[i]);
for (auto &i : adapt_results->match) {
results->push_back(i);
}
if (results->size() > 1) {
std::sort(results->begin(), results->end(), SortDescendingRating);

View File

@ -1096,7 +1096,7 @@ int IntegerMatcher::FindBestMatch(INT_CLASS class_template, const ScratchEvidenc
result->config = c;
best_match = rating;
}
result->fonts.push_back(ScoredFont(c, rating));
result->fonts.emplace_back(c, rating);
}
// Compute confidence on a Probability scale.

View File

@ -55,7 +55,7 @@ public:
~MinK();
struct Element {
Element() {}
Element() = default;
Element(const Key &k, const Value &v) : key(k), value(v) {}
Key key;

View File

@ -40,7 +40,7 @@ LIST ConvertBlob(TBLOB *blob) {
/** Convert a TESSLINE into the float-based MFOUTLINE micro-feature format. */
MFOUTLINE ConvertOutline(TESSLINE *outline) {
MFEDGEPT *NewPoint;
MFOUTLINE MFOutline = NIL_LIST;
auto MFOutline = NIL_LIST;
EDGEPT *EdgePoint;
EDGEPT *StartPoint;
EDGEPT *NextPoint;

View File

@ -52,7 +52,7 @@ MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End);
* @return List of micro-features extracted from the blob.
*/
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm) {
MICROFEATURES MicroFeatures = NIL_LIST;
auto MicroFeatures = NIL_LIST;
LIST Outlines;
LIST RemainingOutlines;
MFOUTLINE Outline;

View File

@ -169,13 +169,13 @@ int ShapeClassifier::DisplayClassifyAs(const TrainingSample &sample, Pix *page_p
void ShapeClassifier::UnicharPrintResults(const char *context,
const std::vector<UnicharRating> &results) const {
tprintf("%s\n", context);
for (int i = 0; i < results.size(); ++i) {
tprintf("%g: c_id=%d=%s", results[i].rating, results[i].unichar_id,
GetUnicharset().id_to_unichar(results[i].unichar_id));
if (!results[i].fonts.empty()) {
for (const auto &result : results) {
tprintf("%g: c_id=%d=%s", result.rating, result.unichar_id,
GetUnicharset().id_to_unichar(result.unichar_id));
if (!result.fonts.empty()) {
tprintf(" Font Vector:");
for (int f = 0; f < results[i].fonts.size(); ++f) {
tprintf(" %d", results[i].fonts[f].fontinfo_id);
for (int f = 0; f < result.fonts.size(); ++f) {
tprintf(" %d", result.fonts[f].fontinfo_id);
}
}
tprintf("\n");
@ -184,13 +184,13 @@ void ShapeClassifier::UnicharPrintResults(const char *context,
void ShapeClassifier::PrintResults(const char *context,
const std::vector<ShapeRating> &results) const {
tprintf("%s\n", context);
for (int i = 0; i < results.size(); ++i) {
tprintf("%g:", results[i].rating);
if (results[i].joined)
for (const auto &result : results) {
tprintf("%g:", result.rating);
if (result.joined)
tprintf("[J]");
if (results[i].broken)
if (result.broken)
tprintf("[B]");
tprintf(" %s\n", GetShapeTable()->DebugStr(results[i].shape_id).c_str());
tprintf(" %s\n", GetShapeTable()->DebugStr(result.shape_id).c_str());
}
}

View File

@ -99,12 +99,12 @@ bool Shape::DeSerialize(TFile *fp) {
// Adds a font_id for the given unichar_id. If the unichar_id is not
// in the shape, it is added.
void Shape::AddToShape(int unichar_id, int font_id) {
for (int c = 0; c < unichars_.size(); ++c) {
if (unichars_[c].unichar_id == unichar_id) {
for (auto &unichar : unichars_) {
if (unichar.unichar_id == unichar_id) {
// Found the unichar in the shape table.
std::vector<int> &font_list = unichars_[c].font_ids;
for (int f = 0; f < font_list.size(); ++f) {
if (font_list[f] == font_id)
std::vector<int> &font_list = unichar.font_ids;
for (int f : font_list) {
if (f == font_id)
return; // Font is already there.
}
font_list.push_back(font_id);
@ -112,15 +112,15 @@ void Shape::AddToShape(int unichar_id, int font_id) {
}
}
// Unichar_id is not in shape, so add it to shape.
unichars_.push_back(UnicharAndFonts(unichar_id, font_id));
unichars_.emplace_back(unichar_id, font_id);
unichars_sorted_ = unichars_.size() <= 1;
}
// Adds everything in other to this.
void Shape::AddShape(const Shape &other) {
for (int c = 0; c < other.unichars_.size(); ++c) {
for (int f = 0; f < other.unichars_[c].font_ids.size(); ++f) {
AddToShape(other.unichars_[c].unichar_id, other.unichars_[c].font_ids[f]);
for (const auto &unichar : other.unichars_) {
for (int f = 0; f < unichar.font_ids.size(); ++f) {
AddToShape(unichar.unichar_id, unichar.font_ids[f]);
}
}
unichars_sorted_ = unichars_.size() <= 1;
@ -128,12 +128,12 @@ void Shape::AddShape(const Shape &other) {
// Returns true if the shape contains the given unichar_id, font_id pair.
bool Shape::ContainsUnicharAndFont(int unichar_id, int font_id) const {
for (int c = 0; c < unichars_.size(); ++c) {
if (unichars_[c].unichar_id == unichar_id) {
for (const auto &unichar : unichars_) {
if (unichar.unichar_id == unichar_id) {
// Found the unichar, so look for the font.
auto &font_list = unichars_[c].font_ids;
for (int f = 0; f < font_list.size(); ++f) {
if (font_list[f] == font_id)
auto &font_list = unichar.font_ids;
for (int f : font_list) {
if (f == font_id)
return true;
}
return false;
@ -144,8 +144,8 @@ bool Shape::ContainsUnicharAndFont(int unichar_id, int font_id) const {
// Returns true if the shape contains the given unichar_id, ignoring font.
bool Shape::ContainsUnichar(int unichar_id) const {
for (int c = 0; c < unichars_.size(); ++c) {
if (unichars_[c].unichar_id == unichar_id) {
for (const auto &unichar : unichars_) {
if (unichar.unichar_id == unichar_id) {
return true;
}
}
@ -154,10 +154,10 @@ bool Shape::ContainsUnichar(int unichar_id) const {
// Returns true if the shape contains the given font, ignoring unichar_id.
bool Shape::ContainsFont(int font_id) const {
for (int c = 0; c < unichars_.size(); ++c) {
auto &font_list = unichars_[c].font_ids;
for (int f = 0; f < font_list.size(); ++f) {
if (font_list[f] == font_id)
for (const auto &unichar : unichars_) {
auto &font_list = unichar.font_ids;
for (int f : font_list) {
if (f == font_id)
return true;
}
}
@ -166,10 +166,10 @@ bool Shape::ContainsFont(int font_id) const {
// Returns true if the shape contains the given font properties, ignoring
// unichar_id.
bool Shape::ContainsFontProperties(const FontInfoTable &font_table, uint32_t properties) const {
for (int c = 0; c < unichars_.size(); ++c) {
auto &font_list = unichars_[c].font_ids;
for (int f = 0; f < font_list.size(); ++f) {
if (font_table.at(font_list[f]).properties == properties)
for (const auto &unichar : unichars_) {
auto &font_list = unichar.font_ids;
for (int f : font_list) {
if (font_table.at(f).properties == properties)
return true;
}
}
@ -179,10 +179,10 @@ bool Shape::ContainsFontProperties(const FontInfoTable &font_table, uint32_t pro
// ignoring unichar_id.
bool Shape::ContainsMultipleFontProperties(const FontInfoTable &font_table) const {
uint32_t properties = font_table.at(unichars_[0].font_ids[0]).properties;
for (int c = 0; c < unichars_.size(); ++c) {
auto &font_list = unichars_[c].font_ids;
for (int f = 0; f < font_list.size(); ++f) {
if (font_table.at(font_list[f]).properties != properties)
for (const auto &unichar : unichars_) {
auto &font_list = unichar.font_ids;
for (int f : font_list) {
if (font_table.at(f).properties != properties)
return true;
}
}
@ -197,11 +197,11 @@ bool Shape::operator==(const Shape &other) const {
// Returns true if this is a subset (including equal) of other.
bool Shape::IsSubsetOf(const Shape &other) const {
for (int c = 0; c < unichars_.size(); ++c) {
int unichar_id = unichars_[c].unichar_id;
const std::vector<int> &font_list = unichars_[c].font_ids;
for (int f = 0; f < font_list.size(); ++f) {
if (!other.ContainsUnicharAndFont(unichar_id, font_list[f]))
for (const auto &unichar : unichars_) {
int unichar_id = unichar.unichar_id;
const std::vector<int> &font_list = unichar.font_ids;
for (int f : font_list) {
if (!other.ContainsUnicharAndFont(unichar_id, f))
return false;
}
}
@ -251,12 +251,12 @@ bool ShapeTable::DeSerialize(TFile *fp) {
// necessary.
int ShapeTable::NumFonts() const {
if (num_fonts_ <= 0) {
for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
const Shape &shape = *shape_table_[shape_id];
for (auto shape_id : shape_table_) {
const Shape &shape = *shape_id;
for (int c = 0; c < shape.size(); ++c) {
for (int f = 0; f < shape[c].font_ids.size(); ++f) {
if (shape[c].font_ids[f] >= num_fonts_)
num_fonts_ = shape[c].font_ids[f] + 1;
for (int font_id : shape[c].font_ids) {
if (font_id >= num_fonts_)
num_fonts_ = font_id + 1;
}
}
}
@ -267,8 +267,7 @@ int ShapeTable::NumFonts() const {
// Re-indexes the class_ids in the shapetable according to the given map.
// Useful in conjunction with set_unicharset.
void ShapeTable::ReMapClassIds(const std::vector<int> &unicharset_map) {
for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
Shape *shape = shape_table_[shape_id];
for (auto shape : shape_table_) {
for (int c = 0; c < shape->size(); ++c) {
shape->SetUnicharId(c, unicharset_map[(*shape)[c].unichar_id]);
}
@ -386,8 +385,8 @@ int ShapeTable::FindShape(int unichar_id, int font_id) const {
if (shape[c].unichar_id == unichar_id) {
if (font_id < 0)
return s; // We don't care about the font.
for (int f = 0; f < shape[c].font_ids.size(); ++f) {
if (shape[c].font_ids[f] == font_id)
for (int f : shape[c].font_ids) {
if (f == font_id)
return s;
}
}
@ -633,8 +632,8 @@ bool ShapeTable::CommonFont(int shape_id1, int shape_id2) const {
const Shape &shape2 = GetShape(shape_id2);
for (int c1 = 0; c1 < shape1.size(); ++c1) {
const std::vector<int> &font_list1 = shape1[c1].font_ids;
for (int f = 0; f < font_list1.size(); ++f) {
if (shape2.ContainsFont(font_list1[f]))
for (int f : font_list1) {
if (shape2.ContainsFont(f))
return true;
}
}
@ -658,8 +657,8 @@ void ShapeTable::AppendMasterShapes(const ShapeTable &other, std::vector<int> *s
// Returns the number of master shapes remaining after merging.
int ShapeTable::NumMasterShapes() const {
int num_shapes = 0;
for (int s = 0; s < shape_table_.size(); ++s) {
if (shape_table_[s]->destination_index() < 0)
for (auto s : shape_table_) {
if (s->destination_index() < 0)
++num_shapes;
}
return num_shapes;
@ -684,9 +683,9 @@ void ShapeTable::AddShapeToResults(const ShapeRating &shape_rating, std::vector<
for (int u = 0; u < shape.size(); ++u) {
int result_index =
AddUnicharToResults(shape[u].unichar_id, shape_rating.rating, unichar_map, results);
for (int f = 0; f < shape[u].font_ids.size(); ++f) {
(*results)[result_index].fonts.push_back(
ScoredFont(shape[u].font_ids[f], IntCastRounded(shape_rating.rating * INT16_MAX)));
for (int font_id : shape[u].font_ids) {
(*results)[result_index].fonts.emplace_back(font_id,
IntCastRounded(shape_rating.rating * INT16_MAX));
}
}
}

View File

@ -120,13 +120,13 @@ void Dawg::iterate_words_rec(const WERD_CHOICE &word_so_far, NODE_REF to_explore
std::function<void(const WERD_CHOICE *)> cb) const {
NodeChildVector children;
this->unichar_ids_of(to_explore, &children, false);
for (int i = 0; i < children.size(); i++) {
for (auto &i : children) {
WERD_CHOICE next_word(word_so_far);
next_word.append_unichar_id(children[i].unichar_id, 1, 0.0, 0.0);
if (this->end_of_word(children[i].edge_ref)) {
next_word.append_unichar_id(i.unichar_id, 1, 0.0, 0.0);
if (this->end_of_word(i.edge_ref)) {
cb(&next_word);
}
NODE_REF next = next_node(children[i].edge_ref);
NODE_REF next = next_node(i.edge_ref);
if (next != 0) {
iterate_words_rec(next_word, next, cb);
}
@ -141,8 +141,8 @@ bool Dawg::match_words(WERD_CHOICE *word, int32_t index, NODE_REF node, UNICHAR_
bool any_matched = false;
NodeChildVector vec;
this->unichar_ids_of(node, &vec, false);
for (int i = 0; i < vec.size(); ++i) {
word->set_unichar_id(vec[i].unichar_id, index);
for (auto &i : vec) {
word->set_unichar_id(i.unichar_id, index);
if (match_words(word, index, node, wildcard))
any_matched = true;
}

View File

@ -351,8 +351,7 @@ bool Dict::FinishLoad() {
// in the successors_ vector is a vector of integers that represent the
// indices into the dawgs_ vector of the successors for dawg i.
successors_.reserve(dawgs_.size());
for (int i = 0; i < dawgs_.size(); ++i) {
const Dawg *dawg = dawgs_[i];
for (auto dawg : dawgs_) {
auto *lst = new SuccessorList();
for (int j = 0; j < dawgs_.size(); ++j) {
const Dawg *other = dawgs_[j];
@ -368,9 +367,9 @@ bool Dict::FinishLoad() {
void Dict::End() {
if (dawgs_.size() == 0)
return; // Not safe to call twice.
for (int i = 0; i < dawgs_.size(); i++) {
if (!dawg_cache_->FreeDawg(dawgs_[i])) {
delete dawgs_[i];
for (auto &dawg : dawgs_) {
if (!dawg_cache_->FreeDawg(dawg)) {
delete dawg;
}
}
dawg_cache_->FreeDawg(bigram_dawg_);
@ -438,8 +437,7 @@ int Dict::def_letter_is_okay(void *void_dawg_args, const UNICHARSET &unicharset,
if (punc_transition_edge != NO_EDGE) {
// Find all successors, and see which can transition.
const SuccessorList &slist = *(successors_[pos.punc_index]);
for (int s = 0; s < slist.size(); ++s) {
int sdawg_index = slist[s];
for (int sdawg_index : slist) {
const Dawg *sdawg = dawgs_[sdawg_index];
UNICHAR_ID ch = char_for_dawg(unicharset, unichar_id, sdawg);
EDGE_REF dawg_edge = sdawg->edge_char_of(0, ch, word_end);
@ -555,13 +553,13 @@ void Dict::ProcessPatternEdges(const Dawg *dawg, const DawgPosition &pos, UNICHA
std::vector<UNICHAR_ID> unichar_id_patterns;
unichar_id_patterns.push_back(unichar_id);
dawg->unichar_id_to_patterns(unichar_id, getUnicharset(), &unichar_id_patterns);
for (int i = 0; i < unichar_id_patterns.size(); ++i) {
for (int unichar_id_pattern : unichar_id_patterns) {
// On the first iteration check all the outgoing edges.
// On the second iteration check all self-loops.
for (int k = 0; k < 2; ++k) {
EDGE_REF edge = (k == 0)
? dawg->edge_char_of(node, unichar_id_patterns[i], word_end)
: dawg->pattern_loop_edge(pos.dawg_ref, unichar_id_patterns[i], word_end);
? dawg->edge_char_of(node, unichar_id_pattern, word_end)
: dawg->pattern_loop_edge(pos.dawg_ref, unichar_id_pattern, word_end);
if (edge == NO_EDGE)
continue;
if (dawg_debug_level >= 3) {
@ -832,8 +830,8 @@ bool Dict::valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) cons
bigram_string.insert(bigram_string.end(), normed_ids.begin(), normed_ids.end());
}
WERD_CHOICE normalized_word(&uchset, bigram_string.size());
for (int i = 0; i < bigram_string.size(); ++i) {
normalized_word.append_unichar_id_space_allocated(bigram_string[i], 1, 0.0f, 0.0f);
for (int i : bigram_string) {
normalized_word.append_unichar_id_space_allocated(i, 1, 0.0f, 0.0f);
}
return bigram_dawg_->word_in_dawg(normalized_word);
}

View File

@ -295,8 +295,8 @@ bool Trie::read_word_list(const char *filename, std::vector<std::string> *words)
bool Trie::add_word_list(const std::vector<std::string> &words, const UNICHARSET &unicharset,
Trie::RTLReversePolicy reverse_policy) {
for (int i = 0; i < words.size(); ++i) {
WERD_CHOICE word(words[i].c_str(), unicharset);
for (const auto &i : words) {
WERD_CHOICE word(i.c_str(), unicharset);
if (word.length() == 0 || word.contains_unichar_id(INVALID_UNICHAR_ID))
continue;
if ((reverse_policy == RRP_REVERSE_IF_HAS_RTL && word.has_rtl_unichar_id()) ||
@ -306,7 +306,7 @@ bool Trie::add_word_list(const std::vector<std::string> &words, const UNICHARSET
if (!word_in_dawg(word)) {
add_word_to_dawg(word);
if (!word_in_dawg(word)) {
tprintf("Error: word '%s' not in DAWG after adding it\n", words[i].c_str());
tprintf("Error: word '%s' not in DAWG after adding it\n", i.c_str());
return false;
}
}
@ -629,8 +629,7 @@ void Trie::sort_edges(EDGE_VECTOR *edges) {
std::vector<KDPairInc<UNICHAR_ID, EDGE_RECORD>> sort_vec;
sort_vec.reserve(num_edges);
for (int i = 0; i < num_edges; ++i) {
sort_vec.push_back(
KDPairInc<UNICHAR_ID, EDGE_RECORD>(unichar_id_from_edge_rec((*edges)[i]), (*edges)[i]));
sort_vec.emplace_back(unichar_id_from_edge_rec((*edges)[i]), (*edges)[i]);
}
std::sort(sort_vec.begin(), sort_vec.end());
for (int i = 0; i < num_edges; ++i)
@ -665,10 +664,10 @@ void Trie::reduce_node_input(NODE_REF node, NODE_MARKER reduced_nodes) {
print_node(node, MAX_NODE_EDGES_DISPLAY);
}
for (int i = 0; i < backward_edges.size(); ++i) {
if (DeadEdge(backward_edges[i]))
for (auto &backward_edge : backward_edges) {
if (DeadEdge(backward_edge))
continue;
NODE_REF next_node = next_node_from_edge_rec(backward_edges[i]);
NODE_REF next_node = next_node_from_edge_rec(backward_edge);
if (next_node != 0 && !reduced_nodes[next_node]) {
reduce_node_input(next_node, reduced_nodes);
}

View File

@ -44,7 +44,7 @@ inline double Tanh(double x) {
if (x < 0.0)
return -Tanh(-x);
x *= kScaleFactor;
unsigned index = static_cast<unsigned>(x);
auto index = static_cast<unsigned>(x);
if (index >= (kTableSize - 1))
return 1.0;
double tanh_i0 = TanhTable[index];
@ -57,7 +57,7 @@ inline double Logistic(double x) {
if (x < 0.0)
return 1.0 - Logistic(-x);
x *= kScaleFactor;
unsigned index = static_cast<unsigned>(x);
auto index = static_cast<unsigned>(x);
if (index >= (kTableSize - 1))
return 1.0;
double l0 = LogisticTable[index];

View File

@ -214,8 +214,7 @@ public:
template <typename T>
class Stack {
public:
Stack() {
}
Stack() = default;
~Stack() {
for (auto data : stack_) {

View File

@ -27,16 +27,16 @@ Plumbing::Plumbing(const std::string &name) : Network(NT_PARALLEL, name, 0, 0) {
// DeSerialize only operate on the run-time data if state is false.
void Plumbing::SetEnableTraining(TrainingState state) {
Network::SetEnableTraining(state);
for (int i = 0; i < stack_.size(); ++i)
stack_[i]->SetEnableTraining(state);
for (auto &i : stack_)
i->SetEnableTraining(state);
}
// Sets flags that control the action of the network. See NetworkFlags enum
// for bit values.
void Plumbing::SetNetworkFlags(uint32_t flags) {
Network::SetNetworkFlags(flags);
for (int i = 0; i < stack_.size(); ++i)
stack_[i]->SetNetworkFlags(flags);
for (auto &i : stack_)
i->SetNetworkFlags(flags);
}
// Sets up the network for training. Initializes weights using weights of
@ -46,8 +46,8 @@ void Plumbing::SetNetworkFlags(uint32_t flags) {
// Returns the number of weights initialized.
int Plumbing::InitWeights(float range, TRand *randomizer) {
num_weights_ = 0;
for (int i = 0; i < stack_.size(); ++i)
num_weights_ += stack_[i]->InitWeights(range, randomizer);
for (auto &i : stack_)
num_weights_ += i->InitWeights(range, randomizer);
return num_weights_;
}
@ -55,24 +55,24 @@ int Plumbing::InitWeights(float range, TRand *randomizer) {
// and remaps their outputs according to code_map. See network.h for details.
int Plumbing::RemapOutputs(int old_no, const std::vector<int> &code_map) {
num_weights_ = 0;
for (int i = 0; i < stack_.size(); ++i) {
num_weights_ += stack_[i]->RemapOutputs(old_no, code_map);
for (auto &i : stack_) {
num_weights_ += i->RemapOutputs(old_no, code_map);
}
return num_weights_;
}
// Converts a float network to an int network.
void Plumbing::ConvertToInt() {
for (int i = 0; i < stack_.size(); ++i)
stack_[i]->ConvertToInt();
for (auto &i : stack_)
i->ConvertToInt();
}
// Provides a pointer to a TRand for any networks that care to use it.
// Note that randomizer is a borrowed pointer that should outlive the network
// and should not be deleted by any of the networks.
void Plumbing::SetRandomizer(TRand *randomizer) {
for (int i = 0; i < stack_.size(); ++i)
stack_[i]->SetRandomizer(randomizer);
for (auto &i : stack_)
i->SetRandomizer(randomizer);
}
// Adds the given network to the stack.
@ -98,8 +98,8 @@ bool Plumbing::SetupNeedsBackprop(bool needs_backprop) {
if (IsTraining()) {
needs_to_backprop_ = needs_backprop;
bool retval = needs_backprop;
for (int i = 0; i < stack_.size(); ++i) {
if (stack_[i]->SetupNeedsBackprop(needs_backprop))
for (auto &i : stack_) {
if (i->SetupNeedsBackprop(needs_backprop))
retval = true;
}
return retval;
@ -122,15 +122,15 @@ int Plumbing::XScaleFactor() const {
// Provides the (minimum) x scale factor to the network (of interest only to
// input units) so they can determine how to scale bounding boxes.
void Plumbing::CacheXScaleFactor(int factor) {
for (int i = 0; i < stack_.size(); ++i) {
stack_[i]->CacheXScaleFactor(factor);
for (auto &i : stack_) {
i->CacheXScaleFactor(factor);
}
}
// Provides debug output on the weights.
void Plumbing::DebugWeights() {
for (int i = 0; i < stack_.size(); ++i)
stack_[i]->DebugWeights();
for (auto &i : stack_)
i->DebugWeights();
}
// Returns a set of strings representing the layer-ids of all layers below.

View File

@ -169,9 +169,9 @@ std::vector<std::vector<std::pair<const char *, float>>>
RecodeBeamSearch::combineSegmentedTimesteps(
std::vector<std::vector<std::vector<std::pair<const char *, float>>>> *segmentedTimesteps) {
std::vector<std::vector<std::pair<const char *, float>>> combined_timesteps;
for (int i = 0; i < segmentedTimesteps->size(); ++i) {
for (int j = 0; j < (*segmentedTimesteps)[i].size(); ++j) {
combined_timesteps.push_back((*segmentedTimesteps)[i][j]);
for (auto &segmentedTimestep : *segmentedTimesteps) {
for (int j = 0; j < segmentedTimestep.size(); ++j) {
combined_timesteps.push_back(segmentedTimestep[j]);
}
}
return combined_timesteps;
@ -436,9 +436,9 @@ void RecodeBeamSearch::extractSymbolChoices(const UNICHARSET *unicharset) {
}
// Exclude the best choice for the followup decoding.
std::unordered_set<int> excludeCodeList;
for (int node = 0; node < best_nodes.size(); ++node) {
if (best_nodes[node]->code != null_char_) {
excludeCodeList.insert(best_nodes[node]->code);
for (auto &best_node : best_nodes) {
if (best_node->code != null_char_) {
excludeCodeList.insert(best_node->code);
}
}
if (j - 1 < excludedUnichars.size()) {
@ -459,7 +459,7 @@ void RecodeBeamSearch::extractSymbolChoices(const UNICHARSET *unicharset) {
int id = unichar_ids[bestPos];
const char *result = unicharset->id_to_unichar_ext(id);
float rating = ratings[bestPos];
choice.push_back(std::pair<const char *, float>(result, rating));
choice.emplace_back(result, rating);
ctc_choices.push_back(choice);
}
// fill the blank spot with an empty array
@ -514,9 +514,9 @@ void RecodeBeamSearch::DebugBeamPos(const UNICHARSET &unicharset, const RecodeHe
}
}
}
for (int u = 0; u < unichar_bests.size(); ++u) {
if (unichar_bests[u] != nullptr) {
const RecodeNode &node = *unichar_bests[u];
for (auto &unichar_best : unichar_bests) {
if (unichar_best != nullptr) {
const RecodeNode &node = *unichar_best;
node.Print(null_char_, unicharset, 1);
}
}
@ -794,7 +794,7 @@ void RecodeBeamSearch::DecodeSecondaryStep(const float *outputs, int t, double d
// first, which may have an empty intersection with the valid codes, so we
// fall back to the rest if the beam is empty.
for (int tn = 0; tn < TN_COUNT && total_beam == 0; ++tn) {
TopNState top_n = static_cast<TopNState>(tn);
auto top_n = static_cast<TopNState>(tn);
for (int index = 0; index < kNumBeams; ++index) {
// Working backwards through the heaps doesn't guarantee that we see the
// best first, but it comes before a lot of the worst, so it is slightly
@ -870,8 +870,7 @@ void RecodeBeamSearch::ContinueContext(const RecodeNode *prev, int index, const
}
const std::vector<int> *final_codes = recoder_.GetFinalCodes(prefix);
if (final_codes != nullptr) {
for (int i = 0; i < final_codes->size(); ++i) {
int code = (*final_codes)[i];
for (int code : *final_codes) {
if (top_n_flags_[code] != top_n_flag)
continue;
if (prev != nullptr && prev->code == code && !is_simple_text_)
@ -904,8 +903,7 @@ void RecodeBeamSearch::ContinueContext(const RecodeNode *prev, int index, const
}
const std::vector<int> *next_codes = recoder_.GetNextCodes(prefix);
if (next_codes != nullptr) {
for (int i = 0; i < next_codes->size(); ++i) {
int code = (*next_codes)[i];
for (int code : *next_codes) {
if (top_n_flags_[code] != top_n_flag)
continue;
if (prev != nullptr && prev->code == code && !is_simple_text_)
@ -1132,16 +1130,16 @@ bool RecodeBeamSearch::UpdateHeapIfMatched(RecodeNode *new_node, RecodeHeap *hea
// It might not be faster because the hash map would have to be updated
// every time a heap reshuffle happens, and that would be a lot of overhead.
std::vector<RecodePair> &nodes = heap->heap();
for (int i = 0; i < nodes.size(); ++i) {
RecodeNode &node = nodes[i].data();
for (auto &i : nodes) {
RecodeNode &node = i.data();
if (node.code == new_node->code && node.code_hash == new_node->code_hash &&
node.permuter == new_node->permuter && node.start_of_dawg == new_node->start_of_dawg) {
if (new_node->score > node.score) {
// The new one is better. Update the entire node in the heap and
// reshuffle.
node = *new_node;
nodes[i].key() = node.score;
heap->Reshuffle(&nodes[i]);
i.key() = node.score;
heap->Reshuffle(&i);
}
return true;
}

View File

@ -46,9 +46,9 @@ StaticShape Series::OutputShape(const StaticShape &input_shape) const {
int Series::InitWeights(float range, TRand *randomizer) {
num_weights_ = 0;
tprintf("Num outputs,weights in Series:\n");
for (int i = 0; i < stack_.size(); ++i) {
int weights = stack_[i]->InitWeights(range, randomizer);
tprintf(" %s:%d, %d\n", stack_[i]->spec().c_str(), stack_[i]->NumOutputs(), weights);
for (auto &i : stack_) {
int weights = i->InitWeights(range, randomizer);
tprintf(" %s:%d, %d\n", i->spec().c_str(), i->NumOutputs(), weights);
num_weights_ += weights;
}
tprintf("Total weights = %d\n", num_weights_);
@ -60,9 +60,9 @@ int Series::InitWeights(float range, TRand *randomizer) {
int Series::RemapOutputs(int old_no, const std::vector<int> &code_map) {
num_weights_ = 0;
tprintf("Num (Extended) outputs,weights in Series:\n");
for (int i = 0; i < stack_.size(); ++i) {
int weights = stack_[i]->RemapOutputs(old_no, code_map);
tprintf(" %s:%d, %d\n", stack_[i]->spec().c_str(), stack_[i]->NumOutputs(), weights);
for (auto &i : stack_) {
int weights = i->RemapOutputs(old_no, code_map);
tprintf(" %s:%d, %d\n", i->spec().c_str(), i->NumOutputs(), weights);
num_weights_ += weights;
}
tprintf("Total weights = %d\n", num_weights_);
@ -75,8 +75,8 @@ int Series::RemapOutputs(int old_no, const std::vector<int> &code_map) {
// can be told to produce backprop for this layer if needed.
bool Series::SetupNeedsBackprop(bool needs_backprop) {
needs_to_backprop_ = needs_backprop;
for (int i = 0; i < stack_.size(); ++i)
needs_backprop = stack_[i]->SetupNeedsBackprop(needs_backprop);
for (auto &i : stack_)
needs_backprop = i->SetupNeedsBackprop(needs_backprop);
return needs_backprop;
}
@ -88,8 +88,8 @@ bool Series::SetupNeedsBackprop(bool needs_backprop) {
// the minimum scale factor of the paths through the GlobalMinimax.
int Series::XScaleFactor() const {
int factor = 1;
for (int i = 0; i < stack_.size(); ++i)
factor *= stack_[i]->XScaleFactor();
for (auto i : stack_)
factor *= i->XScaleFactor();
return factor;
}
@ -158,8 +158,8 @@ void Series::SplitAt(int last_start, Series **start, Series **end) {
tprintf("Invalid split index %d must be in range [0,%zu]!\n", last_start, stack_.size() - 1);
return;
}
Series *master_series = new Series("MasterSeries");
Series *boosted_series = new Series("BoostedSeries");
auto *master_series = new Series("MasterSeries");
auto *boosted_series = new Series("BoostedSeries");
for (int s = 0; s <= last_start; ++s) {
if (s + 1 == stack_.size() && stack_[s]->type() == NT_SOFTMAX) {
// Change the softmax to a tanh.
@ -183,9 +183,9 @@ void Series::SplitAt(int last_start, Series **start, Series **end) {
void Series::AppendSeries(Network *src) {
ASSERT_HOST(src->type() == NT_SERIES);
auto *src_series = static_cast<Series *>(src);
for (int s = 0; s < src_series->stack_.size(); ++s) {
AddToStack(src_series->stack_[s]);
src_series->stack_[s] = nullptr;
for (auto &s : src_series->stack_) {
AddToStack(s);
s = nullptr;
}
delete src;
}

View File

@ -260,8 +260,8 @@ bool WeightMatrix::DeSerializeOld(bool training, TFile *fp) {
if (!fp->DeSerialize(old_scales))
return false;
scales_.reserve(old_scales.size());
for (int i = 0; i < old_scales.size(); ++i) {
scales_.push_back(old_scales[i]);
for (float old_scale : old_scales) {
scales_.push_back(old_scale);
}
} else {
if (!float_array.DeSerialize(fp))

View File

@ -307,8 +307,8 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD &direction) {
// Set up a histogram using disp_quant_factor_ as the bucket size.
STATS dist_stats(IntCastRounded(min_dist / disp_quant_factor_),
IntCastRounded(max_dist / disp_quant_factor_) + 1);
for (int i = 0; i < perp_blob_dists.size(); ++i) {
dist_stats.add(IntCastRounded(perp_blob_dists[i] / disp_quant_factor_), 1);
for (double perp_blob_dist : perp_blob_dists) {
dist_stats.add(IntCastRounded(perp_blob_dist / disp_quant_factor_), 1);
}
std::vector<KDPairInc<float, int>> scaled_modes;
dist_stats.top_n_modes(kMaxDisplacementsModes, scaled_modes);
@ -320,8 +320,8 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD &direction) {
}
}
#endif
for (int i = 0; i < scaled_modes.size(); ++i)
displacement_modes_.push_back(disp_quant_factor_ * scaled_modes[i].key());
for (auto &scaled_mode : scaled_modes)
displacement_modes_.push_back(disp_quant_factor_ * scaled_mode.key());
}
// Fits a line in the given direction to blobs that are close to the given
@ -429,8 +429,7 @@ bool BaselineBlock::FitBaselinesAndFindSkew(bool use_box_bottoms) {
if (non_text_block_)
return false;
std::vector<double> angles;
for (int r = 0; r < rows_.size(); ++r) {
BaselineRow *row = rows_[r];
for (auto row : rows_) {
if (row->FitBaseline(use_box_bottoms)) {
double angle = row->BaselineAngle();
angles.push_back(angle);
@ -462,8 +461,7 @@ void BaselineBlock::ParallelizeBaselines(double default_block_skew) {
if (debug_level_ > 0)
tprintf("Adjusting block to skew angle %g\n", skew_angle_);
FCOORD direction(cos(skew_angle_), sin(skew_angle_));
for (int r = 0; r < rows_.size(); ++r) {
BaselineRow *row = rows_[r];
for (auto row : rows_) {
row->AdjustBaselineToParallel(debug_level_, direction);
if (debug_level_ > 1)
row->Print();
@ -646,8 +644,7 @@ bool BaselineBlock::ComputeLineSpacing() {
void BaselineBlock::ComputeBaselinePositions(const FCOORD &direction,
std::vector<double> *positions) {
positions->clear();
for (int r = 0; r < rows_.size(); ++r) {
BaselineRow *row = rows_[r];
for (auto row : rows_) {
const TBOX &row_box = row->bounding_box();
float x_middle = (row_box.left() + row_box.right()) / 2.0f;
FCOORD row_pos(x_middle, static_cast<float>(row->StraightYAtX(x_middle)));
@ -739,16 +736,15 @@ double BaselineBlock::FitLineSpacingModel(const std::vector<double> &positions,
}
std::vector<double> offsets;
// Get the offset (remainder) linespacing for each line and choose the median.
for (int i = 0; i < positions.size(); ++i)
offsets.push_back(fmod(positions[i], m_in));
for (double position : positions)
offsets.push_back(fmod(position, m_in));
// Get the median offset.
double median_offset = MedianOfCircularValues(m_in, offsets);
// Now fit a line to quantized line number and offset.
LLSQ llsq;
int min_index = INT32_MAX;
int max_index = -INT32_MAX;
for (int i = 0; i < positions.size(); ++i) {
double y_pos = positions[i];
for (double y_pos : positions) {
int row_index = IntCastRounded((y_pos - median_offset) / m_in);
UpdateRange(row_index, &min_index, &max_index);
llsq.add(row_index, y_pos);
@ -758,8 +754,8 @@ double BaselineBlock::FitLineSpacingModel(const std::vector<double> &positions,
// Use the median offset rather than the mean.
offsets.clear();
if (*m_out != 0.0) {
for (int i = 0; i < positions.size(); ++i) {
offsets.push_back(fmod(positions[i], *m_out));
for (double position : positions) {
offsets.push_back(fmod(position, *m_out));
}
// Get the median offset.
if (debug_level_ > 2) {
@ -810,8 +806,7 @@ BaselineDetect::BaselineDetect(int debug_level, const FCOORD &page_skew, TO_BLOC
// smoothing based on block/page-level skew and block-level linespacing.
void BaselineDetect::ComputeStraightBaselines(bool use_box_bottoms) {
std::vector<double> block_skew_angles;
for (int i = 0; i < blocks_.size(); ++i) {
BaselineBlock *bl_block = blocks_[i];
for (auto bl_block : blocks_) {
if (debug_level_ > 0)
tprintf("Fitting initial baselines...\n");
if (bl_block->FitBaselinesAndFindSkew(use_box_bottoms)) {
@ -828,8 +823,7 @@ void BaselineDetect::ComputeStraightBaselines(bool use_box_bottoms) {
}
// Set bad lines in each block to the default block skew and then force fit
// a linespacing model where it makes sense to do so.
for (int i = 0; i < blocks_.size(); ++i) {
BaselineBlock *bl_block = blocks_[i];
for (auto bl_block : blocks_) {
bl_block->ParallelizeBaselines(default_block_skew);
bl_block->SetupBlockParameters(); // This replaced compute_row_stats.
}
@ -843,8 +837,7 @@ void BaselineDetect::ComputeStraightBaselines(bool use_box_bottoms) {
void BaselineDetect::ComputeBaselineSplinesAndXheights(const ICOORD &page_tr, bool enable_splines,
bool remove_noise, bool show_final_rows,
Textord *textord) {
for (int i = 0; i < blocks_.size(); ++i) {
BaselineBlock *bl_block = blocks_[i];
for (auto bl_block : blocks_) {
if (enable_splines)
bl_block->PrepareForSplineFitting(page_tr, remove_noise);
bl_block->FitBaselineSplines(enable_splines, show_final_rows, textord);

View File

@ -105,7 +105,7 @@ public:
};
LocalCorrelation() : finalized_(false) {}
~LocalCorrelation() {}
~LocalCorrelation() = default;
void Finish() {
std::sort(values_.begin(), values_.end(), float_pair_compare);
@ -275,7 +275,7 @@ class FPRow {
public:
FPRow() : all_pitches_(), all_gaps_(), good_pitches_(), good_gaps_(), heights_(), characters_() {}
~FPRow() {}
~FPRow() = default;
// Initialize from TD_ROW.
void Init(TO_ROW *row);
@ -916,7 +916,7 @@ void FPRow::FinalizeLargeChars() {
class FPAnalyzer {
public:
FPAnalyzer(ICOORD page_tr, TO_BLOCK_LIST *port_blocks);
~FPAnalyzer() {}
~FPAnalyzer() = default;
void Pass1Analyze() {
for (auto &row : rows_)

View File

@ -592,8 +592,7 @@ bool ColumnFinder::MakeColumns(bool single_column) {
#endif
ComputeMeanColumnGap(any_multi_column);
}
for (int i = 0; i < part_sets.size(); ++i) {
ColPartitionSet *line_set = part_sets.at(i);
for (auto line_set : part_sets) {
if (line_set != nullptr) {
line_set->RelinquishParts();
delete line_set;
@ -1532,7 +1531,7 @@ void ColumnFinder::RotateAndReskewBlocks(bool input_is_rtl, TO_BLOCK_LIST *block
tprintf("Block median size = (%d, %d)\n", block->median_size().x(), block->median_size().y());
}
std::vector<TessTable>& tables = uniqueInstance<std::vector<TessTable>>();
auto &tables = uniqueInstance<std::vector<TessTable>>();
for(TessTable& mt: tables)
mt.box.rotate_large(reskew_);
}

View File

@ -110,7 +110,7 @@ ColPartition::ColPartition(BlobRegionType blob_type, const ICOORD &vertical)
// Call DeleteBoxes before deleting the ColPartition.
ColPartition *ColPartition::FakePartition(const TBOX &box, PolyBlockType block_type,
BlobRegionType blob_type, BlobTextFlowType flow) {
ColPartition *part = new ColPartition(blob_type, ICOORD(0, 1));
auto *part = new ColPartition(blob_type, ICOORD(0, 1));
part->set_type(block_type);
part->set_flow(flow);
part->AddBox(new BLOBNBOX(C_BLOB::FakeBlob(box)));
@ -129,7 +129,7 @@ ColPartition *ColPartition::FakePartition(const TBOX &box, PolyBlockType block_t
// If the given list is not nullptr, the partition is also added to the list.
ColPartition *ColPartition::MakeBigPartition(BLOBNBOX *box, ColPartition_LIST *big_part_list) {
box->set_owner(nullptr);
ColPartition *single = new ColPartition(BRT_UNKNOWN, ICOORD(0, 1));
auto *single = new ColPartition(BRT_UNKNOWN, ICOORD(0, 1));
single->set_flow(BTFT_NONE);
single->AddBox(box);
single->ComputeLimits();

View File

@ -23,6 +23,8 @@
#include "edgblob.h"
#include <memory>
#include "edgloop.h"
#include "scanedg.h"
@ -60,7 +62,7 @@ OL_BUCKETS::OL_BUCKETS(ICOORD bleft, // corners
bxdim = (tright.x() - bleft.x()) / BUCKETSIZE + 1;
bydim = (tright.y() - bleft.y()) / BUCKETSIZE + 1;
// make array
buckets.reset(new C_OUTLINE_LIST[bxdim * bydim]);
buckets = std::make_unique<C_OUTLINE_LIST[]>(bxdim * bydim);
index = 0;
}

View File

@ -53,7 +53,7 @@ public:
private:
// Copy constructor (currently unused, therefore private).
C_OUTLINE_FRAG(const C_OUTLINE_FRAG &other);
C_OUTLINE_FRAG(const C_OUTLINE_FRAG &other) = delete;
};
ELISTIZEH(C_OUTLINE_FRAG)

View File

@ -460,7 +460,7 @@ void StrokeWidth::FindLeadersAndMarkNoise(TO_BLOCK *block, ColPartition_LIST *le
if (bbox->neighbour(BND_RIGHT) == nullptr && bbox->neighbour(BND_LEFT) == nullptr)
continue;
// Put all the linked blobs into a ColPartition.
ColPartition *part = new ColPartition(BRT_UNKNOWN, ICOORD(0, 1));
auto *part = new ColPartition(BRT_UNKNOWN, ICOORD(0, 1));
BLOBNBOX *blob;
for (blob = bbox; blob != nullptr && blob->flow() == BTFT_NONE;
blob = blob->neighbour(BND_RIGHT))
@ -1365,7 +1365,7 @@ void StrokeWidth::FindVerticalTextChains(ColPartitionGrid *part_grid) {
if (bbox->owner() == nullptr && bbox->UniquelyVertical() &&
(blob = MutualUnusedVNeighbour(bbox, BND_ABOVE)) != nullptr) {
// Put all the linked blobs into a ColPartition.
ColPartition *part = new ColPartition(BRT_VERT_TEXT, ICOORD(0, 1));
auto *part = new ColPartition(BRT_VERT_TEXT, ICOORD(0, 1));
part->AddBox(bbox);
while (blob != nullptr) {
part->AddBox(blob);
@ -1407,7 +1407,7 @@ void StrokeWidth::FindHorizontalTextChains(ColPartitionGrid *part_grid) {
if (bbox->owner() == nullptr && bbox->UniquelyHorizontal() &&
(blob = MutualUnusedHNeighbour(bbox, BND_RIGHT)) != nullptr) {
// Put all the linked blobs into a ColPartition.
ColPartition *part = new ColPartition(BRT_TEXT, ICOORD(0, 1));
auto *part = new ColPartition(BRT_TEXT, ICOORD(0, 1));
part->AddBox(bbox);
while (blob != nullptr) {
part->AddBox(blob);
@ -1786,7 +1786,7 @@ void StrokeWidth::MakePartitionsFromCellList(PageSegMode pageseg_mode, bool comb
BLOBNBOX_C_IT cell_it(cell_list);
if (combine) {
BLOBNBOX *bbox = cell_it.extract();
ColPartition *part = new ColPartition(bbox->region_type(), ICOORD(0, 1));
auto *part = new ColPartition(bbox->region_type(), ICOORD(0, 1));
part->AddBox(bbox);
part->set_flow(bbox->flow());
for (cell_it.forward(); !cell_it.empty(); cell_it.forward()) {
@ -1796,7 +1796,7 @@ void StrokeWidth::MakePartitionsFromCellList(PageSegMode pageseg_mode, bool comb
} else {
for (; !cell_it.empty(); cell_it.forward()) {
BLOBNBOX *bbox = cell_it.extract();
ColPartition *part = new ColPartition(bbox->region_type(), ICOORD(0, 1));
auto *part = new ColPartition(bbox->region_type(), ICOORD(0, 1));
part->set_flow(bbox->flow());
part->AddBox(bbox);
CompletePartition(pageseg_mode, part, part_grid);

View File

@ -75,7 +75,7 @@ TabFind::TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVec
width_cb_ = std::bind(&TabFind::CommonWidth, this, _1);
}
TabFind::~TabFind() {}
TabFind::~TabFind() = default;
///////////////// PUBLIC functions (mostly used by TabVector). //////////////
@ -517,13 +517,13 @@ ScrollView *TabFind::FindInitialTabVectors(BLOBNBOX_LIST *image_blobs, int min_g
// Helper displays all the boxes in the given vector on the given window.
static void DisplayBoxVector(const std::vector<BLOBNBOX *> &boxes, ScrollView *win) {
for (int i = 0; i < boxes.size(); ++i) {
TBOX box = boxes[i]->bounding_box();
for (auto boxe : boxes) {
TBOX box = boxe->bounding_box();
int left_x = box.left();
int right_x = box.right();
int top_y = box.top();
int bottom_y = box.bottom();
ScrollView::Color box_color = boxes[i]->BoxColor();
ScrollView::Color box_color = boxe->BoxColor();
win->Pen(box_color);
win->Rectangle(left_x, bottom_y, right_x, top_y);
}
@ -793,13 +793,11 @@ void TabFind::FindAllTabVectors(int min_gutter_width) {
}
// Get rid of the test vectors and reset the types of the tabs.
dummy_vectors.clear();
for (int i = 0; i < left_tab_boxes_.size(); ++i) {
BLOBNBOX *bbox = left_tab_boxes_[i];
for (auto bbox : left_tab_boxes_) {
if (bbox->left_tab_type() == TT_CONFIRMED)
bbox->set_left_tab_type(TT_MAYBE_ALIGNED);
}
for (int i = 0; i < right_tab_boxes_.size(); ++i) {
BLOBNBOX *bbox = right_tab_boxes_[i];
for (auto bbox : right_tab_boxes_) {
if (bbox->right_tab_type() == TT_CONFIRMED)
bbox->set_right_tab_type(TT_MAYBE_ALIGNED);
}
@ -832,8 +830,7 @@ int TabFind::FindTabVectors(int search_size_multiple, TabAlignment alignment, in
// Search the right or left tab boxes, looking for tab vectors.
bool right = alignment == TA_RIGHT_ALIGNED || alignment == TA_RIGHT_RAGGED;
const std::vector<BLOBNBOX *> &boxes = right ? right_tab_boxes_ : left_tab_boxes_;
for (int i = 0; i < boxes.size(); ++i) {
BLOBNBOX *bbox = boxes[i];
for (auto bbox : boxes) {
if ((!right && bbox->left_tab_type() == TT_MAYBE_ALIGNED) ||
(right && bbox->right_tab_type() == TT_MAYBE_ALIGNED)) {
TabVector *vector = FindTabVector(search_size_multiple, min_gutter_width, alignment, bbox,

View File

@ -2018,11 +2018,11 @@ void TableFinder::MakeTableBlocks(ColPartitionGrid *grid, ColPartitionSet **all_
}
#endif // GRAPHICS_DISABLED
std::vector<TessTable>& tables = uniqueInstance<std::vector<TessTable>>();
tables.push_back(TessTable{table_box, table_structure->getRows(),
table_structure->getCols()});
auto &tables = uniqueInstance<std::vector<TessTable>>();
tables.push_back(
TessTable{table_box, table_structure->getRows(), table_structure->getCols()});
delete table_structure;
delete table_structure;
}
}
}

View File

@ -209,11 +209,11 @@ bool StructuredTable::FindWhitespacedStructure() {
// throughout the code is that "0" distance is a very very small space.
bool StructuredTable::DoesPartitionFit(const ColPartition &part) const {
const TBOX &box = part.bounding_box();
for (int i = 0; i < cell_x_.size(); ++i)
if (box.left() < cell_x_[i] && cell_x_[i] < box.right())
for (int i : cell_x_)
if (box.left() < i && i < box.right())
return false;
for (int i = 0; i < cell_y_.size(); ++i)
if (box.bottom() < cell_y_[i] && cell_y_[i] < box.top())
for (int i : cell_y_)
if (box.bottom() < i && i < box.top())
return false;
return true;
}
@ -290,11 +290,11 @@ void StructuredTable::Display(ScrollView *window, ScrollView::Color color) {
window->Pen(color);
window->Rectangle(bounding_box_.left(), bounding_box_.bottom(), bounding_box_.right(),
bounding_box_.top());
for (int i = 0; i < cell_x_.size(); i++) {
window->Line(cell_x_[i], bounding_box_.bottom(), cell_x_[i], bounding_box_.top());
for (int i : cell_x_) {
window->Line(i, bounding_box_.bottom(), i, bounding_box_.top());
}
for (int i = 0; i < cell_y_.size(); i++) {
window->Line(bounding_box_.left(), cell_y_[i], bounding_box_.right(), cell_y_[i]);
for (int i : cell_y_) {
window->Line(bounding_box_.left(), i, bounding_box_.right(), i);
}
window->UpdateWindow();
}
@ -350,12 +350,12 @@ void StructuredTable::ClearStructure() {
bool StructuredTable::VerifyLinedTableCells() {
// Function only called when lines exist.
ASSERT_HOST(cell_y_.size() >= 2 && cell_x_.size() >= 2);
for (int i = 0; i < cell_y_.size(); ++i) {
if (CountHorizontalIntersections(cell_y_[i]) > 0)
for (int i : cell_y_) {
if (CountHorizontalIntersections(i) > 0)
return false;
}
for (int i = 0; i < cell_x_.size(); ++i) {
if (CountVerticalIntersections(cell_x_[i]) > 0)
for (int i : cell_x_) {
if (CountVerticalIntersections(i) > 0)
return false;
}
return true;
@ -723,7 +723,7 @@ TableRecognizer::TableRecognizer()
, min_width_(0)
, max_text_height_(INT32_MAX) {}
TableRecognizer::~TableRecognizer() {}
TableRecognizer::~TableRecognizer() = default;
void TableRecognizer::Init() {}

View File

@ -57,8 +57,8 @@ int main(int argc, char **argv) {
tesseract::TessBaseAPI api;
std::vector<std::string> vars_vec;
std::vector<std::string> vars_values;
vars_vec.push_back("output_ambig_words_file");
vars_values.push_back(output_file_str);
vars_vec.emplace_back("output_ambig_words_file");
vars_values.emplace_back(output_file_str);
api.Init(tessdata_dir, lang.c_str(), tesseract::OEM_TESSERACT_ONLY, nullptr, 0, &vars_vec,
&vars_values, false);
tesseract::Dict &dict = api.tesseract()->getDict();

View File

@ -171,8 +171,8 @@ int main(int argc, char *argv[]) {
int desc_index = ShortNameToFeatureType(FeatureDefs, PROGRAM_FEATURE_TYPE);
WriteNormProtos(FLAGS_D.c_str(), NormProtoList, FeatureDefs.FeatureDesc[desc_index]);
FreeNormProtoList(NormProtoList);
for (int i = 0; i < freeable_protos.size(); ++i) {
FreeProtoList(&freeable_protos[i]);
for (auto &freeable_proto : freeable_protos) {
FreeProtoList(&freeable_proto);
}
printf("\n");
return 0;

View File

@ -22,7 +22,7 @@ static bool IntFlagExists(const char *flag_name, int32_t *value) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<IntParam *> empty;
IntParam *p =
auto *p =
ParamUtils::FindParam<IntParam>(full_flag_name.c_str(), GlobalParams()->int_params, empty);
if (p == nullptr)
return false;
@ -34,8 +34,8 @@ static bool DoubleFlagExists(const char *flag_name, double *value) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<DoubleParam *> empty;
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(full_flag_name.c_str(),
GlobalParams()->double_params, empty);
auto *p = ParamUtils::FindParam<DoubleParam>(full_flag_name.c_str(),
GlobalParams()->double_params, empty);
if (p == nullptr)
return false;
*value = static_cast<double>(*p);
@ -46,7 +46,7 @@ static bool BoolFlagExists(const char *flag_name, bool *value) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<BoolParam *> empty;
BoolParam *p =
auto *p =
ParamUtils::FindParam<BoolParam>(full_flag_name.c_str(), GlobalParams()->bool_params, empty);
if (p == nullptr)
return false;
@ -58,8 +58,8 @@ static bool StringFlagExists(const char *flag_name, const char **value) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<StringParam *> empty;
StringParam *p = ParamUtils::FindParam<StringParam>(full_flag_name.c_str(),
GlobalParams()->string_params, empty);
auto *p = ParamUtils::FindParam<StringParam>(full_flag_name.c_str(),
GlobalParams()->string_params, empty);
*value = (p != nullptr) ? p->c_str() : nullptr;
return p != nullptr;
}
@ -68,7 +68,7 @@ static void SetIntFlagValue(const char *flag_name, const int32_t new_val) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<IntParam *> empty;
IntParam *p =
auto *p =
ParamUtils::FindParam<IntParam>(full_flag_name.c_str(), GlobalParams()->int_params, empty);
ASSERT_HOST(p != nullptr);
p->set_value(new_val);
@ -78,8 +78,8 @@ static void SetDoubleFlagValue(const char *flag_name, const double new_val) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<DoubleParam *> empty;
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(full_flag_name.c_str(),
GlobalParams()->double_params, empty);
auto *p = ParamUtils::FindParam<DoubleParam>(full_flag_name.c_str(),
GlobalParams()->double_params, empty);
ASSERT_HOST(p != nullptr);
p->set_value(new_val);
}
@ -88,7 +88,7 @@ static void SetBoolFlagValue(const char *flag_name, const bool new_val) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<BoolParam *> empty;
BoolParam *p =
auto *p =
ParamUtils::FindParam<BoolParam>(full_flag_name.c_str(), GlobalParams()->bool_params, empty);
ASSERT_HOST(p != nullptr);
p->set_value(new_val);
@ -98,8 +98,8 @@ static void SetStringFlagValue(const char *flag_name, const char *new_val) {
std::string full_flag_name("FLAGS_");
full_flag_name += flag_name;
std::vector<StringParam *> empty;
StringParam *p = ParamUtils::FindParam<StringParam>(full_flag_name.c_str(),
GlobalParams()->string_params, empty);
auto *p = ParamUtils::FindParam<StringParam>(full_flag_name.c_str(),
GlobalParams()->string_params, empty);
ASSERT_HOST(p != nullptr);
p->set_value(std::string(new_val));
}

View File

@ -518,7 +518,7 @@ void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clus
// Find the nearest alive prototype.
LIST list_it = ProtoList;
iterate(list_it) {
PROTOTYPE *test_p = reinterpret_cast<PROTOTYPE *> first_node(list_it);
auto *test_p = reinterpret_cast<PROTOTYPE *> first_node(list_it);
if (test_p != Prototype && !test_p->Merged) {
float dist = ComputeDistance(Clusterer->SampleSize, Clusterer->ParamDesc, Prototype->Mean,
test_p->Mean);
@ -691,7 +691,7 @@ CLASS_STRUCT *SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassL
// printf("Float2Int ...\n");
CLASS_STRUCT *float_classes = new CLASS_STRUCT[unicharset.size()];
auto *float_classes = new CLASS_STRUCT[unicharset.size()];
iterate(LabeledClassList) {
UnicityTable<int> font_set;
MergeClass = reinterpret_cast<MERGE_CLASS> first_node(LabeledClassList);
@ -782,7 +782,7 @@ void AddToNormProtosList(LIST *NormProtoList, LIST ProtoList, char *CharName) {
int NumberOfProtos(LIST ProtoList, bool CountSigProtos, bool CountInsigProtos) {
int N = 0;
iterate(ProtoList) {
PROTOTYPE *Proto = reinterpret_cast<PROTOTYPE *> first_node(ProtoList);
auto *Proto = reinterpret_cast<PROTOTYPE *> first_node(ProtoList);
if ((Proto->Significant && CountSigProtos) || (!Proto->Significant && CountInsigProtos))
N++;
}

View File

@ -52,8 +52,7 @@ void IntFeatureDist::Init(const IntFeatureMap *feature_map) {
void IntFeatureDist::Set(const std::vector<int> &indexed_features, int canonical_count,
bool value) {
total_feature_weight_ = canonical_count;
for (int i = 0; i < indexed_features.size(); ++i) {
const int f = indexed_features[i];
for (int f : indexed_features) {
features_[f] = value;
for (int dir = -kNumOffsetMaps; dir <= kNumOffsetMaps; ++dir) {
if (dir == 0)

View File

@ -164,8 +164,8 @@ int IntFeatureMap::FinalizeMapping(SampleIterator *it) {
// Prints the map features from the set in human-readable form.
void IntFeatureMap::DebugMapFeatures(const std::vector<int> &map_features) const {
for (int i = 0; i < map_features.size(); ++i) {
INT_FEATURE_STRUCT f = InverseMapFeature(map_features[i]);
for (int map_feature : map_features) {
INT_FEATURE_STRUCT f = InverseMapFeature(map_feature);
f.print();
}
}

View File

@ -62,8 +62,8 @@ MasterTrainer::MasterTrainer(NormalizationMode norm_mode, bool shape_analysis,
MasterTrainer::~MasterTrainer() {
delete[] fragments_;
for (int p = 0; p < page_images_.size(); ++p)
pixDestroy(&page_images_[p]);
for (auto &page_image : page_images_)
pixDestroy(&page_image);
}
// WARNING! Serialize/DeSerialize are only partial, providing
@ -134,7 +134,7 @@ void MasterTrainer::ReadTrainingSamples(const char *page_name,
tprintf("Failed to open tr file: %s\n", page_name);
return;
}
tr_filenames_.push_back(std::string(page_name));
tr_filenames_.emplace_back(page_name);
while (fgets(buffer, sizeof(buffer), fp) != nullptr) {
if (buffer[0] == '\n')
continue;

View File

@ -132,7 +132,7 @@ Network *NetworkBuilder::ParseInput(const char **str) {
return nullptr;
}
*str += length;
Input *input = new Input("Input", shape);
auto *input = new Input("Input", shape);
// We want to allow [<input>rest of net... or <input>[rest of net... so we
// have to check explicitly for '[' here.
SkipWhitespace(str);
@ -145,7 +145,7 @@ Network *NetworkBuilder::ParseInput(const char **str) {
Network *NetworkBuilder::ParseSeries(const StaticShape &input_shape, Input *input_layer,
const char **str) {
StaticShape shape = input_shape;
Series *series = new Series("Series");
auto *series = new Series("Series");
++*str;
if (input_layer != nullptr) {
series->AddToStack(input_layer);
@ -167,7 +167,7 @@ Network *NetworkBuilder::ParseSeries(const StaticShape &input_shape, Input *inpu
// Parses a parallel set of networks, defined by (<net><net>...).
Network *NetworkBuilder::ParseParallel(const StaticShape &input_shape, const char **str) {
Parallel *parallel = new Parallel("Parallel", NT_PARALLEL);
auto *parallel = new Parallel("Parallel", NT_PARALLEL);
++*str;
Network *network = nullptr;
while (**str != '\0' && **str != ')' &&
@ -204,7 +204,7 @@ Network *NetworkBuilder::ParseR(const StaticShape &input_shape, const char **str
tprintf("Invalid R spec!:%s\n", end);
return nullptr;
}
Parallel *parallel = new Parallel("Replicated", NT_REPLICATED);
auto *parallel = new Parallel("Replicated", NT_REPLICATED);
const char *str_copy = *str;
for (int i = 0; i < replicas; ++i) {
str_copy = *str;
@ -284,8 +284,8 @@ Network *NetworkBuilder::ParseC(const StaticShape &input_shape, const char **str
// be slid over all batch,y,x.
return new FullyConnected("Conv1x1", input_shape.depth(), d, type);
}
Series *series = new Series("ConvSeries");
Convolve *convolve = new Convolve("Convolve", input_shape.depth(), x / 2, y / 2);
auto *series = new Series("ConvSeries");
auto *convolve = new Convolve("Convolve", input_shape.depth(), x / 2, y / 2);
series->AddToStack(convolve);
StaticShape fc_input = convolve->OutputShape(input_shape);
series->AddToStack(new FullyConnected("ConvNL", fc_input.depth(), d, type));
@ -358,13 +358,13 @@ Network *NetworkBuilder::ParseLSTM(const StaticShape &input_shape, const char **
std::string name(spec_start, *str - spec_start);
lstm = new LSTM(name, input_shape.depth(), num_states, num_outputs, false, type);
if (dir != 'f') {
Reversed *rev = new Reversed("RevLSTM", NT_XREVERSED);
auto *rev = new Reversed("RevLSTM", NT_XREVERSED);
rev->SetNetwork(lstm);
lstm = rev;
}
if (dir == 'b') {
name += "LTR";
Parallel *parallel = new Parallel("BidiLSTM", NT_PAR_RL_LSTM);
auto *parallel = new Parallel("BidiLSTM", NT_PAR_RL_LSTM);
parallel->AddToStack(
new LSTM(name, input_shape.depth(), num_states, num_outputs, false, type));
parallel->AddToStack(lstm);
@ -372,7 +372,7 @@ Network *NetworkBuilder::ParseLSTM(const StaticShape &input_shape, const char **
}
}
if (dim == 'y') {
Reversed *rev = new Reversed("XYTransLSTM", NT_XYTRANSPOSE);
auto *rev = new Reversed("XYTransLSTM", NT_XYTRANSPOSE);
rev->SetNetwork(lstm);
lstm = rev;
}
@ -381,14 +381,14 @@ Network *NetworkBuilder::ParseLSTM(const StaticShape &input_shape, const char **
// Builds a set of 4 lstms with x and y reversal, running in true parallel.
Network *NetworkBuilder::BuildLSTMXYQuad(int num_inputs, int num_states) {
Parallel *parallel = new Parallel("2DLSTMQuad", NT_PAR_2D_LSTM);
auto *parallel = new Parallel("2DLSTMQuad", NT_PAR_2D_LSTM);
parallel->AddToStack(new LSTM("L2DLTRDown", num_inputs, num_states, num_states, true, NT_LSTM));
Reversed *rev = new Reversed("L2DLTRXRev", NT_XREVERSED);
auto *rev = new Reversed("L2DLTRXRev", NT_XREVERSED);
rev->SetNetwork(new LSTM("L2DRTLDown", num_inputs, num_states, num_states, true, NT_LSTM));
parallel->AddToStack(rev);
rev = new Reversed("L2DRTLYRev", NT_YREVERSED);
rev->SetNetwork(new LSTM("L2DRTLUp", num_inputs, num_states, num_states, true, NT_LSTM));
Reversed *rev2 = new Reversed("L2DXRevU", NT_XREVERSED);
auto *rev2 = new Reversed("L2DXRevU", NT_XREVERSED);
rev2->SetNetwork(rev);
parallel->AddToStack(rev2);
rev = new Reversed("L2DXRevY", NT_YREVERSED);
@ -409,7 +409,7 @@ static Network *BuildFullyConnected(const StaticShape &input_shape, NetworkType
int input_depth = input_size * input_shape.depth();
Network *fc = new FullyConnected(name, input_depth, depth, type);
if (input_size > 1) {
Series *series = new Series("FCSeries");
auto *series = new Series("FCSeries");
series->AddToStack(
new Reconfig("FCReconfig", input_shape.depth(), input_shape.width(), input_shape.height()));
series->AddToStack(fc);
@ -478,7 +478,7 @@ Network *NetworkBuilder::ParseOutput(const StaticShape &input_shape, const char
int input_depth = input_size * input_shape.depth();
Network *fc = new FullyConnected("Output", input_depth, depth, type);
if (input_size > 1) {
Series *series = new Series("FCSeries");
auto *series = new Series("FCSeries");
series->AddToStack(new Reconfig("FCReconfig", input_shape.depth(), 1, input_shape.height()));
series->AddToStack(fc);
fc = series;

View File

@ -430,8 +430,7 @@ int TrainingSampleSet::ReliablySeparable(int font_id1, int class_id1, int font_i
return canonical2.size(); // There are no cloud features.
// Find a canonical2 feature that is not in cloud1.
for (int f = 0; f < canonical2.size(); ++f) {
const int feature = canonical2[f];
for (int feature : canonical2) {
if (cloud1[feature])
continue;
// Gather the near neighbours of f.
@ -488,8 +487,8 @@ float TrainingSampleSet::GetCanonicalDist(int font_id, int class_id) const {
// Generates indexed features for all samples with the supplied feature_space.
void TrainingSampleSet::IndexFeatures(const IntFeatureSpace &feature_space) {
for (int s = 0; s < samples_.size(); ++s)
samples_[s]->IndexFeatures(feature_space);
for (auto &sample : samples_)
sample->IndexFeatures(feature_space);
}
// Marks the given sample index for deletion.
@ -560,8 +559,8 @@ void TrainingSampleSet::OrganizeByFontAndClass() {
void TrainingSampleSet::SetupFontIdMap() {
// Number of samples for each font_id.
std::vector<int> font_counts;
for (int s = 0; s < samples_.size(); ++s) {
const int font_id = samples_[s]->font_id();
for (auto &sample : samples_) {
const int font_id = sample->font_id();
while (font_id >= font_counts.size())
font_counts.push_back(0);
++font_counts[font_id];
@ -618,8 +617,7 @@ void TrainingSampleSet::ComputeCanonicalSamples(const IntFeatureMap &map, bool d
// reasonably fast because f_table.FeatureDistance is fast, but we
// may have to reconsider if we start playing with too many samples
// of a single char/font.
for (int j = 0; j < fcinfo.samples.size(); ++j) {
int s2 = fcinfo.samples[j];
for (int s2 : fcinfo.samples) {
if (samples_[s2]->class_id() != c || samples_[s2]->font_id() != font_id || s2 == s1)
continue;
std::vector<int> features2 = samples_[s2]->indexed_features();
@ -733,8 +731,8 @@ void TrainingSampleSet::ComputeCloudFeatures(int feature_space_size) {
for (int s = 0; s < num_samples; ++s) {
const TrainingSample *sample = GetSample(font_id, c, s);
const std::vector<int> &sample_features = sample->indexed_features();
for (int i = 0; i < sample_features.size(); ++i)
fcinfo.cloud_features.SetBit(sample_features[i]);
for (int sample_feature : sample_features)
fcinfo.cloud_features.SetBit(sample_feature);
}
}
}
@ -761,8 +759,8 @@ void TrainingSampleSet::DisplaySamplesWithFeature(int f_index, const Shape &shap
if (shape.ContainsUnichar(sample->class_id())) {
std::vector<int> indexed_features;
space.IndexAndSortFeatures(sample->features(), sample->num_features(), &indexed_features);
for (int f = 0; f < indexed_features.size(); ++f) {
if (indexed_features[f] == f_index) {
for (int indexed_feature : indexed_features) {
if (indexed_feature == f_index) {
sample->DisplayFeatures(color, window);
}
}

View File

@ -58,7 +58,7 @@ static void DisplayProtoList(const char *ch, LIST protolist) {
auto window = std::make_unique<ScrollView>("Char samples", 50, 200, 520, 520, 260, 260, true);
LIST proto = protolist;
iterate(proto) {
PROTOTYPE *prototype = reinterpret_cast<PROTOTYPE *>(first_node(proto));
auto *prototype = reinterpret_cast<PROTOTYPE *>(first_node(proto));
if (prototype->Significant)
window->Pen(ScrollView::GREEN);
else if (prototype->NumSamples == 0)
@ -70,8 +70,8 @@ static void DisplayProtoList(const char *ch, LIST protolist) {
float x = CenterX(prototype->Mean);
float y = CenterY(prototype->Mean);
double angle = OrientationOf(prototype->Mean) * 2 * M_PI;
float dx = static_cast<float>(LengthOf(prototype->Mean) * cos(angle) / 2);
float dy = static_cast<float>(LengthOf(prototype->Mean) * sin(angle) / 2);
auto dx = static_cast<float>(LengthOf(prototype->Mean) * cos(angle) / 2);
auto dy = static_cast<float>(LengthOf(prototype->Mean) * sin(angle) / 2);
window->SetCursor((x - dx) * 256, (y - dy) * 256);
window->DrawTo((x + dx) * 256, (y + dy) * 256);
if (prototype->Significant)
@ -113,7 +113,7 @@ static LIST ClusterOneConfig(int shape_id, const char *class_label, LIST mf_clas
merge_class->Class->font_set.push_back(shape_id);
LIST proto_it = proto_list;
iterate(proto_it) {
PROTOTYPE *prototype = reinterpret_cast<PROTOTYPE *>(first_node(proto_it));
auto *prototype = reinterpret_cast<PROTOTYPE *>(first_node(proto_it));
// See if proto can be approximated by existing proto.
int p_id = FindClosestExistingProto(merge_class->Class, merge_class->NumMerged, prototype);
if (p_id == NO_PROTO) {

View File

@ -54,8 +54,8 @@ void BoxChar::GetDirection(int *num_rtl, int *num_ltr) const {
std::vector<char32> uni_vector = UNICHAR::UTF8ToUTF32(ch_.c_str());
if (uni_vector.empty()) {
tprintf("Illegal utf8 in boxchar string:%s = ", ch_.c_str());
for (size_t c = 0; c < ch_.size(); ++c) {
tprintf(" 0x%x", ch_[c]);
for (char c : ch_) {
tprintf(" 0x%x", c);
}
tprintf("\n");
return;
@ -81,8 +81,8 @@ void BoxChar::ReverseUnicodesInBox() {
/* static */
void BoxChar::TranslateBoxes(int xshift, int yshift, std::vector<BoxChar *> *boxes) {
for (size_t i = 0; i < boxes->size(); ++i) {
BOX *box = (*boxes)[i]->box_;
for (auto &boxe : *boxes) {
BOX *box = boxe->box_;
if (box != nullptr) {
box->x += xshift;
box->y += yshift;
@ -154,7 +154,7 @@ void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules, std::vector<Bo
}
if (prev_i + 1 == i) {
// New character needed.
BoxChar *new_box = new BoxChar("\t", 1);
auto *new_box = new BoxChar("\t", 1);
new_box->AddBox(x, y, width, height);
new_box->page_ = (*boxes)[i]->page_;
boxes->insert(boxes->begin() + i, new_box);
@ -257,8 +257,8 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar *> *boxes) {
/* static */
bool BoxChar::ContainsMostlyRTL(const std::vector<BoxChar *> &boxes) {
int num_rtl = 0, num_ltr = 0;
for (size_t i = 0; i < boxes.size(); ++i) {
boxes[i]->GetDirection(&num_rtl, &num_ltr);
for (auto boxe : boxes) {
boxe->GetDirection(&num_rtl, &num_ltr);
}
return num_rtl > num_ltr;
}
@ -285,8 +285,8 @@ bool BoxChar::MostlyVertical(const std::vector<BoxChar *> &boxes) {
/* static */
int BoxChar::TotalByteLength(const std::vector<BoxChar *> &boxes) {
int total_length = 0;
for (size_t i = 0; i < boxes.size(); ++i)
total_length += boxes[i]->ch_.size();
for (auto boxe : boxes)
total_length += boxe->ch_.size();
return total_length;
}
@ -324,15 +324,14 @@ void BoxChar::WriteTesseractBoxFile(const std::string &filename, int height,
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_;
for (auto boxe : boxes) {
const Box *box = boxe->box_;
if (box == nullptr) {
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
return "";
}
int nbytes =
snprintf(buffer, kMaxLineLength, "%s %d %d %d %d %d\n", boxes[i]->ch_.c_str(), box->x,
height - box->y - box->h, box->x + box->w, height - box->y, boxes[i]->page_);
int nbytes = snprintf(buffer, kMaxLineLength, "%s %d %d %d %d %d\n", boxe->ch_.c_str(), box->x,
height - box->y - box->h, box->x + box->w, height - box->y, boxe->page_);
output.append(buffer, nbytes);
}
return output;

View File

@ -114,7 +114,7 @@ std::string LigatureTable::RemoveLigatures(const std::string &str) const {
for (UNICHAR::const_iterator it = it_begin; it != it_end; ++it) {
len = it.get_utf8(tmp);
tmp[len] = '\0';
LigHash::const_iterator lig_it = lig_to_norm_table_.find(tmp);
auto lig_it = lig_to_norm_table_.find(tmp);
if (lig_it != lig_to_norm_table_.end()) {
result += lig_it->second;
} else {
@ -159,7 +159,7 @@ std::string LigatureTable::AddLigatures(const std::string &str, const PangoFontI
for (int liglen = max_norm_length_; liglen >= min_norm_length_; --liglen) {
if (i + liglen <= len) {
std::string lig_cand = str.substr(i, liglen);
LigHash::const_iterator it = norm_to_lig_table_.find(lig_cand);
auto it = norm_to_lig_table_.find(lig_cand);
if (it != norm_to_lig_table_.end()) {
tlog(3, "Considering %s -> %s\n", lig_cand.c_str(), it->second.c_str());
if (font) {

View File

@ -71,8 +71,8 @@ protected:
int max_norm_length_;
private:
LigatureTable(const LigatureTable &);
void operator=(const LigatureTable &);
LigatureTable(const LigatureTable &) = delete;
void operator=(const LigatureTable &) = delete;
};
} // namespace tesseract

View File

@ -552,7 +552,7 @@ const std::vector<std::string> &FontUtils::ListAvailableFonts() {
char *desc_str = pango_font_description_to_string(desc);
// "synthesized" font faces that are not truly loadable, so we skip it
if (!pango_font_face_is_synthesized(faces[j]) && IsAvailableFont(desc_str)) {
available_fonts_.push_back(desc_str);
available_fonts_.emplace_back(desc_str);
}
pango_font_description_free(desc);
g_free(desc_str);
@ -583,14 +583,13 @@ int FontUtils::FontScore(const std::unordered_map<char32, int64_t> &ch_map,
}
*raw_score = 0;
int ok_chars = 0;
for (std::unordered_map<char32, int64_t>::const_iterator it = ch_map.begin(); it != ch_map.end();
++it) {
bool covered = (coverage != nullptr) &&
(IsWhitespace(it->first) ||
(pango_coverage_get(coverage, it->first) == PANGO_COVERAGE_EXACT));
for (auto it : ch_map) {
bool covered =
(coverage != nullptr) && (IsWhitespace(it.first) ||
(pango_coverage_get(coverage, it.first) == PANGO_COVERAGE_EXACT));
if (covered) {
++(*raw_score);
ok_chars += it->second;
ok_chars += it.second;
}
if (ch_flags) {
ch_flags->push_back(covered);
@ -616,10 +615,10 @@ std::string FontUtils::BestFonts(const std::unordered_map<char32, int64_t> &ch_m
int most_ok_chars = 0;
int best_raw_score = 0;
const std::vector<std::string> &font_names = FontUtils::ListAvailableFonts();
for (unsigned i = 0; i < font_names.size(); ++i) {
for (const auto &font_name : font_names) {
std::vector<bool> ch_flags;
int raw_score = 0;
int ok_chars = FontScore(ch_map, font_names[i], &raw_score, &ch_flags);
int ok_chars = FontScore(ch_map, font_name, &raw_score, &ch_flags);
most_ok_chars = std::max(ok_chars, most_ok_chars);
best_raw_score = std::max(raw_score, best_raw_score);
@ -672,16 +671,16 @@ bool FontUtils::SelectFont(const char *utf8_word, const int utf8_len,
font_name->clear();
if (graphemes)
graphemes->clear();
for (unsigned i = 0; i < all_fonts.size(); ++i) {
for (const auto &all_font : all_fonts) {
PangoFontInfo font;
std::vector<std::string> found_graphemes;
ASSERT_HOST_MSG(font.ParseFontDescriptionName(all_fonts[i]),
"Could not parse font desc name %s\n", all_fonts[i].c_str());
ASSERT_HOST_MSG(font.ParseFontDescriptionName(all_font), "Could not parse font desc name %s\n",
all_font.c_str());
if (font.CanRenderString(utf8_word, utf8_len, &found_graphemes)) {
if (graphemes)
graphemes->swap(found_graphemes);
if (font_name)
*font_name = all_fonts[i];
*font_name = all_font;
return true;
}
}

View File

@ -144,8 +144,8 @@ private:
static std::string cache_dir_;
private:
PangoFontInfo(const PangoFontInfo &);
void operator=(const PangoFontInfo &);
PangoFontInfo(const PangoFontInfo &) = delete;
void operator=(const PangoFontInfo &) = delete;
};
// Static utility methods for querying font availability and font-selection

View File

@ -336,8 +336,8 @@ void StringRenderer::RotatePageBoxes(float rotation) {
}
void StringRenderer::ClearBoxes() {
for (size_t i = 0; i < boxchars_.size(); ++i)
delete boxchars_[i];
for (auto &boxchar : boxchars_)
delete boxchar;
boxchars_.clear();
boxaDestroy(&page_boxes_);
}
@ -388,8 +388,7 @@ bool StringRenderer::GetClusterStrings(std::vector<std::string> *cluster_text) {
pango_layout_iter_free(run_iter);
cluster_text->clear();
for (std::map<int, std::string>::const_iterator it = start_byte_to_text.begin();
it != start_byte_to_text.end(); ++it) {
for (auto it = start_byte_to_text.begin(); it != start_byte_to_text.end(); ++it) {
cluster_text->push_back(it->second);
}
return !cluster_text->empty();
@ -408,10 +407,10 @@ bool StringRenderer::GetClusterStrings(std::vector<std::string> *cluster_text) {
static void MergeBoxCharsToWords(std::vector<BoxChar *> *boxchars) {
std::vector<BoxChar *> result;
bool started_word = false;
for (size_t i = 0; i < boxchars->size(); ++i) {
if (boxchars->at(i)->ch() == " " || boxchars->at(i)->box() == nullptr) {
result.push_back(boxchars->at(i));
boxchars->at(i) = nullptr;
for (auto &boxchar : *boxchars) {
if (boxchar->ch() == " " || boxchar->box() == nullptr) {
result.push_back(boxchar);
boxchar = nullptr;
started_word = false;
continue;
}
@ -419,12 +418,12 @@ static void MergeBoxCharsToWords(std::vector<BoxChar *> *boxchars) {
if (!started_word) {
// Begin new word
started_word = true;
result.push_back(boxchars->at(i));
boxchars->at(i) = nullptr;
result.push_back(boxchar);
boxchar = nullptr;
} else {
BoxChar *last_boxchar = result.back();
// Compute bounding box union
const Box *box = boxchars->at(i)->box();
const Box *box = boxchar->box();
Box *last_box = last_boxchar->mutable_box();
int left = std::min(last_box->x, box->x);
int right = std::max(last_box->x + last_box->w, box->x + box->w);
@ -438,18 +437,18 @@ static void MergeBoxCharsToWords(std::vector<BoxChar *> *boxchars) {
// Insert a fake interword space and start a new word with the current
// boxchar.
result.push_back(new BoxChar(" ", 1));
result.push_back(boxchars->at(i));
boxchars->at(i) = nullptr;
result.push_back(boxchar);
boxchar = nullptr;
continue;
}
// Append to last word
last_boxchar->mutable_ch()->append(boxchars->at(i)->ch());
last_boxchar->mutable_ch()->append(boxchar->ch());
last_box->x = left;
last_box->w = right - left;
last_box->y = top;
last_box->h = bottom - top;
delete boxchars->at(i);
boxchars->at(i) = nullptr;
delete boxchar;
boxchar = nullptr;
}
}
boxchars->swap(result);
@ -495,7 +494,7 @@ void StringRenderer::ComputeClusterBoxes() {
if (!cluster_rect.width || !cluster_rect.height || IsUTF8Whitespace(cluster_text.c_str())) {
tlog(2, "Skipping whitespace with boxdim (%d,%d) '%s'\n", cluster_rect.width,
cluster_rect.height, cluster_text.c_str());
BoxChar *boxchar = new BoxChar(" ", 1);
auto *boxchar = new BoxChar(" ", 1);
boxchar->set_page(page_);
start_byte_to_box[start_byte_index] = boxchar;
continue;
@ -519,7 +518,7 @@ void StringRenderer::ComputeClusterBoxes() {
// decided to use an unmapped glyph.
cluster_text = LigatureTable::Get()->AddLigatures(cluster_text, nullptr);
}
BoxChar *boxchar = new BoxChar(cluster_text.c_str(), cluster_text.size());
auto *boxchar = new BoxChar(cluster_text.c_str(), cluster_text.size());
boxchar->set_page(page_);
boxchar->AddBox(cluster_rect.x, cluster_rect.y, cluster_rect.width, cluster_rect.height);
start_byte_to_box[start_byte_index] = boxchar;
@ -536,8 +535,7 @@ void StringRenderer::ComputeClusterBoxes() {
if (GetClusterStrings(&cluster_text)) {
ASSERT_HOST(cluster_text.size() == start_byte_to_box.size());
int ind = 0;
for (std::map<int, BoxChar *>::iterator it = start_byte_to_box.begin();
it != start_byte_to_box.end(); ++it, ++ind) {
for (auto it = start_byte_to_box.begin(); it != start_byte_to_box.end(); ++it, ++ind) {
it->second->mutable_ch()->swap(cluster_text[ind]);
}
}
@ -546,8 +544,7 @@ void StringRenderer::ComputeClusterBoxes() {
std::vector<BoxChar *> page_boxchars;
page_boxchars.reserve(start_byte_to_box.size());
std::string last_ch;
for (std::map<int, BoxChar *>::const_iterator it = start_byte_to_box.begin();
it != start_byte_to_box.end(); ++it) {
for (auto it = start_byte_to_box.begin(); it != start_byte_to_box.end(); ++it) {
if (it->second->ch() == kWordJoinerUTF8) {
// Skip zero-width joiner characters (ZWJs) here.
delete it->second;
@ -558,11 +555,10 @@ void StringRenderer::ComputeClusterBoxes() {
CorrectBoxPositionsToLayout(&page_boxchars);
if (render_fullwidth_latin_) {
for (std::map<int, BoxChar *>::iterator it = start_byte_to_box.begin();
it != start_byte_to_box.end(); ++it) {
for (auto &it : start_byte_to_box) {
// Convert fullwidth Latin characters to their halfwidth forms.
std::string half(ConvertFullwidthLatinToBasicLatin(it->second->ch()));
it->second->mutable_ch()->swap(half);
std::string half(ConvertFullwidthLatinToBasicLatin(it.second->ch()));
it.second->mutable_ch()->swap(half);
}
}
@ -576,12 +572,12 @@ void StringRenderer::ComputeClusterBoxes() {
// Compute the page bounding box
Box *page_box = nullptr;
Boxa *all_boxes = nullptr;
for (size_t i = 0; i < page_boxchars.size(); ++i) {
if (page_boxchars[i]->box() == nullptr)
for (auto &page_boxchar : page_boxchars) {
if (page_boxchar->box() == nullptr)
continue;
if (all_boxes == nullptr)
all_boxes = boxaCreate(0);
boxaAddBox(all_boxes, page_boxchars[i]->mutable_box(), L_CLONE);
boxaAddBox(all_boxes, page_boxchar->mutable_box(), L_CLONE);
}
if (all_boxes != nullptr) {
boxaGetExtent(all_boxes, nullptr, nullptr, &page_box);

View File

@ -224,8 +224,8 @@ protected:
int last_offset_; // Offset returned from last successful rendering
private:
StringRenderer(const StringRenderer &);
void operator=(const StringRenderer &);
StringRenderer(const StringRenderer &) = delete;
void operator=(const StringRenderer &) = delete;
};
} // namespace tesseract

View File

@ -561,7 +561,7 @@ static int Main() {
int offset = SpanUTF8Whitespace(str8);
while (offset < len) {
step = SpanUTF8NotWhitespace(str8 + offset);
offsets.push_back(std::make_pair(offset, step));
offsets.emplace_back(offset, step);
offset += step;
offset += SpanUTF8Whitespace(str8 + offset);
}
@ -694,8 +694,8 @@ static int Main() {
if (fp == nullptr) {
tprintf("Failed to create output font list %s\n", filename.c_str());
} else {
for (size_t i = 0; i < font_names.size(); ++i) {
fprintf(fp, "%s\n", font_names[i].c_str());
for (auto &font_name : font_names) {
fprintf(fp, "%s\n", font_name.c_str());
}
fclose(fp);
}

View File

@ -44,19 +44,19 @@ namespace tesseract {
class IcuErrorCode : public icu::ErrorCode {
public:
IcuErrorCode() {}
virtual ~IcuErrorCode();
IcuErrorCode() = default;
~IcuErrorCode() override;
protected:
virtual void handleFailure() const {
void handleFailure() const override {
tprintf("ICU ERROR: %s\n", errorName());
exit(errorCode);
}
private:
// Disallow implicit copying of object.
IcuErrorCode(const IcuErrorCode &);
void operator=(const IcuErrorCode &);
IcuErrorCode(const IcuErrorCode &) = delete;
void operator=(const IcuErrorCode &) = delete;
};
} // namespace tesseract

View File

@ -1233,9 +1233,9 @@ double LSTMTrainer::ComputeWordError(std::string *truth_str, std::string *ocr_st
--it->second;
}
int word_recall_errs = 0;
for (StrMap::const_iterator it = word_counts.begin(); it != word_counts.end(); ++it) {
if (it->second > 0)
word_recall_errs += it->second;
for (const auto &word_count : word_counts) {
if (word_count.second > 0)
word_recall_errs += word_count.second;
}
return static_cast<double>(word_recall_errs) / truth_words.size();
}

View File

@ -46,8 +46,8 @@ static bool is_hyphen_punc(const char32 ch) {
0xfe63, // small hyphen-minus
0xff0d, // fullwidth hyphen-minus
};
for (int i = 0; i < kNumHyphenPuncUnicodes; ++i) {
if (kHyphenPuncUnicodes[i] == ch)
for (int kHyphenPuncUnicode : kHyphenPuncUnicodes) {
if (kHyphenPuncUnicode == ch)
return true;
}
return false;
@ -65,8 +65,8 @@ static bool is_single_quote(const char32 ch) {
0x300C, // left corner bracket (East Asian languages)
0xFF07, // fullwidth apostrophe
};
for (int i = 0; i < kNumSingleQuoteUnicodes; ++i) {
if (kSingleQuoteUnicodes[i] == ch)
for (int kSingleQuoteUnicode : kSingleQuoteUnicodes) {
if (kSingleQuoteUnicode == ch)
return true;
}
return false;
@ -85,8 +85,8 @@ static bool is_double_quote(const char32 ch) {
0x301E, // close double prime (East Asian languages written horizontally)
0xFF02, // fullwidth quotation mark
};
for (int i = 0; i < kNumDoubleQuoteUnicodes; ++i) {
if (kDoubleQuoteUnicodes[i] == ch)
for (int kDoubleQuoteUnicode : kDoubleQuoteUnicodes) {
if (kDoubleQuoteUnicode == ch)
return true;
}
return false;

View File

@ -10,7 +10,7 @@ namespace tesseract {
class ValidateGrapheme : public Validator {
public:
ValidateGrapheme(ViramaScript script, bool report_errors) : Validator(script, report_errors) {}
~ValidateGrapheme() {}
~ValidateGrapheme() override = default;
protected:
// Consumes the next Grapheme in codes_[codes_used_++...] and copies it to

View File

@ -10,7 +10,7 @@ namespace tesseract {
class ValidateIndic : public Validator {
public:
ValidateIndic(ViramaScript script, bool report_errors) : Validator(script, report_errors) {}
~ValidateIndic() {}
~ValidateIndic() override = default;
protected:
// Returns whether codes matches the pattern for an Indic Grapheme.

View File

@ -28,7 +28,7 @@ namespace tesseract {
class ValidateJavanese : public Validator {
public:
ValidateJavanese(ViramaScript script, bool report_errors) : Validator(script, report_errors) {}
~ValidateJavanese() {}
~ValidateJavanese() override = default;
protected:
// Returns whether codes matches the pattern for an Javanese Grapheme.

View File

@ -9,7 +9,7 @@ namespace tesseract {
class ValidateKhmer : public Validator {
public:
ValidateKhmer(ViramaScript script, bool report_errors) : Validator(script, report_errors) {}
~ValidateKhmer() {}
~ValidateKhmer() override = default;
protected:
// Returns whether codes matches the pattern for an Khmer Grapheme.

View File

@ -9,7 +9,7 @@ namespace tesseract {
class ValidateMyanmar : public Validator {
public:
ValidateMyanmar(ViramaScript script, bool report_errors) : Validator(script, report_errors) {}
~ValidateMyanmar() {}
~ValidateMyanmar() override = default;
protected:
// Returns whether codes matches the pattern for a Myanmar Grapheme.

View File

@ -148,7 +148,7 @@ ViramaScript Validator::MostFrequentViramaScript(const std::vector<char32> &utf3
}
if (!histogram.empty()) {
int base = std::max_element(histogram.begin(), histogram.end(), CmpPairSecond)->first;
char32 codebase = static_cast<char32>(base * kIndicCodePageSize);
auto codebase = static_cast<char32>(base * kIndicCodePageSize);
// Check for validity.
if (codebase == static_cast<char32>(ViramaScript::kMyanmar) ||
codebase == static_cast<char32>(ViramaScript::kJavanese) ||
@ -187,7 +187,7 @@ bool Validator::IsSubscriptScript() const {
void Validator::ComputeClassCodes(const std::vector<char32> &text) {
codes_.reserve(text.size());
for (char32 c : text) {
codes_.push_back(std::make_pair(UnicodeToCharClass(c), c));
codes_.emplace_back(UnicodeToCharClass(c), c);
}
}

View File

@ -42,11 +42,11 @@ namespace tesseract {
// adds the segmented parts to unicharset.
static void AddStringsToUnicharset(const std::vector<std::string> &strings, int norm_mode,
UNICHARSET *unicharset) {
for (int i = 0; i < strings.size(); ++i) {
for (const auto &string : strings) {
std::vector<std::string> normalized;
if (NormalizeCleanAndSegmentUTF8(UnicodeNormMode::kNFC, OCRNorm::kNone,
static_cast<GraphemeNormMode>(norm_mode),
/*report_errors*/ true, strings[i].c_str(), &normalized)) {
/*report_errors*/ true, string.c_str(), &normalized)) {
for (const std::string &normed : normalized) {
// normed is a UTF-8 encoded string
if (normed.empty() || IsUTF8Whitespace(normed.c_str()))
@ -54,7 +54,7 @@ static void AddStringsToUnicharset(const std::vector<std::string> &strings, int
unicharset->unichar_insert(normed.c_str());
}
} else {
tprintf("Normalization failed for string '%s'\n", strings[i].c_str());
tprintf("Normalization failed for string '%s'\n", string.c_str());
}
}
}

View File

@ -52,7 +52,7 @@ SVMenuNode::SVMenuNode() {
is_check_box_entry_ = false;
}
SVMenuNode::~SVMenuNode() {}
SVMenuNode::~SVMenuNode() = default;
// Create a new sub menu node with just a caption. This is used to create
// nodes which act as parent nodes to other nodes (e.g. submenus).

View File

@ -271,10 +271,10 @@ SEAM *Wordrec::chop_overlapping_blob(const std::vector<TBOX> &boxes, bool italic
bool almost_equal_box = false;
int num_overlap = 0;
for (int i = 0; i < boxes.size(); i++) {
if (original_box.overlap_fraction(boxes[i]) > 0.125)
for (auto boxe : boxes) {
if (original_box.overlap_fraction(boxe) > 0.125)
num_overlap++;
if (original_box.almost_equal(boxes[i], 3))
if (original_box.almost_equal(boxe, 3))
almost_equal_box = true;
}
@ -585,10 +585,9 @@ int Wordrec::select_blob_to_split(const std::vector<BLOB_CHOICE *> &blob_choices
int Wordrec::select_blob_to_split_from_fixpt(DANGERR *fixpt) {
if (!fixpt)
return -1;
for (int i = 0; i < fixpt->size(); i++) {
if ((*fixpt)[i].begin + 1 == (*fixpt)[i].end && (*fixpt)[i].dangerous &&
(*fixpt)[i].correct_is_ngram) {
return (*fixpt)[i].begin;
for (auto &i : *fixpt) {
if (i.begin + 1 == i.end && i.dangerous && i.correct_is_ngram) {
return i.begin;
}
}
return -1;

View File

@ -128,8 +128,7 @@ void LMPainPoints::GenerateFromAmbigs(const DANGERR &fixpt, ViterbiStateEntry *v
WERD_RES *word_res) {
// Begins and ends in DANGERR vector now record the blob indices as used
// by the ratings matrix.
for (int d = 0; d < fixpt.size(); ++d) {
const DANGERR_INFO &danger = fixpt[d];
for (auto danger : fixpt) {
// Only use dangerous ambiguities.
if (danger.dangerous) {
GeneratePainPoint(danger.begin, danger.end - 1, LM_PPTYPE_AMBIG, vse->cost, true,

View File

@ -70,7 +70,7 @@ public:
, fixed_pitch_(fp)
, dict_(d)
, debug_level_(deb) {}
~LMPainPoints() {}
~LMPainPoints() = default;
// Returns true if the heap of pain points of pp_type is not empty().
inline bool HasPainPoints(LMPainPointsType pp_type) const {

View File

@ -202,8 +202,7 @@ struct LanguageModelState {
: viterbi_state_entries_prunable_length(0)
, viterbi_state_entries_prunable_max_cost(FLT_MAX)
, viterbi_state_entries_length(0) {}
~LanguageModelState() {
}
~LanguageModelState() = default;
/// Clears the viterbi search state back to its initial conditions.
void Clear();

View File

@ -281,8 +281,8 @@ void Wordrec::ResetNGramSearch(WERD_RES *word_res, BestChoiceBundle *best_choice
std::vector<SegSearchPending> *pending) {
// TODO(rays) More refactoring required here.
// Delete existing viterbi states.
for (int col = 0; col < best_choice_bundle->beam.size(); ++col) {
best_choice_bundle->beam[col]->Clear();
for (auto &col : best_choice_bundle->beam) {
col->Clear();
}
// Reset best_choice_bundle.
word_res->ClearWordChoices();

View File

@ -18,6 +18,8 @@
#include "wordrec.h"
#include <memory>
#ifdef DISABLED_LEGACY_ENGINE
# include "params.h"
@ -99,7 +101,7 @@ Wordrec::Wordrec()
params())
, pass2_ok_split(0.0f) {
prev_word_best_choice_ = nullptr;
language_model_.reset(new LanguageModel(&get_fontinfo_table(), &(getDict())));
language_model_ = std::make_unique<LanguageModel>(&get_fontinfo_table(), &(getDict()));
fill_lattice_ = nullptr;
}