@@ -37,12 +37,14 @@ namespace tesseract {
3737// Returns -1 if the unichar_id is not found
3838int 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
5456int 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.
123127void 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
428432int 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 }
0 commit comments