Skip to content

Commit 500bfaf

Browse files
committed
Added std:: to some stl types
1 parent 1cc5111 commit 500bfaf

File tree

5 files changed

+69
-66
lines changed

5 files changed

+69
-66
lines changed

training/boxchar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar*>* boxes) {
207207
for (int start = 0; start < boxes->size(); start = end + 1) {
208208
end = start + 1;
209209
while (end < boxes->size() && (*boxes)[end]->ch_ != "\t") ++end;
210-
sort(boxes->begin() + start, boxes->begin() + end, sorter);
210+
std::sort(boxes->begin() + start, boxes->begin() + end, sorter);
211211
}
212212
}
213213

training/boxchar.h

+12-11
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,27 @@ class BoxChar {
6666
}
6767

6868
static void TranslateBoxes(int xshift, int yshift,
69-
vector<BoxChar*>* boxes);
69+
std::vector<BoxChar*>* boxes);
7070

7171
// Prepares for writing the boxes to a file by inserting newlines, spaces,
7272
// and re-ordering so the boxes are strictly left-to-right.
73-
static void PrepareToWrite(vector<BoxChar*>* boxes);
73+
static void PrepareToWrite(std::vector<BoxChar*>* boxes);
7474
// Inserts newline (tab) characters into the vector at newline positions.
7575
static void InsertNewlines(bool rtl_rules, bool vertical_rules,
76-
vector<BoxChar*>* boxes);
76+
std::vector<BoxChar*>* boxes);
7777
// Converts nullptr boxes to space characters, with appropriate bounding
7878
// boxes.
7979
static void InsertSpaces(bool rtl_rules, bool vertical_rules,
80-
vector<BoxChar*>* boxes);
80+
std::vector<BoxChar*>* boxes);
8181
// Reorders text in a right-to-left script in left-to-right order.
82-
static void ReorderRTLText(vector<BoxChar*>* boxes);
82+
static void ReorderRTLText(std::vector<BoxChar*>* boxes);
8383
// Returns true if the vector contains mostly RTL characters.
84-
static bool ContainsMostlyRTL(const vector<BoxChar*>& boxes);
84+
static bool ContainsMostlyRTL(const std::vector<BoxChar*>& boxes);
8585
// Returns true if the text is mostly laid out vertically.
86-
static bool MostlyVertical(const vector<BoxChar*>& boxes);
86+
static bool MostlyVertical(const std::vector<BoxChar*>& boxes);
8787

8888
// Returns the total length of all the strings in the boxes.
89-
static int TotalByteLength(const vector<BoxChar*>& boxes);
89+
static int TotalByteLength(const std::vector<BoxChar*>& boxes);
9090

9191
// Rotate the vector of boxes between start and end by the given rotation.
9292
// The rotation is in radians clockwise about the given center.
@@ -95,15 +95,16 @@ class BoxChar {
9595
int ycenter,
9696
int start_box,
9797
int end_box,
98-
vector<BoxChar*>* boxes);
98+
std::vector<BoxChar*>* boxes);
9999

100100
// Create a tesseract box file from the vector of boxes. The image height
101101
// is needed to convert to tesseract coordinates.
102102
static void WriteTesseractBoxFile(const string& name, int height,
103-
const vector<BoxChar*>& boxes);
103+
const std::vector<BoxChar*>& boxes);
104104
// Gets the tesseract box file as a string from the vector of boxes.
105105
// The image height is needed to convert to tesseract coordinates.
106-
static string GetTesseractBoxStr(int height, const vector<BoxChar*>& boxes);
106+
static string GetTesseractBoxStr(int height,
107+
const std::vector<BoxChar*>& boxes);
107108

108109
private:
109110
string ch_;

training/pango_font_info.cpp

+25-24
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,12 @@ bool PangoFontInfo::GetSpacingProperties(const string& utf8_char,
387387
}
388388

389389
bool PangoFontInfo::CanRenderString(const char* utf8_word, int len) const {
390-
vector<string> graphemes;
390+
std::vector<string> graphemes;
391391
return CanRenderString(utf8_word, len, &graphemes);
392392
}
393393

394394
bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
395-
vector<string>* graphemes) const {
395+
std::vector<string>* graphemes) const {
396396
if (graphemes) graphemes->clear();
397397
// We check for font coverage of the text first, as otherwise Pango could
398398
// (undesirably) fall back to another font that does have the required
@@ -508,7 +508,7 @@ bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
508508

509509

510510
// ------------------------ FontUtils ------------------------------------
511-
vector<string> FontUtils::available_fonts_; // cache list
511+
std::vector<string> FontUtils::available_fonts_; // cache list
512512

513513
// Returns whether the specified font description is available in the fonts
514514
// directory.
@@ -591,7 +591,7 @@ static bool ShouldIgnoreFontFamilyName(const char* query) {
591591

592592
// Outputs description names of available fonts.
593593
/* static */
594-
const vector<string>& FontUtils::ListAvailableFonts() {
594+
const std::vector<string>& FontUtils::ListAvailableFonts() {
595595
if (!available_fonts_.empty()) {
596596
return available_fonts_;
597597
}
@@ -634,13 +634,13 @@ const vector<string>& FontUtils::ListAvailableFonts() {
634634
g_free(faces);
635635
}
636636
g_free(families);
637-
sort(available_fonts_.begin(), available_fonts_.end());
637+
std::sort(available_fonts_.begin(), available_fonts_.end());
638638
return available_fonts_;
639639
}
640640

641641

642642
static void CharCoverageMapToBitmap(PangoCoverage* coverage,
643-
vector<bool>* unichar_bitmap) {
643+
std::vector<bool>* unichar_bitmap) {
644644
const int kMinUnicodeValue = 33;
645645
const int kMaxUnicodeValue = 0x10FFFF;
646646
unichar_bitmap->resize(kMaxUnicodeValue + 1, false);
@@ -654,23 +654,23 @@ static void CharCoverageMapToBitmap(PangoCoverage* coverage,
654654
}
655655

656656
/* static */
657-
void FontUtils::GetAllRenderableCharacters(vector<bool>* unichar_bitmap) {
658-
const vector<string>& all_fonts = ListAvailableFonts();
657+
void FontUtils::GetAllRenderableCharacters(std::vector<bool>* unichar_bitmap) {
658+
const std::vector<string>& all_fonts = ListAvailableFonts();
659659
return GetAllRenderableCharacters(all_fonts, unichar_bitmap);
660660
}
661661

662662
/* static */
663663
void FontUtils::GetAllRenderableCharacters(const string& font_name,
664-
vector<bool>* unichar_bitmap) {
664+
std::vector<bool>* unichar_bitmap) {
665665
PangoFontInfo font_info(font_name);
666666
PangoCoverage* coverage =
667667
pango_font_get_coverage(font_info.ToPangoFont(), nullptr);
668668
CharCoverageMapToBitmap(coverage, unichar_bitmap);
669669
}
670670

671671
/* static */
672-
void FontUtils::GetAllRenderableCharacters(const vector<string>& fonts,
673-
vector<bool>* unichar_bitmap) {
672+
void FontUtils::GetAllRenderableCharacters(const std::vector<string>& fonts,
673+
std::vector<bool>* unichar_bitmap) {
674674
// Form the union of coverage maps from the fonts
675675
PangoCoverage* all_coverage = pango_coverage_new();
676676
tlog(1, "Processing %d fonts\n", fonts.size());
@@ -691,7 +691,7 @@ void FontUtils::GetAllRenderableCharacters(const vector<string>& fonts,
691691
/* static */
692692
int FontUtils::FontScore(const std::unordered_map<char32, inT64>& ch_map,
693693
const string& fontname, int* raw_score,
694-
vector<bool>* ch_flags) {
694+
std::vector<bool>* ch_flags) {
695695
PangoFontInfo font_info;
696696
if (!font_info.ParseFontDescriptionName(fontname)) {
697697
tprintf("ERROR: Could not parse %s\n", fontname.c_str());
@@ -723,22 +723,23 @@ int FontUtils::FontScore(const std::unordered_map<char32, inT64>& ch_map,
723723

724724

725725
/* static */
726-
string FontUtils::BestFonts(const std::unordered_map<char32, inT64>& ch_map,
727-
vector<pair<const char*, vector<bool> > >* fonts) {
726+
string FontUtils::BestFonts(
727+
const std::unordered_map<char32, inT64>& ch_map,
728+
std::vector<std::pair<const char*, std::vector<bool> > >* fonts) {
728729
const double kMinOKFraction = 0.99;
729730
// Weighted fraction of characters that must be renderable in a font to make
730731
// it OK even if the raw count is not good.
731732
const double kMinWeightedFraction = 0.99995;
732733

733734
fonts->clear();
734-
vector<vector<bool> > font_flags;
735-
vector<int> font_scores;
736-
vector<int> raw_scores;
735+
std::vector<std::vector<bool> > font_flags;
736+
std::vector<int> font_scores;
737+
std::vector<int> raw_scores;
737738
int most_ok_chars = 0;
738739
int best_raw_score = 0;
739-
const vector<string>& font_names = FontUtils::ListAvailableFonts();
740+
const std::vector<string>& font_names = FontUtils::ListAvailableFonts();
740741
for (int i = 0; i < font_names.size(); ++i) {
741-
vector<bool> ch_flags;
742+
std::vector<bool> ch_flags;
742743
int raw_score = 0;
743744
int ok_chars = FontScore(ch_map, font_names[i], &raw_score, &ch_flags);
744745
most_ok_chars = MAX(ok_chars, most_ok_chars);
@@ -767,7 +768,7 @@ string FontUtils::BestFonts(const std::unordered_map<char32, inT64>& ch_map,
767768
int raw_score = raw_scores[i];
768769
if ((score >= least_good_enough && raw_score >= least_raw_enough) ||
769770
score >= override_enough) {
770-
fonts->push_back(make_pair(font_names[i].c_str(), font_flags[i]));
771+
fonts->push_back(std::make_pair(font_names[i].c_str(), font_flags[i]));
771772
tlog(1, "OK font %s = %.4f%%, raw = %d = %.2f%%\n",
772773
font_names[i].c_str(),
773774
100.0 * score / most_ok_chars,
@@ -786,20 +787,20 @@ string FontUtils::BestFonts(const std::unordered_map<char32, inT64>& ch_map,
786787

787788
/* static */
788789
bool FontUtils::SelectFont(const char* utf8_word, const int utf8_len,
789-
string* font_name, vector<string>* graphemes) {
790+
string* font_name, std::vector<string>* graphemes) {
790791
return SelectFont(utf8_word, utf8_len, ListAvailableFonts(), font_name,
791792
graphemes);
792793
}
793794

794795
/* static */
795796
bool FontUtils::SelectFont(const char* utf8_word, const int utf8_len,
796-
const vector<string>& all_fonts,
797-
string* font_name, vector<string>* graphemes) {
797+
const std::vector<string>& all_fonts,
798+
string* font_name, std::vector<string>* graphemes) {
798799
if (font_name) font_name->clear();
799800
if (graphemes) graphemes->clear();
800801
for (int i = 0; i < all_fonts.size(); ++i) {
801802
PangoFontInfo font;
802-
vector<string> found_graphemes;
803+
std::vector<string> found_graphemes;
803804
ASSERT_HOST_MSG(font.ParseFontDescriptionName(all_fonts[i]),
804805
"Could not parse font desc name %s\n",
805806
all_fonts[i].c_str());

training/stringrenderer.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ int StringRenderer::FindFirstPageBreakOffset(const char* text,
326326
return offset;
327327
}
328328

329-
const vector<BoxChar*>& StringRenderer::GetBoxes() const {
329+
const std::vector<BoxChar*>& StringRenderer::GetBoxes() const {
330330
return boxchars_;
331331
}
332332

@@ -358,8 +358,8 @@ void StringRenderer::WriteAllBoxes(const string& filename) {
358358
}
359359

360360
// Returns cluster strings in logical order.
361-
bool StringRenderer::GetClusterStrings(vector<string>* cluster_text) {
362-
map<int, string> start_byte_to_text;
361+
bool StringRenderer::GetClusterStrings(std::vector<string>* cluster_text) {
362+
std::map<int, string> start_byte_to_text;
363363
PangoLayoutIter* run_iter = pango_layout_get_iter(layout_);
364364
const char* full_text = pango_layout_get_text(layout_);
365365
do {
@@ -396,7 +396,7 @@ bool StringRenderer::GetClusterStrings(vector<string>* cluster_text) {
396396
pango_layout_iter_free(run_iter);
397397

398398
cluster_text->clear();
399-
for (map<int, string>::const_iterator it = start_byte_to_text.begin();
399+
for (std::map<int, string>::const_iterator it = start_byte_to_text.begin();
400400
it != start_byte_to_text.end(); ++it) {
401401
cluster_text->push_back(it->second);
402402
}
@@ -413,8 +413,8 @@ bool StringRenderer::GetClusterStrings(vector<string>* cluster_text) {
413413
// hyphens. When this is detected the word is split at that location into
414414
// multiple BoxChars. Otherwise, each resulting BoxChar will contain a word and
415415
// its bounding box.
416-
static void MergeBoxCharsToWords(vector<BoxChar*>* boxchars) {
417-
vector<BoxChar*> result;
416+
static void MergeBoxCharsToWords(std::vector<BoxChar*>* boxchars) {
417+
std::vector<BoxChar*> result;
418418
bool started_word = false;
419419
for (int i = 0; i < boxchars->size(); ++i) {
420420
if (boxchars->at(i)->ch() == " " || boxchars->at(i)->box() == nullptr) {
@@ -469,7 +469,7 @@ void StringRenderer::ComputeClusterBoxes() {
469469
PangoLayoutIter* cluster_iter = pango_layout_get_iter(layout_);
470470

471471
// Do a first pass to store cluster start indexes.
472-
vector<int> cluster_start_indices;
472+
std::vector<int> cluster_start_indices;
473473
do {
474474
cluster_start_indices.push_back(pango_layout_iter_get_index(cluster_iter));
475475
tlog(3, "Added %d\n", cluster_start_indices.back());
@@ -478,8 +478,8 @@ void StringRenderer::ComputeClusterBoxes() {
478478
cluster_start_indices.push_back(strlen(text));
479479
tlog(3, "Added last index %d\n", cluster_start_indices.back());
480480
// Sort the indices and create a map from start to end indices.
481-
sort(cluster_start_indices.begin(), cluster_start_indices.end());
482-
map<int, int> cluster_start_to_end_index;
481+
std::sort(cluster_start_indices.begin(), cluster_start_indices.end());
482+
std::map<int, int> cluster_start_to_end_index;
483483
for (int i = 0; i < cluster_start_indices.size() - 1; ++i) {
484484
cluster_start_to_end_index[cluster_start_indices[i]]
485485
= cluster_start_indices[i + 1];
@@ -489,7 +489,7 @@ void StringRenderer::ComputeClusterBoxes() {
489489
// cluster extent information.
490490
cluster_iter = pango_layout_get_iter(layout_);
491491
// Store BoxChars* sorted by their byte start positions
492-
map<int, BoxChar*> start_byte_to_box;
492+
std::map<int, BoxChar*> start_byte_to_box;
493493
do {
494494
PangoRectangle cluster_rect;
495495
pango_layout_iter_get_cluster_extents(cluster_iter, &cluster_rect, nullptr);
@@ -548,21 +548,21 @@ void StringRenderer::ComputeClusterBoxes() {
548548
// accurate.
549549
// TODO(ranjith): Revisit whether this is still needed in newer versions of
550550
// pango.
551-
vector<string> cluster_text;
551+
std::vector<string> cluster_text;
552552
if (GetClusterStrings(&cluster_text)) {
553553
ASSERT_HOST(cluster_text.size() == start_byte_to_box.size());
554554
int ind = 0;
555-
for (map<int, BoxChar*>::iterator it = start_byte_to_box.begin();
555+
for (std::map<int, BoxChar*>::iterator it = start_byte_to_box.begin();
556556
it != start_byte_to_box.end(); ++it, ++ind) {
557557
it->second->mutable_ch()->swap(cluster_text[ind]);
558558
}
559559
}
560560

561561
// Append to the boxchars list in byte order.
562-
vector<BoxChar*> page_boxchars;
562+
std::vector<BoxChar*> page_boxchars;
563563
page_boxchars.reserve(start_byte_to_box.size());
564564
string last_ch;
565-
for (map<int, BoxChar*>::const_iterator it = start_byte_to_box.begin();
565+
for (std::map<int, BoxChar*>::const_iterator it = start_byte_to_box.begin();
566566
it != start_byte_to_box.end(); ++it) {
567567
if (it->second->ch() == kWordJoinerUTF8) {
568568
// Skip zero-width joiner characters (ZWJs) here.
@@ -574,7 +574,7 @@ void StringRenderer::ComputeClusterBoxes() {
574574
CorrectBoxPositionsToLayout(&page_boxchars);
575575

576576
if (render_fullwidth_latin_) {
577-
for (map<int, BoxChar*>::iterator it = start_byte_to_box.begin();
577+
for (std::map<int, BoxChar*>::iterator it = start_byte_to_box.begin();
578578
it != start_byte_to_box.end(); ++it) {
579579
// Convert fullwidth Latin characters to their halfwidth forms.
580580
string half(ConvertFullwidthLatinToBasicLatin(it->second->ch()));
@@ -606,7 +606,8 @@ void StringRenderer::ComputeClusterBoxes() {
606606
}
607607

608608

609-
void StringRenderer::CorrectBoxPositionsToLayout(vector<BoxChar*>* boxchars) {
609+
void StringRenderer::CorrectBoxPositionsToLayout(
610+
std::vector<BoxChar*>* boxchars) {
610611
if (vertical_text_) {
611612
const double rotation = - pango_gravity_to_rotation(
612613
pango_context_get_base_gravity(pango_layout_get_context(layout_)));
@@ -864,7 +865,7 @@ int StringRenderer::RenderAllFontsToImage(double min_coverage,
864865
}
865866
tprintf("Total chars = %d\n", total_chars_);
866867
}
867-
const vector<string>& all_fonts = FontUtils::ListAvailableFonts();
868+
const std::vector<string>& all_fonts = FontUtils::ListAvailableFonts();
868869
for (int i = font_index_; i < all_fonts.size(); ++i) {
869870
++font_index_;
870871
int raw_score = 0;

0 commit comments

Comments
 (0)