mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 20:59:36 +08:00
Modernize code (clang-tidy -checks='-*,modernize-loop-convert')
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
cb80eb6963
commit
77ed2886a7
@ -175,8 +175,8 @@ void ShapeClassifier::UnicharPrintResults(const char *context,
|
||||
GetUnicharset().id_to_unichar(result.unichar_id));
|
||||
if (!result.fonts.empty()) {
|
||||
tprintf(" Font Vector:");
|
||||
for (int f = 0; f < result.fonts.size(); ++f) {
|
||||
tprintf(" %d", result.fonts[f].fontinfo_id);
|
||||
for (auto font : result.fonts) {
|
||||
tprintf(" %d", font.fontinfo_id);
|
||||
}
|
||||
}
|
||||
tprintf("\n");
|
||||
|
@ -173,8 +173,8 @@ 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 (auto &segmentedTimestep : *segmentedTimesteps) {
|
||||
for (int j = 0; j < segmentedTimestep.size(); ++j) {
|
||||
combined_timesteps.push_back(segmentedTimestep[j]);
|
||||
for (auto &j : segmentedTimestep) {
|
||||
combined_timesteps.push_back(j);
|
||||
}
|
||||
}
|
||||
return combined_timesteps;
|
||||
|
@ -278,25 +278,25 @@ TEST_F(TesseractTest, InitConfigOnlyTest) {
|
||||
const char *langs[] = {"eng", "chi_tra", "jpn", "vie"};
|
||||
std::unique_ptr<tesseract::TessBaseAPI> api;
|
||||
CycleTimer timer;
|
||||
for (size_t i = 0; i < countof(langs); ++i) {
|
||||
for (auto &lang : langs) {
|
||||
api = std::make_unique<tesseract::TessBaseAPI>();
|
||||
timer.Restart();
|
||||
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), langs[i], tesseract::OEM_TESSERACT_ONLY));
|
||||
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), lang, tesseract::OEM_TESSERACT_ONLY));
|
||||
timer.Stop();
|
||||
LOG(INFO) << "Lang " << langs[i] << " took " << timer.GetInMs() << "ms in regular init";
|
||||
LOG(INFO) << "Lang " << lang << " took " << timer.GetInMs() << "ms in regular init";
|
||||
}
|
||||
// Init variables to set for config-only initialization.
|
||||
std::vector<std::string> vars_vec, vars_values;
|
||||
vars_vec.push_back("tessedit_init_config_only");
|
||||
vars_values.push_back("1");
|
||||
LOG(INFO) << "Switching to config only initialization:";
|
||||
for (size_t i = 0; i < countof(langs); ++i) {
|
||||
for (auto &lang : langs) {
|
||||
api = std::make_unique<tesseract::TessBaseAPI>();
|
||||
timer.Restart();
|
||||
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), langs[i], tesseract::OEM_TESSERACT_ONLY, nullptr,
|
||||
0, &vars_vec, &vars_values, false));
|
||||
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), lang, tesseract::OEM_TESSERACT_ONLY, nullptr, 0,
|
||||
&vars_vec, &vars_values, false));
|
||||
timer.Stop();
|
||||
LOG(INFO) << "Lang " << langs[i] << " took " << timer.GetInMs() << "ms in config-only init";
|
||||
LOG(INFO) << "Lang " << lang << " took " << timer.GetInMs() << "ms in config-only init";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,9 +162,9 @@ protected:
|
||||
}
|
||||
|
||||
void ClearParts(std::vector<ColPartition *> *all_parts) {
|
||||
for (size_t i = 0; i < all_parts->size(); ++i) {
|
||||
(*all_parts)[i]->DeleteBoxes();
|
||||
delete ((*all_parts)[i]);
|
||||
for (auto &all_part : *all_parts) {
|
||||
all_part->DeleteBoxes();
|
||||
delete all_part;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@ TEST(FileTest, JoinPath) {
|
||||
TEST(OutputBufferTest, WriteString) {
|
||||
const int kMaxBufSize = 128;
|
||||
char buffer[kMaxBufSize];
|
||||
for (int i = 0; i < kMaxBufSize; ++i)
|
||||
buffer[i] = '\0';
|
||||
for (char &i : buffer)
|
||||
i = '\0';
|
||||
FILE *fp = tmpfile();
|
||||
CHECK(fp != nullptr);
|
||||
|
||||
|
@ -136,11 +136,11 @@ TEST_F(HeapTest, RevalueTest) {
|
||||
GenericHeap<PtrPair> heap;
|
||||
std::vector<PtrPair> v;
|
||||
// Push the test data onto both the heap and the vector.
|
||||
for (size_t i = 0; i < countof(test_data); ++i) {
|
||||
for (int i : test_data) {
|
||||
PtrPair h_pair;
|
||||
h_pair.key() = test_data[i];
|
||||
h_pair.key() = i;
|
||||
PtrPair v_pair;
|
||||
v_pair.key() = test_data[i];
|
||||
v_pair.key() = i;
|
||||
h_pair.data().Connect(&v_pair.data());
|
||||
heap.Push(&h_pair);
|
||||
v.push_back(v_pair);
|
||||
@ -163,8 +163,8 @@ TEST_F(HeapTest, RevalueTest) {
|
||||
// of the vector.
|
||||
std::sort(v.begin(), v.end());
|
||||
EXPECT_GT(v[0].key(), v.back().key());
|
||||
for (int i = 0; i < v.size(); ++i) {
|
||||
EXPECT_EQ(v[i].key(), heap.PeekTop().key());
|
||||
for (auto &i : v) {
|
||||
EXPECT_EQ(i.key(), heap.PeekTop().key());
|
||||
EXPECT_FALSE(heap.empty());
|
||||
heap.Pop(nullptr);
|
||||
}
|
||||
|
@ -104,15 +104,15 @@ TEST(NormstrngsTest, DetectsCorrectText) {
|
||||
}
|
||||
|
||||
TEST(NormstrngsTest, DetectsIncorrectText) {
|
||||
for (size_t i = 0; i < countof(kBadlyFormedHinWords); ++i) {
|
||||
for (auto &kBadlyFormedHinWord : kBadlyFormedHinWords) {
|
||||
EXPECT_FALSE(NormalizeUTF8String(UnicodeNormMode::kNFKC, OCRNorm::kNone,
|
||||
GraphemeNorm::kNormalize, kBadlyFormedHinWords[i], nullptr))
|
||||
<< kBadlyFormedHinWords[i];
|
||||
GraphemeNorm::kNormalize, kBadlyFormedHinWord, nullptr))
|
||||
<< kBadlyFormedHinWord;
|
||||
}
|
||||
for (size_t i = 0; i < countof(kBadlyFormedThaiWords); ++i) {
|
||||
for (auto &kBadlyFormedThaiWord : kBadlyFormedThaiWords) {
|
||||
EXPECT_FALSE(NormalizeUTF8String(UnicodeNormMode::kNFKC, OCRNorm::kNone,
|
||||
GraphemeNorm::kNormalize, kBadlyFormedThaiWords[i], nullptr))
|
||||
<< kBadlyFormedThaiWords[i];
|
||||
GraphemeNorm::kNormalize, kBadlyFormedThaiWord, nullptr))
|
||||
<< kBadlyFormedThaiWord;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,10 +165,10 @@ TEST_F(PangoFontInfoTest, CanDropUncoveredChars) {
|
||||
"\u200C", // U+200C (ZWJ)
|
||||
"\u200D" // U+200D (ZWNJ)
|
||||
};
|
||||
for (size_t i = 0; i < countof(kJoiners); ++i) {
|
||||
word = kJoiners[i];
|
||||
for (auto &kJoiner : kJoiners) {
|
||||
word = kJoiner;
|
||||
EXPECT_EQ(0, font_info_.DropUncoveredChars(&word));
|
||||
EXPECT_STREQ(kJoiners[i], word.c_str());
|
||||
EXPECT_STREQ(kJoiner, word.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,8 +108,8 @@ protected:
|
||||
const std::vector<int> &transcription) {
|
||||
// Get the utf8 string of the transcription.
|
||||
std::string truth_utf8;
|
||||
for (int i = 0; i < transcription.size(); ++i) {
|
||||
truth_utf8 += ccutil_.unicharset.id_to_unichar(transcription[i]);
|
||||
for (int i : transcription) {
|
||||
truth_utf8 += ccutil_.unicharset.id_to_unichar(i);
|
||||
}
|
||||
PointerVector<WERD_RES> words;
|
||||
ExpectCorrect(output, truth_utf8, nullptr, &words);
|
||||
@ -211,9 +211,9 @@ protected:
|
||||
outputs(t, i) = random.UnsignedRand(0.25);
|
||||
}
|
||||
int t = 0;
|
||||
for (int i = 0; i < unichar_ids.size(); ++i) {
|
||||
for (int unichar_id : unichar_ids) {
|
||||
RecodedCharID code;
|
||||
int len = recoder_.EncodeUnichar(unichar_ids[i], &code);
|
||||
int len = recoder_.EncodeUnichar(unichar_id, &code);
|
||||
EXPECT_NE(0, len);
|
||||
for (int j = 0; j < len; ++j) {
|
||||
// Make the desired answer a clear winner.
|
||||
|
@ -505,8 +505,8 @@ TEST_F(ResultIteratorTest, TextlineOrderSanityCheck) {
|
||||
for (int i = 0; i < kNumCombos; i++) {
|
||||
// generate the next combination.
|
||||
int tmp = i;
|
||||
for (int j = 0; j < kNumWords; j++) {
|
||||
word_dirs[j] = static_cast<StrongScriptDirection>(tmp % 4);
|
||||
for (auto &word_dir : word_dirs) {
|
||||
word_dir = static_cast<StrongScriptDirection>(tmp % 4);
|
||||
tmp = tmp / 4;
|
||||
}
|
||||
VerifySaneTextlineOrder(true, word_dirs, kNumWords);
|
||||
|
@ -213,8 +213,8 @@ TEST_F(StringRendererTest, ArabicBoxcharsInLTROrder) {
|
||||
std::vector<std::string> texts;
|
||||
EXPECT_TRUE(ReadMemBoxes(0, false, boxes_str.c_str(), false, nullptr, &texts, nullptr, nullptr));
|
||||
std::string ltr_str;
|
||||
for (size_t i = 0; i < texts.size(); ++i) {
|
||||
ltr_str += texts[i].c_str();
|
||||
for (auto &text : texts) {
|
||||
ltr_str += text.c_str();
|
||||
}
|
||||
// The string should come out perfectly reversed, despite there being a
|
||||
// ligature.
|
||||
|
@ -130,8 +130,8 @@ private:
|
||||
|
||||
TEST_F(TableFinderTest, GapInXProjectionNoGap) {
|
||||
int data[100];
|
||||
for (int i = 0; i < 100; ++i)
|
||||
data[i] = 10;
|
||||
for (int &i : data)
|
||||
i = 10;
|
||||
EXPECT_FALSE(finder_->GapInXProjection(data, 100));
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ protected:
|
||||
// used as its size on reading.
|
||||
if (fp->FWrite(&num_squares_, sizeof(num_squares_), 1) != 1)
|
||||
return false;
|
||||
for (int i = 0; i < squares_.size(); ++i)
|
||||
ReverseN(&squares_[i], sizeof(squares_[i]));
|
||||
for (int &square : squares_)
|
||||
ReverseN(&square, sizeof(square));
|
||||
if (!fp->Serialize(squares_))
|
||||
return false;
|
||||
ReverseN(&num_triangles_, sizeof(num_triangles_));
|
||||
|
@ -139,8 +139,7 @@ protected:
|
||||
int length = code.length();
|
||||
const std::vector<int> *final_codes = compressed_.GetFinalCodes(code);
|
||||
if (final_codes != nullptr) {
|
||||
for (int i = 0; i < final_codes->size(); ++i) {
|
||||
int ending = (*final_codes)[i];
|
||||
for (int ending : *final_codes) {
|
||||
EXPECT_GT(times_seen[ending](length), 0);
|
||||
extended.Set(length, ending);
|
||||
int unichar_id = compressed_.DecodeUnichar(extended);
|
||||
@ -149,8 +148,7 @@ protected:
|
||||
}
|
||||
const std::vector<int> *next_codes = compressed_.GetNextCodes(code);
|
||||
if (next_codes != nullptr) {
|
||||
for (int i = 0; i < next_codes->size(); ++i) {
|
||||
int extension = (*next_codes)[i];
|
||||
for (int extension : *next_codes) {
|
||||
EXPECT_GT(times_seen[extension](length), 0);
|
||||
extended.Set(length, extension);
|
||||
CheckCodeExtensions(extended, times_seen);
|
||||
|
Loading…
Reference in New Issue
Block a user