Skip to content

Commit cb6e9e0

Browse files
committed
training: Replace NULL by nullptr
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 9d6e4f6 commit cb6e9e0

24 files changed

+222
-222
lines changed

training/ambiguous_words.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ int main(int argc, char** argv) {
5656
vars_vec.push_back("output_ambig_words_file");
5757
vars_values.push_back(output_file_str);
5858
api.Init(tessdata_dir, lang.string(), tesseract::OEM_TESSERACT_ONLY,
59-
NULL, 0, &vars_vec, &vars_values, false);
59+
nullptr, 0, &vars_vec, &vars_values, false);
6060
tesseract::Dict &dict = api.tesseract()->getDict();
6161
FILE *input_file = fopen(input_file_str, "rb");
62-
if (input_file == NULL) {
62+
if (input_file == nullptr) {
6363
tprintf("Failed to open input wordlist file %s\n", input_file_str);
6464
exit(1);
6565
}
6666
char str[CHARS_PER_LINE];
6767

6868
// Read word list and call Dict::NoDangerousAmbig() for each word
6969
// to record ambiguities in the output file.
70-
while (fgets(str, CHARS_PER_LINE, input_file) != NULL) {
70+
while (fgets(str, CHARS_PER_LINE, input_file) != nullptr) {
7171
chomp_string(str); // remove newline
7272
WERD_CHOICE word(str, dict.getUnicharset());
73-
dict.NoDangerousAmbig(&word, NULL, false, NULL);
73+
dict.NoDangerousAmbig(&word, nullptr, false, nullptr);
7474
}
7575
// Clean up.
7676
fclose(input_file);

training/boxchar.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const int kMinNewlineRatio = 5;
3939
namespace tesseract {
4040

4141
BoxChar::BoxChar(const char* utf8_str, int len) : ch_(utf8_str, len) {
42-
box_ = NULL;
42+
box_ = nullptr;
4343
}
4444

4545
BoxChar::~BoxChar() { boxDestroy(&box_); }
@@ -53,7 +53,7 @@ void BoxChar::TranslateBoxes(int xshift, int yshift,
5353
std::vector<BoxChar*>* boxes) {
5454
for (int i = 0; i < boxes->size(); ++i) {
5555
BOX* box = (*boxes)[i]->box_;
56-
if (box != NULL) {
56+
if (box != nullptr) {
5757
box->x += xshift;
5858
box->y += yshift;
5959
}
@@ -69,7 +69,7 @@ void BoxChar::PrepareToWrite(std::vector<BoxChar*>* boxes) {
6969
InsertNewlines(rtl_rules, vertical_rules, boxes);
7070
InsertSpaces(rtl_rules, vertical_rules, boxes);
7171
for (int i = 0; i < boxes->size(); ++i) {
72-
if ((*boxes)[i]->box_ == NULL) tprintf("Null box at index %d\n", i);
72+
if ((*boxes)[i]->box_ == nullptr) tprintf("Null box at index %d\n", i);
7373
}
7474
if (rtl_rules) {
7575
ReorderRTLText(boxes);
@@ -84,14 +84,14 @@ void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules,
8484
int max_shift = 0;
8585
for (int i = 0; i < boxes->size(); ++i) {
8686
Box* box = (*boxes)[i]->box_;
87-
if (box == NULL) {
87+
if (box == nullptr) {
8888
if (prev_i < 0 || prev_i < i - 1 || i + 1 == boxes->size()) {
8989
// Erase null boxes at the start of a line and after another null box.
9090
do {
9191
delete (*boxes)[i];
9292
boxes->erase(boxes->begin() + i);
9393
--i;
94-
} while (i >= 0 && i + 1 == boxes->size() && (*boxes)[i]->box_ == NULL);
94+
} while (i >= 0 && i + 1 == boxes->size() && (*boxes)[i]->box_ == nullptr);
9595
}
9696
continue;
9797
}
@@ -139,18 +139,18 @@ void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules,
139139
}
140140
}
141141

142-
// Converts NULL boxes to space characters, with appropriate bounding boxes.
142+
// Converts nullptr boxes to space characters, with appropriate bounding boxes.
143143
/* static */
144144
void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
145145
std::vector<BoxChar*>* boxes) {
146146
// After InsertNewlines, any remaining null boxes are not newlines, and are
147147
// singletons, so add a box to each remaining null box.
148148
for (int i = 1; i + 1 < boxes->size(); ++i) {
149149
Box* box = (*boxes)[i]->box_;
150-
if (box == NULL) {
150+
if (box == nullptr) {
151151
Box* prev = (*boxes)[i - 1]->box_;
152152
Box* next = (*boxes)[i + 1]->box_;
153-
ASSERT_HOST(prev != NULL && next != NULL);
153+
ASSERT_HOST(prev != nullptr && next != nullptr);
154154
int top = MIN(prev->y, next->y);
155155
int bottom = MAX(prev->y + prev->h, next->y + next->h);
156156
int left = prev->x + prev->w;
@@ -170,14 +170,14 @@ void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
170170
j >= 0 && (*boxes)[j]->ch_ != " " && (*boxes)[j]->ch_ != "\t";
171171
--j) {
172172
prev = (*boxes)[j]->box_;
173-
ASSERT_HOST(prev != NULL);
173+
ASSERT_HOST(prev != nullptr);
174174
if (prev->x < right) {
175175
right = prev->x;
176176
}
177177
}
178178
// Left becomes the max right of all next boxes forward to the first
179179
// space or newline.
180-
for (int j = i + 2; j < boxes->size() && (*boxes)[j]->box_ != NULL &&
180+
for (int j = i + 2; j < boxes->size() && (*boxes)[j]->box_ != nullptr &&
181181
(*boxes)[j]->ch_ != "\t";
182182
++j) {
183183
next = (*boxes)[j]->box_;
@@ -244,7 +244,7 @@ bool BoxChar::ContainsMostlyRTL(const std::vector<BoxChar*>& boxes) {
244244
bool BoxChar::MostlyVertical(const std::vector<BoxChar*>& boxes) {
245245
inT64 total_dx = 0, total_dy = 0;
246246
for (int i = 1; i < boxes.size(); ++i) {
247-
if (boxes[i - 1]->box_ != NULL && boxes[i]->box_ != NULL &&
247+
if (boxes[i - 1]->box_ != nullptr && boxes[i]->box_ != nullptr &&
248248
boxes[i - 1]->page_ == boxes[i]->page_) {
249249
int dx = boxes[i]->box_->x - boxes[i - 1]->box_->x;
250250
int dy = boxes[i]->box_->y - boxes[i - 1]->box_->y;
@@ -303,7 +303,7 @@ string BoxChar::GetTesseractBoxStr(int height,
303303
char buffer[kMaxLineLength];
304304
for (int i = 0; i < boxes.size(); ++i) {
305305
const Box* box = boxes[i]->box_;
306-
if (box == NULL) {
306+
if (box == nullptr) {
307307
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
308308
return "";
309309
}

training/boxchar.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class BoxChar {
6060
// Sort function for sorting by left edge of box. Note that this will not
6161
// work properly until after InsertNewlines and InsertSpaces.
6262
bool operator<(const BoxChar& other) const {
63-
if (box_ == NULL) return true;
64-
if (other.box_ == NULL) return false;
63+
if (box_ == nullptr) return true;
64+
if (other.box_ == nullptr) return false;
6565
return box_->x < other.box_->x;
6666
}
6767

@@ -74,7 +74,7 @@ class BoxChar {
7474
// Inserts newline (tab) characters into the vector at newline positions.
7575
static void InsertNewlines(bool rtl_rules, bool vertical_rules,
7676
vector<BoxChar*>* boxes);
77-
// Converts NULL boxes to space characters, with appropriate bounding boxes.
77+
// Converts nullptr boxes to space characters, with appropriate bounding boxes.
7878
static void InsertSpaces(bool rtl_rules, bool vertical_rules,
7979
vector<BoxChar*>* boxes);
8080
// Reorders text in a right-to-left script in left-to-right order.

training/classifier_tester.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum ClassifierName {
4040
};
4141

4242
const char* names[] = {"pruner", "full",
43-
NULL};
43+
nullptr};
4444

4545
static tesseract::ShapeClassifier* InitializeClassifier(
4646
const char* classifer_name, const UNICHARSET& unicharset,
@@ -56,33 +56,33 @@ static tesseract::ShapeClassifier* InitializeClassifier(
5656
}
5757
if (classifier == CN_COUNT) {
5858
fprintf(stderr, "Invalid classifier name:%s\n", FLAGS_classifier.c_str());
59-
return NULL;
59+
return nullptr;
6060
}
6161

6262
// We need to initialize tesseract to test.
6363
*api = new tesseract::TessBaseAPI;
6464
tesseract::OcrEngineMode engine_mode = tesseract::OEM_TESSERACT_ONLY;
65-
tesseract::Tesseract* tesseract = NULL;
66-
tesseract::Classify* classify = NULL;
65+
tesseract::Tesseract* tesseract = nullptr;
66+
tesseract::Classify* classify = nullptr;
6767
if (
6868
classifier == CN_PRUNER || classifier == CN_FULL) {
6969
if ((*api)->Init(FLAGS_tessdata_dir.c_str(), FLAGS_lang.c_str(),
7070
engine_mode) < 0) {
7171
fprintf(stderr, "Tesseract initialization failed!\n");
72-
return NULL;
72+
return nullptr;
7373
}
7474
tesseract = const_cast<tesseract::Tesseract*>((*api)->tesseract());
7575
classify = reinterpret_cast<tesseract::Classify*>(tesseract);
76-
if (classify->shape_table() == NULL) {
76+
if (classify->shape_table() == nullptr) {
7777
fprintf(stderr, "Tesseract must contain a ShapeTable!\n");
78-
return NULL;
78+
return nullptr;
7979
}
8080
}
81-
tesseract::ShapeClassifier* shape_classifier = NULL;
81+
tesseract::ShapeClassifier* shape_classifier = nullptr;
8282

8383
if (!FLAGS_T.empty()) {
8484
const char* config_name;
85-
while ((config_name = GetNextFilename(argc, argv)) != NULL) {
85+
while ((config_name = GetNextFilename(argc, argv)) != nullptr) {
8686
tprintf("Reading config file %s ...\n", config_name);
8787
(*api)->ReadConfigFile(config_name);
8888
}
@@ -93,7 +93,7 @@ static tesseract::ShapeClassifier* InitializeClassifier(
9393
shape_classifier = new tesseract::TessClassifier(false, classify);
9494
} else {
9595
fprintf(stderr, "%s tester not yet implemented\n", classifer_name);
96-
return NULL;
96+
return nullptr;
9797
}
9898
tprintf("Testing classifier %s:\n", classifer_name);
9999
return shape_classifier;
@@ -122,12 +122,12 @@ int main(int argc, char **argv) {
122122
ParseArguments(&argc, &argv);
123123
STRING file_prefix;
124124
tesseract::MasterTrainer* trainer = tesseract::LoadTrainingData(
125-
argc, argv, false, NULL, &file_prefix);
125+
argc, argv, false, nullptr, &file_prefix);
126126
tesseract::TessBaseAPI* api;
127127
// Decode the classifier string.
128128
tesseract::ShapeClassifier* shape_classifier = InitializeClassifier(
129129
FLAGS_classifier.c_str(), trainer->unicharset(), argc, argv, &api);
130-
if (shape_classifier == NULL) {
130+
if (shape_classifier == nullptr) {
131131
fprintf(stderr, "Classifier init failed!:%s\n", FLAGS_classifier.c_str());
132132
return 1;
133133
}
@@ -139,7 +139,7 @@ int main(int argc, char **argv) {
139139

140140
trainer->TestClassifierOnSamples(tesseract:: CT_UNICHAR_TOP1_ERR,
141141
MAX(3, FLAGS_debug_level), false,
142-
shape_classifier, NULL);
142+
shape_classifier, nullptr);
143143
delete shape_classifier;
144144
delete api;
145145
delete trainer;

training/cntraining.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int main(int argc, char *argv[]) {
137137
const char *PageName;
138138
FILE *TrainingPage;
139139
LIST CharList = NIL_LIST;
140-
CLUSTERER *Clusterer = NULL;
140+
CLUSTERER *Clusterer = nullptr;
141141
LIST ProtoList = NIL_LIST;
142142
LIST NormProtoList = NIL_LIST;
143143
LIST pCharList;
@@ -147,11 +147,11 @@ int main(int argc, char *argv[]) {
147147

148148
ParseArguments(&argc, &argv);
149149
int num_fonts = 0;
150-
while ((PageName = GetNextFilename(argc, argv)) != NULL) {
150+
while ((PageName = GetNextFilename(argc, argv)) != nullptr) {
151151
printf("Reading %s ...\n", PageName);
152152
TrainingPage = Efopen(PageName, "rb");
153153
ReadTrainingSamples(FeatureDefs, PROGRAM_FEATURE_TYPE,
154-
100, NULL, TrainingPage, &CharList);
154+
100, nullptr, TrainingPage, &CharList);
155155
fclose(TrainingPage);
156156
++num_fonts;
157157
}
@@ -168,7 +168,7 @@ int main(int argc, char *argv[]) {
168168
CharSample = (LABELEDLIST)first_node(pCharList);
169169
Clusterer =
170170
SetUpForClustering(FeatureDefs, CharSample, PROGRAM_FEATURE_TYPE);
171-
if (Clusterer == NULL) { // To avoid a SIGSEGV
171+
if (Clusterer == nullptr) { // To avoid a SIGSEGV
172172
fprintf(stderr, "Error: NULL clusterer!\n");
173173
return 1;
174174
}
@@ -229,7 +229,7 @@ void WriteNormProtos(const char *Directory, LIST LabeledProtoList,
229229
int N;
230230

231231
Filename = "";
232-
if (Directory != NULL && Directory[0] != '\0')
232+
if (Directory != nullptr && Directory[0] != '\0')
233233
{
234234
Filename += Directory;
235235
Filename += "/";

0 commit comments

Comments
 (0)