Skip to content

Commit 2c837df

Browse files
committed
Result of clang tidy on recent merge
1 parent 8972c0e commit 2c837df

File tree

139 files changed

+2553
-3012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2553
-3012
lines changed

COPYING

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ in this distribution is now licensed under the Apache License:
1717
Other Dependencies and Licenses:
1818
================================
1919

20-
Tesseract uses Leptonica library (http://leptonica.com/) with a very weakly
21-
restricted copyright license (http://leptonica.com/about-the-license.html)
20+
Tesseract uses Leptonica library (http://leptonica.com/) which essentially
21+
uses a BSD 2-clause license. (http://leptonica.com/about-the-license.html)

android/jni/Android.mk

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
44
LOCAL_MODULE := tesseract-$(APP_ABI)
55

66
LOCAL_STATIC_LIBRARIES := \
7-
mobile_base \
7+
base \
88
leptonica-$(APP_ABI)
99

1010
LOCAL_C_INCLUDES := $(APP_C_INCLUDES)
@@ -51,7 +51,6 @@ LOCAL_CFLAGS := -DANDROID_BUILD -DNO_CUBE_BUILD -DGRAPHICS_DISABLED
5151

5252
include $(BUILD_SHARED_LIBRARY)
5353

54-
$(call import-module,mobile/base)
55-
$(call import-module,mobile/base)
54+
$(call import-module,base/port)
5655
$(call import-module,mobile/util/hash)
5756
$(call import-module,third_party/leptonica/android/jni)

api/baseapi.cpp

+66-68
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,7 @@ int CubeAPITest(Boxa* boxa_blocks, Pixa* pixa_blocks,
809809
* has not been subjected to a call of Init, SetImage, Recognize, Clear, End
810810
* DetectOS, or anything else that changes the internal PAGE_RES.
811811
*/
812-
PageIterator* TessBaseAPI::AnalyseLayout() {
813-
return AnalyseLayout(false);
814-
}
812+
PageIterator* TessBaseAPI::AnalyseLayout() { return AnalyseLayout(false); }
815813

816814
PageIterator* TessBaseAPI::AnalyseLayout(bool merge_similar_words) {
817815
if (FindLines() == 0) {
@@ -1379,8 +1377,9 @@ static void AddBaselineCoordsTohOCR(const PageIterator *it,
13791377
hocr_str->add_str_double(" ", round(p0 * 1000.0) / 1000.0);
13801378
}
13811379

1382-
static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1, int num2) {
1383-
const unsigned long BUFSIZE = 64;
1380+
static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1,
1381+
int num2) {
1382+
const size_t BUFSIZE = 64;
13841383
char id_buffer[BUFSIZE];
13851384
if (num2 >= 0) {
13861385
snprintf(id_buffer, BUFSIZE - 1, "%s_%d_%d", base.c_str(), num1, num2);
@@ -1393,8 +1392,7 @@ static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1, int
13931392
*hocr_str += "'";
13941393
}
13951394

1396-
static void AddBoxTohOCR(const ResultIterator *it,
1397-
PageIteratorLevel level,
1395+
static void AddBoxTohOCR(const ResultIterator* it, PageIteratorLevel level,
13981396
STRING* hocr_str) {
13991397
int left, top, right, bottom;
14001398
it->BoundingBox(level, &left, &top, &right, &bottom);
@@ -1410,17 +1408,16 @@ static void AddBoxTohOCR(const ResultIterator *it,
14101408
// add custom height measures
14111409
float row_height, descenders, ascenders; // row attributes
14121410
it->RowAttributes(&row_height, &descenders, &ascenders);
1413-
// TODO: Do we want to limit these to a single decimal place?
1411+
// TODO(rays): Do we want to limit these to a single decimal place?
14141412
hocr_str->add_str_double("; x_size ", row_height);
14151413
hocr_str->add_str_double("; x_descenders ", descenders * -1);
14161414
hocr_str->add_str_double("; x_ascenders ", ascenders);
14171415
}
14181416
*hocr_str += "\">";
14191417
}
14201418

1421-
static void AddBoxToTSV(const PageIterator *it,
1422-
PageIteratorLevel level,
1423-
STRING* hocr_str) {
1419+
static void AddBoxToTSV(const PageIterator* it, PageIteratorLevel level,
1420+
STRING* hocr_str) {
14241421
int left, top, right, bottom;
14251422
it->BoundingBox(level, &left, &top, &right, &bottom);
14261423
hocr_str->add_str_int("\t", left);
@@ -1429,8 +1426,6 @@ static void AddBoxToTSV(const PageIterator *it,
14291426
hocr_str->add_str_int("\t", bottom - top);
14301427
}
14311428

1432-
1433-
14341429
/**
14351430
* Make a HTML-formatted string with hOCR markup from the internal
14361431
* data structures.
@@ -1440,7 +1435,7 @@ static void AddBoxToTSV(const PageIterator *it,
14401435
* STL removed from original patch submission and refactored by rays.
14411436
*/
14421437
char* TessBaseAPI::GetHOCRText(int page_number) {
1443-
return GetHOCRText(NULL,page_number);
1438+
return GetHOCRText(NULL, page_number);
14441439
}
14451440

14461441
/**
@@ -1452,13 +1447,12 @@ char* TessBaseAPI::GetHOCRText(int page_number) {
14521447
* STL removed from original patch submission and refactored by rays.
14531448
*/
14541449
char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
1455-
if (tesseract_ == NULL ||
1456-
(page_res_ == NULL && Recognize(monitor) < 0))
1450+
if (tesseract_ == NULL || (page_res_ == NULL && Recognize(monitor) < 0))
14571451
return NULL;
14581452

14591453
int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
14601454
int page_id = page_number + 1; // hOCR uses 1-based page numbers.
1461-
bool para_is_ltr = true; // Default direction is LTR
1455+
bool para_is_ltr = true; // Default direction is LTR
14621456
const char* paragraph_lang = NULL;
14631457
bool font_info = false;
14641458
GetBoolVariable("hocr_font_info", &font_info);
@@ -1470,13 +1464,13 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
14701464

14711465
#ifdef _WIN32
14721466
// convert input name from ANSI encoding to utf-8
1473-
int str16_len = MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1,
1474-
NULL, 0);
1467+
int str16_len =
1468+
MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1, NULL, 0);
14751469
wchar_t *uni16_str = new WCHAR[str16_len];
14761470
str16_len = MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1,
14771471
uni16_str, str16_len);
1478-
int utf8_len = WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, NULL,
1479-
0, NULL, NULL);
1472+
int utf8_len = WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, NULL, 0,
1473+
NULL, NULL);
14801474
char *utf8_str = new char[utf8_len];
14811475
WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, utf8_str,
14821476
utf8_len, NULL, NULL);
@@ -1509,7 +1503,7 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
15091503

15101504
// Open any new block/paragraph/textline.
15111505
if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
1512-
para_is_ltr = true; // reset to default direction
1506+
para_is_ltr = true; // reset to default direction
15131507
hocr_str += " <div class='ocr_carea'";
15141508
AddIdTohOCR(&hocr_str, "block", page_id, bcnt);
15151509
AddBoxTohOCR(res_it, RIL_BLOCK, &hocr_str);
@@ -1523,9 +1517,9 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
15231517
AddIdTohOCR(&hocr_str, "par", page_id, pcnt);
15241518
paragraph_lang = res_it->WordRecognitionLanguage();
15251519
if (paragraph_lang) {
1526-
hocr_str += " lang='";
1527-
hocr_str += paragraph_lang;
1528-
hocr_str += "'";
1520+
hocr_str += " lang='";
1521+
hocr_str += paragraph_lang;
1522+
hocr_str += "'";
15291523
}
15301524
AddBoxTohOCR(res_it, RIL_PARA, &hocr_str);
15311525
}
@@ -1567,8 +1561,12 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
15671561
}
15681562
switch (res_it->WordDirection()) {
15691563
// Only emit direction if different from current paragraph direction
1570-
case DIR_LEFT_TO_RIGHT: if (!para_is_ltr) hocr_str += " dir='ltr'"; break;
1571-
case DIR_RIGHT_TO_LEFT: if (para_is_ltr) hocr_str += " dir='rtl'"; break;
1564+
case DIR_LEFT_TO_RIGHT:
1565+
if (!para_is_ltr) hocr_str += " dir='ltr'";
1566+
break;
1567+
case DIR_RIGHT_TO_LEFT:
1568+
if (para_is_ltr) hocr_str += " dir='rtl'";
1569+
break;
15721570
case DIR_MIX:
15731571
case DIR_NEUTRAL:
15741572
default: // Do nothing.
@@ -1600,7 +1598,7 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
16001598
if (last_word_in_para) {
16011599
hocr_str += "\n </p>\n";
16021600
pcnt++;
1603-
para_is_ltr = true; // back to default direction
1601+
para_is_ltr = true; // back to default direction
16041602
}
16051603
if (last_word_in_block) {
16061604
hocr_str += " </div>\n";
@@ -1620,18 +1618,18 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
16201618
* page_number is 0-based but will appear in the output as 1-based.
16211619
*/
16221620
char* TessBaseAPI::GetTSVText(int page_number) {
1623-
if (tesseract_ == NULL ||
1624-
(page_res_ == NULL && Recognize(NULL) < 0))
1621+
if (tesseract_ == NULL || (page_res_ == NULL && Recognize(NULL) < 0))
16251622
return NULL;
16261623

16271624
int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
16281625
int page_id = page_number + 1; // we use 1-based page numbers.
16291626

16301627
STRING tsv_str("");
16311628

1632-
int page_num = page_id, block_num = 0, par_num = 0, line_num = 0, word_num = 0;
1629+
int page_num = page_id, block_num = 0, par_num = 0, line_num = 0,
1630+
word_num = 0;
16331631

1634-
tsv_str.add_str_int("1\t", page_num); // level 1 - page
1632+
tsv_str.add_str_int("1\t", page_num); // level 1 - page
16351633
tsv_str.add_str_int("\t", block_num);
16361634
tsv_str.add_str_int("\t", par_num);
16371635
tsv_str.add_str_int("\t", line_num);
@@ -1642,7 +1640,7 @@ char* TessBaseAPI::GetTSVText(int page_number) {
16421640
tsv_str.add_str_int("\t", rect_height_);
16431641
tsv_str += "\t-1\t\n";
16441642

1645-
ResultIterator *res_it = GetIterator();
1643+
ResultIterator* res_it = GetIterator();
16461644
while (!res_it->Empty(RIL_BLOCK)) {
16471645
if (res_it->Empty(RIL_WORD)) {
16481646
res_it->Next(RIL_WORD);
@@ -1652,46 +1650,46 @@ char* TessBaseAPI::GetTSVText(int page_number) {
16521650
// Add rows for any new block/paragraph/textline.
16531651
if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
16541652
block_num++, par_num = 0, line_num = 0, word_num = 0;
1655-
tsv_str.add_str_int("2\t", page_num); // level 2 - block
1653+
tsv_str.add_str_int("2\t", page_num); // level 2 - block
16561654
tsv_str.add_str_int("\t", block_num);
16571655
tsv_str.add_str_int("\t", par_num);
16581656
tsv_str.add_str_int("\t", line_num);
16591657
tsv_str.add_str_int("\t", word_num);
16601658
AddBoxToTSV(res_it, RIL_BLOCK, &tsv_str);
1661-
tsv_str += "\t-1\t\n"; // end of row for block
1659+
tsv_str += "\t-1\t\n"; // end of row for block
16621660
}
16631661
if (res_it->IsAtBeginningOf(RIL_PARA)) {
16641662
par_num++, line_num = 0, word_num = 0;
1665-
tsv_str.add_str_int("3\t", page_num); // level 3 - paragraph
1663+
tsv_str.add_str_int("3\t", page_num); // level 3 - paragraph
16661664
tsv_str.add_str_int("\t", block_num);
16671665
tsv_str.add_str_int("\t", par_num);
16681666
tsv_str.add_str_int("\t", line_num);
16691667
tsv_str.add_str_int("\t", word_num);
16701668
AddBoxToTSV(res_it, RIL_PARA, &tsv_str);
1671-
tsv_str += "\t-1\t\n"; // end of row for para
1669+
tsv_str += "\t-1\t\n"; // end of row for para
16721670
}
16731671
if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
16741672
line_num++, word_num = 0;
1675-
tsv_str.add_str_int("4\t", page_num); // level 4 - line
1673+
tsv_str.add_str_int("4\t", page_num); // level 4 - line
16761674
tsv_str.add_str_int("\t", block_num);
16771675
tsv_str.add_str_int("\t", par_num);
16781676
tsv_str.add_str_int("\t", line_num);
16791677
tsv_str.add_str_int("\t", word_num);
16801678
AddBoxToTSV(res_it, RIL_TEXTLINE, &tsv_str);
1681-
tsv_str += "\t-1\t\n"; // end of row for line
1679+
tsv_str += "\t-1\t\n"; // end of row for line
16821680
}
16831681

16841682
// Now, process the word...
16851683
int left, top, right, bottom;
16861684
bool bold, italic, underlined, monospace, serif, smallcaps;
16871685
int pointsize, font_id;
1688-
const char *font_name;
1686+
const char* font_name;
16891687
res_it->BoundingBox(RIL_WORD, &left, &top, &right, &bottom);
1690-
font_name = res_it->WordFontAttributes(&bold, &italic, &underlined,
1691-
&monospace, &serif, &smallcaps,
1692-
&pointsize, &font_id);
1688+
font_name =
1689+
res_it->WordFontAttributes(&bold, &italic, &underlined, &monospace,
1690+
&serif, &smallcaps, &pointsize, &font_id);
16931691
word_num++;
1694-
tsv_str.add_str_int("5\t", page_num); // level 5 - word
1692+
tsv_str.add_str_int("5\t", page_num); // level 5 - word
16951693
tsv_str.add_str_int("\t", block_num);
16961694
tsv_str.add_str_int("\t", par_num);
16971695
tsv_str.add_str_int("\t", line_num);
@@ -1712,11 +1710,11 @@ char* TessBaseAPI::GetTSVText(int page_number) {
17121710
tsv_str += res_it->GetUTF8Text(RIL_SYMBOL);
17131711
res_it->Next(RIL_SYMBOL);
17141712
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
1715-
tsv_str += "\n"; // end of row
1713+
tsv_str += "\n"; // end of row
17161714
wcnt++;
17171715
}
17181716

1719-
char *ret = new char[tsv_str.length() + 1];
1717+
char* ret = new char[tsv_str.length() + 1];
17201718
strcpy(ret, tsv_str.string());
17211719
delete res_it;
17221720
return ret;
@@ -1760,7 +1758,7 @@ char* TessBaseAPI::GetBoxText(int page_number) {
17601758
int total_length = blob_count * kBytesPerBoxFileLine + utf8_length +
17611759
kMaxBytesPerLine;
17621760
char* result = new char[total_length];
1763-
strcpy(result, "\0");
1761+
result[0] = '\0';
17641762
int output_length = 0;
17651763
LTRResultIterator* it = GetLTRIterator();
17661764
do {
@@ -1907,17 +1905,17 @@ char* TessBaseAPI::GetUNLVText() {
19071905
return result;
19081906
}
19091907

1910-
/**
1911-
* The recognized text is returned as a char* which is coded
1912-
* as UTF8 and must be freed with the delete [] operator.
1913-
* page_number is a 0-based page index that will appear in the osd file.
1914-
*/
1908+
/**
1909+
* The recognized text is returned as a char* which is coded
1910+
* as UTF8 and must be freed with the delete [] operator.
1911+
* page_number is a 0-based page index that will appear in the osd file.
1912+
*/
19151913
char* TessBaseAPI::GetOsdText(int page_number) {
19161914
OSResults osr;
19171915

19181916
bool osd = DetectOS(&osr);
19191917
if (!osd) {
1920-
return NULL;
1918+
return NULL;
19211919
}
19221920

19231921
int orient_id = osr.best_result.orientation_id;
@@ -1931,19 +1929,19 @@ char* TessBaseAPI::GetOsdText(int page_number) {
19311929
int orient_deg = orient_id * 90;
19321930

19331931
// clockwise rotation needed to make the page upright
1934-
int rotate = OrientationIdToValue(orient_id);
1935-
1936-
char* osd_buf = new char[255];
1937-
snprintf(osd_buf, 255,
1938-
"Page number: %d\n"
1939-
"Orientation in degrees: %d\n"
1940-
"Rotate: %d\n"
1941-
"Orientation confidence: %.2f\n"
1942-
"Script: %s\n"
1943-
"Script confidence: %.2f\n",
1944-
page_number,
1945-
orient_deg, rotate, orient_conf,
1946-
script_name, script_conf);
1932+
int rotate = OrientationIdToValue(orient_id);
1933+
1934+
const int kOsdBufsize = 255;
1935+
char* osd_buf = new char[kOsdBufsize];
1936+
snprintf(osd_buf, kOsdBufsize,
1937+
"Page number: %d\n"
1938+
"Orientation in degrees: %d\n"
1939+
"Rotate: %d\n"
1940+
"Orientation confidence: %.2f\n"
1941+
"Script: %s\n"
1942+
"Script confidence: %.2f\n",
1943+
page_number, orient_deg, rotate, orient_conf, script_name,
1944+
script_conf);
19471945

19481946
return osd_buf;
19491947
}
@@ -2063,7 +2061,7 @@ void TessBaseAPI::Clear() {
20632061
if (thresholder_ != NULL)
20642062
thresholder_->Clear();
20652063
ClearResults();
2066-
SetInputImage(NULL);
2064+
if (tesseract_ != NULL) SetInputImage(NULL);
20672065
}
20682066

20692067
/**
@@ -2767,7 +2765,7 @@ void TessBaseAPI::GetFeaturesForBlob(TBLOB* blob,
27672765
INT_FX_RESULT_STRUCT fx_info;
27682766
tesseract_->ExtractFeatures(*blob, false, &bl_features,
27692767
&cn_features, &fx_info, &outline_counts);
2770-
if (cn_features.size() == 0 || cn_features.size() > MAX_NUM_INT_FEATURES) {
2768+
if (cn_features.empty() || cn_features.size() > MAX_NUM_INT_FEATURES) {
27712769
*num_features = 0;
27722770
return; // Feature extraction failed.
27732771
}

0 commit comments

Comments
 (0)