@@ -37,12 +37,14 @@ namespace tesseract {
37
37
// Returns -1 if the unichar_id is not found
38
38
int ShapeRating::FirstResultWithUnichar (const std::vector<ShapeRating> &results,
39
39
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 ;
42
43
const Shape &shape = shape_table.GetShape (shape_id);
43
44
if (shape.ContainsUnichar (unichar_id)) {
44
45
return r;
45
46
}
47
+ ++r;
46
48
}
47
49
return -1 ;
48
50
}
@@ -53,10 +55,12 @@ int ShapeRating::FirstResultWithUnichar(const std::vector<ShapeRating> &results,
53
55
// Returns -1 if the unichar_id is not found
54
56
int UnicharRating::FirstResultWithUnichar (const std::vector<UnicharRating> &results,
55
57
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) {
58
61
return r;
59
62
}
63
+ ++r;
60
64
}
61
65
return -1 ;
62
66
}
@@ -122,8 +126,8 @@ void Shape::AddToShape(int unichar_id, int font_id) {
122
126
// Adds everything in other to this.
123
127
void Shape::AddShape (const Shape &other) {
124
128
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 );
127
131
}
128
132
}
129
133
unichars_sorted_ = unichars_.size () <= 1 ;
@@ -267,7 +271,7 @@ int ShapeTable::NumFonts() const {
267
271
for (auto shape_id : shape_table_) {
268
272
const Shape &shape = *shape_id;
269
273
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 ) {
271
275
if (font_id >= num_fonts_) {
272
276
num_fonts_ = font_id + 1 ;
273
277
}
@@ -405,7 +409,7 @@ int ShapeTable::FindShape(int unichar_id, int font_id) const {
405
409
if (font_id < 0 ) {
406
410
return s; // We don't care about the font.
407
411
}
408
- for (int f : shape[c].font_ids ) {
412
+ for (auto f : shape[c].font_ids ) {
409
413
if (f == font_id) {
410
414
return s;
411
415
}
@@ -428,14 +432,13 @@ void ShapeTable::GetFirstUnicharAndFont(unsigned shape_id, int *unichar_id, int
428
432
int ShapeTable::BuildFromShape (const Shape &shape, const ShapeTable &master_shapes) {
429
433
BitVector shape_map (master_shapes.NumShapes ());
430
434
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 ) {
432
436
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);
435
438
if (master_id >= 0 ) {
436
439
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 );
439
442
}
440
443
}
441
444
}
@@ -630,19 +633,19 @@ bool ShapeTable::MergeEqualUnichars(int merge_id1, int merge_id2, unsigned shape
630
633
const Shape &merge2 = GetShape (merge_id2);
631
634
const Shape &shape = GetShape (shape_id);
632
635
for (int cs = 0 ; cs < shape.size (); ++cs) {
633
- int unichar_id = shape[cs].unichar_id ;
636
+ auto unichar_id = shape[cs].unichar_id ;
634
637
if (!merge1.ContainsUnichar (unichar_id) && !merge2.ContainsUnichar (unichar_id)) {
635
638
return false ; // Shape has a unichar that appears in neither merge.
636
639
}
637
640
}
638
641
for (int cm1 = 0 ; cm1 < merge1.size (); ++cm1) {
639
- int unichar_id1 = merge1[cm1].unichar_id ;
642
+ auto unichar_id1 = merge1[cm1].unichar_id ;
640
643
if (!shape.ContainsUnichar (unichar_id1)) {
641
644
return false ; // Merge has a unichar that is not in shape.
642
645
}
643
646
}
644
647
for (int cm2 = 0 ; cm2 < merge2.size (); ++cm2) {
645
- int unichar_id2 = merge2[cm2].unichar_id ;
648
+ auto unichar_id2 = merge2[cm2].unichar_id ;
646
649
if (!shape.ContainsUnichar (unichar_id2)) {
647
650
return false ; // Merge has a unichar that is not in shape.
648
651
}
@@ -655,7 +658,7 @@ bool ShapeTable::CommonUnichars(unsigned shape_id1, unsigned shape_id2) const {
655
658
const Shape &shape1 = GetShape (shape_id1);
656
659
const Shape &shape2 = GetShape (shape_id2);
657
660
for (int c1 = 0 ; c1 < shape1.size (); ++c1) {
658
- int unichar_id1 = shape1[c1].unichar_id ;
661
+ auto unichar_id1 = shape1[c1].unichar_id ;
659
662
if (shape2.ContainsUnichar (unichar_id1)) {
660
663
return true ;
661
664
}
@@ -725,7 +728,7 @@ void ShapeTable::AddShapeToResults(const ShapeRating &shape_rating, std::vector<
725
728
for (int u = 0 ; u < shape.size (); ++u) {
726
729
int result_index =
727
730
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 ) {
729
732
(*results)[result_index].fonts .emplace_back (font_id,
730
733
IntCastRounded (shape_rating.rating * INT16_MAX));
731
734
}
0 commit comments