Skip to content

Commit 5b4ce24

Browse files
committed
ccmain: Replace NULL by nullptr
Signed-off-by: Stefan Weil <[email protected]>
1 parent 17e01ee commit 5b4ce24

36 files changed

+524
-524
lines changed

ccmain/adaptions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ BOOL8 Tesseract::word_adaptable( //should we adapt?
4747
uint16_t mode) {
4848
if (tessedit_adaption_debug) {
4949
tprintf("Running word_adaptable() for %s rating %.4f certainty %.4f\n",
50-
word->best_choice == NULL ? "" :
50+
word->best_choice == nullptr ? "" :
5151
word->best_choice->unichar_string().string(),
5252
word->best_choice->rating(), word->best_choice->certainty());
5353
}
@@ -106,7 +106,7 @@ BOOL8 Tesseract::word_adaptable( //should we adapt?
106106
}
107107

108108
if (flags.bit (CHECK_SPACES) &&
109-
(strchr(word->best_choice->unichar_string().string(), ' ') != NULL)) {
109+
(strchr(word->best_choice->unichar_string().string(), ' ') != nullptr)) {
110110
if (tessedit_adaption_debug) tprintf("word contains spaces\n");
111111
return FALSE;
112112
}

ccmain/applybox.cpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname,
120120
GenericVector<TBOX> boxes;
121121
GenericVector<STRING> texts, full_texts;
122122
if (!ReadAllBoxes(applybox_page, true, fname, &boxes, &texts, &full_texts,
123-
NULL)) {
124-
return NULL; // Can't do it.
123+
nullptr)) {
124+
return nullptr; // Can't do it.
125125
}
126126

127127
int box_count = boxes.size();
@@ -134,14 +134,14 @@ PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname,
134134
// In word mode, we use the boxes to make a word for each box, but
135135
// in blob mode we use the existing words and maximally chop them first.
136136
PAGE_RES* page_res = find_segmentation ?
137-
NULL : SetupApplyBoxes(boxes, block_list);
137+
nullptr : SetupApplyBoxes(boxes, block_list);
138138
clear_any_old_text(block_list);
139139

140140
for (int i = 0; i < boxes.size() - 1; i++) {
141141
bool foundit = false;
142-
if (page_res != NULL) {
142+
if (page_res != nullptr) {
143143
if (i == 0) {
144-
foundit = ResegmentCharBox(page_res, NULL, boxes[i], boxes[i + 1],
144+
foundit = ResegmentCharBox(page_res, nullptr, boxes[i], boxes[i + 1],
145145
full_texts[i].string());
146146
} else {
147147
foundit = ResegmentCharBox(page_res, &boxes[i-1], boxes[i],
@@ -158,7 +158,7 @@ PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname,
158158
}
159159
}
160160

161-
if (page_res == NULL) {
161+
if (page_res == nullptr) {
162162
// In word/line mode, we now maximally chop all the words and resegment
163163
// them with the classifier.
164164
page_res = SetupApplyBoxes(boxes, block_list);
@@ -236,10 +236,10 @@ PAGE_RES* Tesseract::SetupApplyBoxes(const GenericVector<TBOX>& boxes,
236236
}
237237
}
238238
}
239-
PAGE_RES* page_res = new PAGE_RES(false, block_list, NULL);
239+
PAGE_RES* page_res = new PAGE_RES(false, block_list, nullptr);
240240
PAGE_RES_IT pr_it(page_res);
241241
WERD_RES* word_res;
242-
while ((word_res = pr_it.word()) != NULL) {
242+
while ((word_res = pr_it.word()) != nullptr) {
243243
MaximallyChopWord(boxes, pr_it.block()->block,
244244
pr_it.row()->row, word_res);
245245
pr_it.forward();
@@ -254,7 +254,7 @@ void Tesseract::MaximallyChopWord(const GenericVector<TBOX>& boxes,
254254
BLOCK* block, ROW* row,
255255
WERD_RES* word_res) {
256256
if (!word_res->SetupForRecognition(unicharset, this, BestPix(),
257-
tessedit_ocr_engine_mode, NULL,
257+
tessedit_ocr_engine_mode, nullptr,
258258
classify_bln_numeric_mode,
259259
textord_use_cjk_fp_model,
260260
poly_allow_detailed_fx,
@@ -288,9 +288,9 @@ void Tesseract::MaximallyChopWord(const GenericVector<TBOX>& boxes,
288288
int right_chop_index = 0;
289289
if (!assume_fixed_pitch_char_segment) {
290290
// We only chop if the language is not fixed pitch like CJK.
291-
SEAM* seam = NULL;
291+
SEAM* seam = nullptr;
292292
while ((seam = chop_one_blob(boxes, blob_choices, word_res,
293-
&blob_number)) != NULL) {
293+
&blob_number)) != nullptr) {
294294
word_res->InsertSeam(blob_number, seam);
295295
BLOB_CHOICE* left_choice = blob_choices[blob_number];
296296
rating = left_choice->rating() / e;
@@ -345,7 +345,7 @@ bool Tesseract::ResegmentCharBox(PAGE_RES* page_res, const TBOX *prev_box,
345345
}
346346
PAGE_RES_IT page_res_it(page_res);
347347
WERD_RES* word_res;
348-
for (word_res = page_res_it.word(); word_res != NULL;
348+
for (word_res = page_res_it.word(); word_res != nullptr;
349349
word_res = page_res_it.forward()) {
350350
if (!word_res->box_word->bounding_box().major_overlap(box))
351351
continue;
@@ -381,7 +381,7 @@ bool Tesseract::ResegmentCharBox(PAGE_RES* page_res, const TBOX *prev_box,
381381
}
382382
if (!char_box.almost_equal(box, 3) &&
383383
(box.x_gap(next_box) < -3 ||
384-
(prev_box != NULL && prev_box->x_gap(box) < -3))) {
384+
(prev_box != nullptr && prev_box->x_gap(box) < -3))) {
385385
return false;
386386
}
387387
// We refine just the box_word, best_state and correct_text here.
@@ -441,7 +441,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list,
441441
if (applybox_debug > 1) {
442442
tprintf("\nAPPLY_BOX: in ResegmentWordBox() for %s\n", correct_text);
443443
}
444-
WERD* new_word = NULL;
444+
WERD* new_word = nullptr;
445445
BLOCK_IT b_it(block_list);
446446
for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
447447
BLOCK* block = b_it.data();
@@ -459,7 +459,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list,
459459
tprintf("Checking word:");
460460
word->bounding_box().print();
461461
}
462-
if (word->text() != NULL && word->text()[0] != '\0')
462+
if (word->text() != nullptr && word->text()[0] != '\0')
463463
continue; // Ignore words that are already done.
464464
if (!box.major_overlap(word->bounding_box()))
465465
continue;
@@ -488,7 +488,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list,
488488
tprintf("With next box:");
489489
next_box.print();
490490
}
491-
if (new_word == NULL) {
491+
if (new_word == nullptr) {
492492
// Make a new word with a single blob.
493493
new_word = word->shallow_copy();
494494
new_word->set_text(correct_text);
@@ -500,18 +500,18 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list,
500500
}
501501
}
502502
}
503-
if (new_word == NULL && applybox_debug > 0) tprintf("FAIL!\n");
504-
return new_word != NULL;
503+
if (new_word == nullptr && applybox_debug > 0) tprintf("FAIL!\n");
504+
return new_word != nullptr;
505505
}
506506

507507
/// Resegments the words by running the classifier in an attempt to find the
508508
/// correct segmentation that produces the required string.
509509
void Tesseract::ReSegmentByClassification(PAGE_RES* page_res) {
510510
PAGE_RES_IT pr_it(page_res);
511511
WERD_RES* word_res;
512-
for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) {
512+
for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) {
513513
WERD* word = word_res->word;
514-
if (word->text() == NULL || word->text()[0] == '\0')
514+
if (word->text() == nullptr || word->text()[0] == '\0')
515515
continue; // Ignore words that have no text.
516516
// Convert the correct text to a vector of UNICHAR_ID
517517
GenericVector<UNICHAR_ID> target_text;
@@ -536,7 +536,7 @@ bool Tesseract::ConvertStringToUnichars(const char* utf8,
536536
GenericVector<UNICHAR_ID>* class_ids) {
537537
for (int step = 0; *utf8 != '\0'; utf8 += step) {
538538
const char* next_space = strchr(utf8, ' ');
539-
if (next_space == NULL)
539+
if (next_space == nullptr)
540540
next_space = utf8 + strlen(utf8);
541541
step = next_space - utf8;
542542
UNICHAR_ID class_id = unicharset.unichar_to_id(utf8, step);
@@ -648,7 +648,7 @@ void Tesseract::SearchForText(const GenericVector<BLOB_CHOICE_LIST*>* choices,
648648
break;
649649
}
650650
// Search ambigs table.
651-
if (class_id < table.size() && table[class_id] != NULL) {
651+
if (class_id < table.size() && table[class_id] != nullptr) {
652652
AmbigSpec_IT spec_it(table[class_id]);
653653
for (spec_it.mark_cycle_pt(); !spec_it.cycled_list();
654654
spec_it.forward()) {
@@ -710,7 +710,7 @@ void Tesseract::TidyUp(PAGE_RES* page_res) {
710710
int unlabelled_words = 0;
711711
PAGE_RES_IT pr_it(page_res);
712712
WERD_RES* word_res;
713-
for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) {
713+
for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) {
714714
int ok_in_word = 0;
715715
int blob_count = word_res->correct_text.size();
716716
WERD_CHOICE* word_choice = new WERD_CHOICE(word_res->uch_set, blob_count);
@@ -742,7 +742,7 @@ void Tesseract::TidyUp(PAGE_RES* page_res) {
742742
}
743743
}
744744
pr_it.restart_page();
745-
for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) {
745+
for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) {
746746
// Denormalize back to a BoxWord.
747747
word_res->RebuildBestState();
748748
word_res->SetupBoxWord();
@@ -771,7 +771,7 @@ void Tesseract::ReportFailedBox(int boxfile_lineno, TBOX box,
771771
/** Creates a fake best_choice entry in each WERD_RES with the correct text.*/
772772
void Tesseract::CorrectClassifyWords(PAGE_RES* page_res) {
773773
PAGE_RES_IT pr_it(page_res);
774-
for (WERD_RES *word_res = pr_it.word(); word_res != NULL;
774+
for (WERD_RES *word_res = pr_it.word(); word_res != nullptr;
775775
word_res = pr_it.forward()) {
776776
WERD_CHOICE* choice = new WERD_CHOICE(word_res->uch_set,
777777
word_res->correct_text.size());
@@ -796,7 +796,7 @@ void Tesseract::CorrectClassifyWords(PAGE_RES* page_res) {
796796
void Tesseract::ApplyBoxTraining(const STRING& fontname, PAGE_RES* page_res) {
797797
PAGE_RES_IT pr_it(page_res);
798798
int word_count = 0;
799-
for (WERD_RES *word_res = pr_it.word(); word_res != NULL;
799+
for (WERD_RES *word_res = pr_it.word(); word_res != nullptr;
800800
word_res = pr_it.forward()) {
801801
LearnWord(fontname.string(), word_res);
802802
++word_count;

0 commit comments

Comments
 (0)