Skip to content

Commit 16e00b5

Browse files
committed
dict: Replace NULL by nullptr
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 800b290 commit 16e00b5

File tree

8 files changed

+72
-72
lines changed

8 files changed

+72
-72
lines changed

dict/dawg.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool Dawg::word_in_dawg(const WERD_CHOICE &word) const {
7373
int Dawg::check_for_words(const char *filename,
7474
const UNICHARSET &unicharset,
7575
bool enable_wildcard) const {
76-
if (filename == NULL) return 0;
76+
if (filename == nullptr) return 0;
7777

7878
FILE *word_file;
7979
char string [CHARS_PER_LINE];
@@ -82,7 +82,7 @@ int Dawg::check_for_words(const char *filename,
8282

8383
word_file = open_file (filename, "r");
8484

85-
while (fgets (string, CHARS_PER_LINE, word_file) != NULL) {
85+
while (fgets (string, CHARS_PER_LINE, word_file) != nullptr) {
8686
chomp_string(string); // remove newline
8787
WERD_CHOICE word(string, unicharset);
8888
if (word.length() > 0 &&
@@ -110,7 +110,7 @@ void Dawg::iterate_words(const UNICHARSET &unicharset,
110110

111111
void CallWithUTF8(TessCallback1<const char *> *cb, const WERD_CHOICE *wc) {
112112
STRING s;
113-
wc->string_and_lengths(&s, NULL);
113+
wc->string_and_lengths(&s, nullptr);
114114
cb->Run(s.string());
115115
}
116116

dict/dict.cpp

+28-28
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Image;
3333
Dict::Dict(CCUtil *ccutil)
3434
: letter_is_okay_(&tesseract::Dict::def_letter_is_okay),
3535
probability_in_context_(&tesseract::Dict::def_probability_in_context),
36-
params_model_classify_(NULL),
36+
params_model_classify_(nullptr),
3737
ccutil_(ccutil),
3838
STRING_MEMBER(user_words_file, "", "A filename of user-provided words.",
3939
getCCUtil()->params()),
@@ -164,29 +164,29 @@ Dict::Dict(CCUtil *ccutil)
164164
" are specified, since overly generic patterns can result in"
165165
" dawg search exploring an overly large number of options.",
166166
getCCUtil()->params()) {
167-
dang_ambigs_table_ = NULL;
168-
replace_ambigs_table_ = NULL;
167+
dang_ambigs_table_ = nullptr;
168+
replace_ambigs_table_ = nullptr;
169169
reject_offset_ = 0.0;
170-
go_deeper_fxn_ = NULL;
171-
hyphen_word_ = NULL;
170+
go_deeper_fxn_ = nullptr;
171+
hyphen_word_ = nullptr;
172172
last_word_on_line_ = false;
173173
hyphen_unichar_id_ = INVALID_UNICHAR_ID;
174-
document_words_ = NULL;
175-
dawg_cache_ = NULL;
174+
document_words_ = nullptr;
175+
dawg_cache_ = nullptr;
176176
dawg_cache_is_ours_ = false;
177-
pending_words_ = NULL;
178-
bigram_dawg_ = NULL;
179-
freq_dawg_ = NULL;
180-
punc_dawg_ = NULL;
181-
unambig_dawg_ = NULL;
177+
pending_words_ = nullptr;
178+
bigram_dawg_ = nullptr;
179+
freq_dawg_ = nullptr;
180+
punc_dawg_ = nullptr;
181+
unambig_dawg_ = nullptr;
182182
wordseg_rating_adjust_factor_ = -1.0f;
183-
output_ambig_words_file_ = NULL;
183+
output_ambig_words_file_ = nullptr;
184184
}
185185

186186
Dict::~Dict() {
187187
End();
188188
delete hyphen_word_;
189-
if (output_ambig_words_file_ != NULL) fclose(output_ambig_words_file_);
189+
if (output_ambig_words_file_ != nullptr) fclose(output_ambig_words_file_);
190190
}
191191

192192
DawgCache *Dict::GlobalDawgCache() {
@@ -205,7 +205,7 @@ void Dict::SetupForLoad(DawgCache *dawg_cache) {
205205
slash_unichar_id_ = getUnicharset().unichar_to_id(kSlashSymbol);
206206
hyphen_unichar_id_ = getUnicharset().unichar_to_id(kHyphenSymbol);
207207

208-
if (dawg_cache != NULL) {
208+
if (dawg_cache != nullptr) {
209209
dawg_cache_ = dawg_cache;
210210
dawg_cache_is_ours_ = false;
211211
} else {
@@ -330,7 +330,7 @@ bool Dict::FinishLoad() {
330330
SuccessorList *lst = new SuccessorList();
331331
for (int j = 0; j < dawgs_.length(); ++j) {
332332
const Dawg *other = dawgs_[j];
333-
if (dawg != NULL && other != NULL &&
333+
if (dawg != nullptr && other != nullptr &&
334334
(dawg->lang() == other->lang()) &&
335335
kDawgSuccessors[dawg->type()][other->type()]) *lst += j;
336336
}
@@ -350,14 +350,14 @@ void Dict::End() {
350350
dawg_cache_->FreeDawg(bigram_dawg_);
351351
if (dawg_cache_is_ours_) {
352352
delete dawg_cache_;
353-
dawg_cache_ = NULL;
353+
dawg_cache_ = nullptr;
354354
}
355355
successors_.delete_data_pointers();
356356
dawgs_.clear();
357357
successors_.clear();
358-
document_words_ = NULL;
358+
document_words_ = nullptr;
359359
delete pending_words_;
360-
pending_words_ = NULL;
360+
pending_words_ = nullptr;
361361
}
362362

363363
// Returns true if in light of the current state unichar_id is allowed
@@ -394,8 +394,8 @@ int Dict::def_letter_is_okay(void* void_dawg_args,
394394
// dawg_args->updated_pos.
395395
for (int a = 0; a < dawg_args->active_dawgs->length(); ++a) {
396396
const DawgPosition &pos = (*dawg_args->active_dawgs)[a];
397-
const Dawg *punc_dawg = pos.punc_index >= 0 ? dawgs_[pos.punc_index] : NULL;
398-
const Dawg *dawg = pos.dawg_index >= 0 ? dawgs_[pos.dawg_index] : NULL;
397+
const Dawg *punc_dawg = pos.punc_index >= 0 ? dawgs_[pos.punc_index] : nullptr;
398+
const Dawg *dawg = pos.dawg_index >= 0 ? dawgs_[pos.dawg_index] : nullptr;
399399

400400
if (!dawg && !punc_dawg) {
401401
// shouldn't happen.
@@ -499,7 +499,7 @@ int Dict::def_letter_is_okay(void* void_dawg_args,
499499
}
500500
if (dawg->permuter() > curr_perm) curr_perm = dawg->permuter();
501501
if (dawg->end_of_word(edge) &&
502-
(punc_dawg == NULL || punc_dawg->end_of_word(pos.punc_ref)))
502+
(punc_dawg == nullptr || punc_dawg->end_of_word(pos.punc_ref)))
503503
dawg_args->valid_end = true;
504504
dawg_args->updated_dawgs->add_unique(
505505
DawgPosition(pos.dawg_index, edge, pos.punc_index, pos.punc_ref,
@@ -581,11 +581,11 @@ void Dict::init_active_dawgs(DawgPositionVector *active_dawgs,
581581
void Dict::default_dawgs(DawgPositionVector *dawg_pos_vec,
582582
bool suppress_patterns) const {
583583
bool punc_dawg_available =
584-
(punc_dawg_ != NULL) &&
584+
(punc_dawg_ != nullptr) &&
585585
punc_dawg_->edge_char_of(0, Dawg::kPatternUnicharID, true) != NO_EDGE;
586586

587587
for (int i = 0; i < dawgs_.length(); i++) {
588-
if (dawgs_[i] != NULL &&
588+
if (dawgs_[i] != nullptr &&
589589
!(suppress_patterns && (dawgs_[i])->type() == DAWG_TYPE_PATTERN)) {
590590
int dawg_ty = dawgs_[i]->type();
591591
bool subsumed_by_punc = kDawgSuccessors[DAWG_TYPE_PUNCTUATION][dawg_ty];
@@ -607,7 +607,7 @@ void Dict::default_dawgs(DawgPositionVector *dawg_pos_vec,
607607

608608
void Dict::add_document_word(const WERD_CHOICE &best_choice) {
609609
// Do not add hyphenated word parts to the document dawg.
610-
// hyphen_word_ will be non-NULL after the set_hyphen_word() is
610+
// hyphen_word_ will be non-nullptr after the set_hyphen_word() is
611611
// called when the first part of the hyphenated word is
612612
// discovered and while the second part of the word is recognized.
613613
// hyphen_word_ is cleared in cc_recg() before the next word on
@@ -721,7 +721,7 @@ void Dict::adjust_word(WERD_CHOICE *word,
721721
}
722722
} else { // dictionary word
723723
if (case_is_ok) {
724-
if (!is_han && freq_dawg_ != NULL && freq_dawg_->word_in_dawg(*word)) {
724+
if (!is_han && freq_dawg_ != nullptr && freq_dawg_->word_in_dawg(*word)) {
725725
word->set_permuter(FREQ_DAWG_PERM);
726726
adjust_factor += segment_penalty_dict_frequent_word;
727727
new_rating *= adjust_factor;
@@ -778,7 +778,7 @@ int Dict::valid_word(const WERD_CHOICE &word, bool numbers_ok) const {
778778

779779
bool Dict::valid_bigram(const WERD_CHOICE &word1,
780780
const WERD_CHOICE &word2) const {
781-
if (bigram_dawg_ == NULL) return false;
781+
if (bigram_dawg_ == nullptr) return false;
782782

783783
// Extract the core word from the middle of each word with any digits
784784
// replaced with question marks.
@@ -838,7 +838,7 @@ bool Dict::valid_punctuation(const WERD_CHOICE &word) {
838838
}
839839
}
840840
for (i = 0; i < dawgs_.size(); ++i) {
841-
if (dawgs_[i] != NULL &&
841+
if (dawgs_[i] != nullptr &&
842842
dawgs_[i]->type() == DAWG_TYPE_PUNCTUATION &&
843843
dawgs_[i]->word_in_dawg(new_word)) return true;
844844
}

dict/dict.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Dict {
132132
}
133133
/// If this word is hyphenated copy the base word (the part on
134134
/// the line before) of a hyphenated word into the given word.
135-
/// This function assumes that word is not NULL.
135+
/// This function assumes that word is not nullptr.
136136
inline void copy_hyphen_info(WERD_CHOICE *word) const {
137137
if (this->hyphenated()) {
138138
*word = *hyphen_word_;
@@ -308,9 +308,9 @@ class Dict {
308308

309309
// Resets the document dictionary analogous to ResetAdaptiveClassifier.
310310
void ResetDocumentDictionary() {
311-
if (pending_words_ != NULL)
311+
if (pending_words_ != nullptr)
312312
pending_words_->clear();
313-
if (document_words_ != NULL)
313+
if (document_words_ != nullptr)
314314
document_words_->clear();
315315
}
316316

@@ -341,7 +341,7 @@ class Dict {
341341
* can be obtained from dawg_args->updated_dawgs passed to
342342
* def_letter_is_okay for word_index-1.
343343
* Note: the function assumes that active_dawgs, nd updated_dawgs
344-
* member variables of dawg_args are not NULL.
344+
* member variables of dawg_args are not nullptr.
345345
*
346346
* Output:
347347
* The function fills in dawg_args->updated_dawgs vector with the
@@ -401,7 +401,7 @@ class Dict {
401401
float ParamsModelClassify(const char *lang, void *path);
402402
// Call params_model_classify_ member function.
403403
float CallParamsModelClassify(void *path) {
404-
ASSERT_HOST(params_model_classify_ != NULL); // ASSERT_HOST -> assert
404+
ASSERT_HOST(params_model_classify_ != nullptr); // ASSERT_HOST -> assert
405405
return (this->*params_model_classify_)(
406406
getCCUtil()->lang.string(), path);
407407
}

dict/hyphen.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ namespace tesseract {
3131
// clear hyphen_active_dawgs_, hyphen_constraints_ update last_word_on_line_.
3232
void Dict::reset_hyphen_vars(bool last_word_on_line) {
3333
if (!(last_word_on_line_ == true && last_word_on_line == false)) {
34-
if (hyphen_word_ != NULL) {
34+
if (hyphen_word_ != nullptr) {
3535
delete hyphen_word_;
36-
hyphen_word_ = NULL;
36+
hyphen_word_ = nullptr;
3737
hyphen_active_dawgs_.clear();
3838
}
3939
}
@@ -48,7 +48,7 @@ void Dict::reset_hyphen_vars(bool last_word_on_line) {
4848
// hyphen_active_dawgs_.
4949
void Dict::set_hyphen_word(const WERD_CHOICE &word,
5050
const DawgPositionVector &active_dawgs) {
51-
if (hyphen_word_ == NULL) {
51+
if (hyphen_word_ == nullptr) {
5252
hyphen_word_ = new WERD_CHOICE(word.unicharset());
5353
hyphen_word_->make_bad();
5454
}

dict/permdawg.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ void Dict::go_deeper_dawg_fxn(
7373
GenericVector<UNICHAR_ID> encoding;
7474
const char *ngram_str = getUnicharset().id_to_unichar(orig_uch_id);
7575
// Since the string came out of the unicharset, failure is impossible.
76-
ASSERT_HOST(getUnicharset().encode_string(ngram_str, true, &encoding, NULL,
77-
NULL));
76+
ASSERT_HOST(getUnicharset().encode_string(ngram_str, true, &encoding, nullptr,
77+
nullptr));
7878
bool unigrams_ok = true;
7979
// Construct DawgArgs that reflect the current state.
8080
DawgPositionVector unigram_active_dawgs = *(more_args->active_dawgs);
@@ -119,21 +119,21 @@ void Dict::go_deeper_dawg_fxn(
119119
tprintf("found word = %s\n", word->debug_string().string());
120120
}
121121
if (strcmp(output_ambig_words_file.string(), "") != 0) {
122-
if (output_ambig_words_file_ == NULL) {
122+
if (output_ambig_words_file_ == nullptr) {
123123
output_ambig_words_file_ =
124124
fopen(output_ambig_words_file.string(), "wb+");
125-
if (output_ambig_words_file_ == NULL) {
125+
if (output_ambig_words_file_ == nullptr) {
126126
tprintf("Failed to open output_ambig_words_file %s\n",
127127
output_ambig_words_file.string());
128128
exit(1);
129129
}
130130
STRING word_str;
131-
word->string_and_lengths(&word_str, NULL);
131+
word->string_and_lengths(&word_str, nullptr);
132132
word_str += " ";
133133
fprintf(output_ambig_words_file_, "%s", word_str.string());
134134
}
135135
STRING word_str;
136-
word->string_and_lengths(&word_str, NULL);
136+
word->string_and_lengths(&word_str, nullptr);
137137
word_str += " ";
138138
fprintf(output_ambig_words_file_, "%s", word_str.string());
139139
}
@@ -187,8 +187,8 @@ WERD_CHOICE *Dict::dawg_permute_and_select(
187187
float certainties[MAX_WERD_LENGTH];
188188
this->go_deeper_fxn_ = &tesseract::Dict::go_deeper_dawg_fxn;
189189
int attempts_left = max_permuter_attempts;
190-
permute_choices((dawg_debug_level) ? "permute_dawg_debug" : NULL,
191-
char_choices, 0, NULL, &word, certainties, &rating_limit, best_choice,
190+
permute_choices((dawg_debug_level) ? "permute_dawg_debug" : nullptr,
191+
char_choices, 0, nullptr, &word, certainties, &rating_limit, best_choice,
192192
&attempts_left, &dawg_args);
193193
delete[] active_dawgs;
194194
return best_choice;
@@ -301,7 +301,7 @@ void Dict::append_choices(
301301
* present and whether they can be concatenated.
302302
*
303303
* The given prev_char_frag_info contains:
304-
* - fragment: if not NULL contains information about immediately
304+
* - fragment: if not nullptr contains information about immediately
305305
* preceding fragmented character choice
306306
* - num_fragments: number of fragments that have been used so far
307307
* to construct a character
@@ -311,7 +311,7 @@ void Dict::append_choices(
311311
* ratings concatenated so far
312312
*
313313
* The output char_frag_info is filled in as follows:
314-
* - character: is set to be NULL if the choice is a non-matching
314+
* - character: is set to be nullptr if the choice is a non-matching
315315
* or non-ending fragment piece; is set to unichar of the given choice
316316
* if it represents a regular character or a matching ending fragment
317317
* - fragment,num_fragments,certainty,rating are set as described above
@@ -326,7 +326,7 @@ bool Dict::fragment_state_okay(UNICHAR_ID curr_unichar_id,
326326
const CHAR_FRAGMENT *this_fragment =
327327
getUnicharset().get_fragment(curr_unichar_id);
328328
const CHAR_FRAGMENT *prev_fragment =
329-
prev_char_frag_info != NULL ? prev_char_frag_info->fragment : NULL;
329+
prev_char_frag_info != nullptr ? prev_char_frag_info->fragment : nullptr;
330330

331331
// Print debug info for fragments.
332332
if (debug && (prev_fragment || this_fragment)) {
@@ -361,7 +361,7 @@ bool Dict::fragment_state_okay(UNICHAR_ID curr_unichar_id,
361361
if (this_fragment->is_ending()) {
362362
char_frag_info->unichar_id =
363363
getUnicharset().unichar_to_id(this_fragment->get_unichar());
364-
char_frag_info->fragment = NULL;
364+
char_frag_info->fragment = nullptr;
365365
if (debug) {
366366
tprintf("Built character %s from fragments\n",
367367
getUnicharset().debug_str(

0 commit comments

Comments
 (0)