Skip to content

Commit 5490081

Browse files
committed
Fix some signed / unsigned mismatches
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 7fca690 commit 5490081

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

src/ccmain/osdetect.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,8 @@ bool OrientationDetector::detect_blob(BLOB_CHOICE_LIST *scores) {
373373
for (choice_it.mark_cycle_pt(); !choice_it.cycled_list() && choice == nullptr;
374374
choice_it.forward()) {
375375
int choice_script = choice_it.data()->script_id();
376-
unsigned s = 0;
377-
for (s = 0; s < allowed_scripts_->size(); ++s) {
378-
if ((*allowed_scripts_)[s] == choice_script) {
376+
for (auto script : *allowed_scripts_) {
377+
if (script == choice_script) {
379378
choice = choice_it.data();
380379
break;
381380
}

src/classify/shapetable.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ namespace tesseract {
3737
// Returns -1 if the unichar_id is not found
3838
int ShapeRating::FirstResultWithUnichar(const std::vector<ShapeRating> &results,
3939
const ShapeTable &shape_table, UNICHAR_ID unichar_id) {
40-
for (unsigned r = 0; r < results.size(); ++r) {
41-
const auto shape_id = results[r].shape_id;
40+
size_t r = 0;
41+
for (const auto &result : results) {
42+
const auto shape_id = result.shape_id;
4243
const Shape &shape = shape_table.GetShape(shape_id);
4344
if (shape.ContainsUnichar(unichar_id)) {
4445
return r;
4546
}
47+
++r;
4648
}
4749
return -1;
4850
}
@@ -53,10 +55,12 @@ int ShapeRating::FirstResultWithUnichar(const std::vector<ShapeRating> &results,
5355
// Returns -1 if the unichar_id is not found
5456
int UnicharRating::FirstResultWithUnichar(const std::vector<UnicharRating> &results,
5557
UNICHAR_ID unichar_id) {
56-
for (unsigned r = 0; r < results.size(); ++r) {
57-
if (results[r].unichar_id == unichar_id) {
58+
size_t r = 0;
59+
for (const auto &result : results) {
60+
if (result.unichar_id == unichar_id) {
5861
return r;
5962
}
63+
++r;
6064
}
6165
return -1;
6266
}
@@ -122,8 +126,8 @@ void Shape::AddToShape(int unichar_id, int font_id) {
122126
// Adds everything in other to this.
123127
void Shape::AddShape(const Shape &other) {
124128
for (const auto &unichar : other.unichars_) {
125-
for (unsigned f = 0; f < unichar.font_ids.size(); ++f) {
126-
AddToShape(unichar.unichar_id, unichar.font_ids[f]);
129+
for (auto font_id : unichar.font_ids) {
130+
AddToShape(unichar.unichar_id, font_id);
127131
}
128132
}
129133
unichars_sorted_ = unichars_.size() <= 1;
@@ -267,7 +271,7 @@ int ShapeTable::NumFonts() const {
267271
for (auto shape_id : shape_table_) {
268272
const Shape &shape = *shape_id;
269273
for (int c = 0; c < shape.size(); ++c) {
270-
for (int font_id : shape[c].font_ids) {
274+
for (auto font_id : shape[c].font_ids) {
271275
if (font_id >= num_fonts_) {
272276
num_fonts_ = font_id + 1;
273277
}
@@ -405,7 +409,7 @@ int ShapeTable::FindShape(int unichar_id, int font_id) const {
405409
if (font_id < 0) {
406410
return s; // We don't care about the font.
407411
}
408-
for (int f : shape[c].font_ids) {
412+
for (auto f : shape[c].font_ids) {
409413
if (f == font_id) {
410414
return s;
411415
}
@@ -428,14 +432,13 @@ void ShapeTable::GetFirstUnicharAndFont(unsigned shape_id, int *unichar_id, int
428432
int ShapeTable::BuildFromShape(const Shape &shape, const ShapeTable &master_shapes) {
429433
BitVector shape_map(master_shapes.NumShapes());
430434
for (int u_ind = 0; u_ind < shape.size(); ++u_ind) {
431-
for (unsigned f_ind = 0; f_ind < shape[u_ind].font_ids.size(); ++f_ind) {
435+
for (auto font_id : shape[u_ind].font_ids) {
432436
int c = shape[u_ind].unichar_id;
433-
int f = shape[u_ind].font_ids[f_ind];
434-
int master_id = master_shapes.FindShape(c, f);
437+
int master_id = master_shapes.FindShape(c, font_id);
435438
if (master_id >= 0) {
436439
shape_map.SetBit(master_id);
437-
} else if (FindShape(c, f) < 0) {
438-
AddShape(c, f);
440+
} else if (FindShape(c, font_id) < 0) {
441+
AddShape(c, font_id);
439442
}
440443
}
441444
}
@@ -630,19 +633,19 @@ bool ShapeTable::MergeEqualUnichars(int merge_id1, int merge_id2, unsigned shape
630633
const Shape &merge2 = GetShape(merge_id2);
631634
const Shape &shape = GetShape(shape_id);
632635
for (int cs = 0; cs < shape.size(); ++cs) {
633-
int unichar_id = shape[cs].unichar_id;
636+
auto unichar_id = shape[cs].unichar_id;
634637
if (!merge1.ContainsUnichar(unichar_id) && !merge2.ContainsUnichar(unichar_id)) {
635638
return false; // Shape has a unichar that appears in neither merge.
636639
}
637640
}
638641
for (int cm1 = 0; cm1 < merge1.size(); ++cm1) {
639-
int unichar_id1 = merge1[cm1].unichar_id;
642+
auto unichar_id1 = merge1[cm1].unichar_id;
640643
if (!shape.ContainsUnichar(unichar_id1)) {
641644
return false; // Merge has a unichar that is not in shape.
642645
}
643646
}
644647
for (int cm2 = 0; cm2 < merge2.size(); ++cm2) {
645-
int unichar_id2 = merge2[cm2].unichar_id;
648+
auto unichar_id2 = merge2[cm2].unichar_id;
646649
if (!shape.ContainsUnichar(unichar_id2)) {
647650
return false; // Merge has a unichar that is not in shape.
648651
}
@@ -655,7 +658,7 @@ bool ShapeTable::CommonUnichars(unsigned shape_id1, unsigned shape_id2) const {
655658
const Shape &shape1 = GetShape(shape_id1);
656659
const Shape &shape2 = GetShape(shape_id2);
657660
for (int c1 = 0; c1 < shape1.size(); ++c1) {
658-
int unichar_id1 = shape1[c1].unichar_id;
661+
auto unichar_id1 = shape1[c1].unichar_id;
659662
if (shape2.ContainsUnichar(unichar_id1)) {
660663
return true;
661664
}
@@ -725,7 +728,7 @@ void ShapeTable::AddShapeToResults(const ShapeRating &shape_rating, std::vector<
725728
for (int u = 0; u < shape.size(); ++u) {
726729
int result_index =
727730
AddUnicharToResults(shape[u].unichar_id, shape_rating.rating, unichar_map, results);
728-
for (int font_id : shape[u].font_ids) {
731+
for (auto font_id : shape[u].font_ids) {
729732
(*results)[result_index].fonts.emplace_back(font_id,
730733
IntCastRounded(shape_rating.rating * INT16_MAX));
731734
}

src/dict/dict.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,9 @@ void Dict::init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode)
612612
if (hyphenated()) {
613613
*active_dawgs = hyphen_active_dawgs_;
614614
if (dawg_debug_level >= 3) {
615-
for (unsigned i = 0; i < hyphen_active_dawgs_.size(); ++i) {
615+
for (const auto &dawg : hyphen_active_dawgs_) {
616616
tprintf("Adding hyphen beginning dawg [%d, " REFFORMAT "]\n",
617-
hyphen_active_dawgs_[i].dawg_index, hyphen_active_dawgs_[i].dawg_ref);
617+
dawg.dawg_index, dawg.dawg_ref);
618618
}
619619
}
620620
} else {
@@ -633,12 +633,12 @@ void Dict::default_dawgs(DawgPositionVector *dawg_pos_vec, bool suppress_pattern
633633
if (dawg_ty == DAWG_TYPE_PUNCTUATION) {
634634
dawg_pos_vec->push_back(DawgPosition(-1, NO_EDGE, i, NO_EDGE, false));
635635
if (dawg_debug_level >= 3) {
636-
tprintf("Adding beginning punc dawg [%d, " REFFORMAT "]\n", i, NO_EDGE);
636+
tprintf("Adding beginning punc dawg [%u, " REFFORMAT "]\n", i, NO_EDGE);
637637
}
638638
} else if (!punc_dawg_available || !subsumed_by_punc) {
639639
dawg_pos_vec->push_back(DawgPosition(i, NO_EDGE, -1, NO_EDGE, false));
640640
if (dawg_debug_level >= 3) {
641-
tprintf("Adding beginning dawg [%d, " REFFORMAT "]\n", i, NO_EDGE);
641+
tprintf("Adding beginning dawg [%u, " REFFORMAT "]\n", i, NO_EDGE);
642642
}
643643
}
644644
}
@@ -900,9 +900,9 @@ bool Dict::valid_punctuation(const WERD_CHOICE &word) {
900900
new_word.append_unichar_id(Dawg::kPatternUnicharID, 1, 0.0, 0.0);
901901
}
902902
}
903-
for (unsigned i = 0; i < dawgs_.size(); ++i) {
904-
if (dawgs_[i] != nullptr && dawgs_[i]->type() == DAWG_TYPE_PUNCTUATION &&
905-
dawgs_[i]->word_in_dawg(new_word)) {
903+
for (auto dawg : dawgs_) {
904+
if (dawg != nullptr && dawg->type() == DAWG_TYPE_PUNCTUATION &&
905+
dawg->word_in_dawg(new_word)) {
906906
return true;
907907
}
908908
}

0 commit comments

Comments
 (0)