Skip to content

Commit

Permalink
dict: Replace NULL by nullptr
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Apr 22, 2018
1 parent 800b290 commit 16e00b5
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 72 deletions.
6 changes: 3 additions & 3 deletions dict/dawg.cpp
Expand Up @@ -73,7 +73,7 @@ bool Dawg::word_in_dawg(const WERD_CHOICE &word) const {
int Dawg::check_for_words(const char *filename,
const UNICHARSET &unicharset,
bool enable_wildcard) const {
if (filename == NULL) return 0;
if (filename == nullptr) return 0;

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

word_file = open_file (filename, "r");

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

void CallWithUTF8(TessCallback1<const char *> *cb, const WERD_CHOICE *wc) {
STRING s;
wc->string_and_lengths(&s, NULL);
wc->string_and_lengths(&s, nullptr);
cb->Run(s.string());
}

Expand Down
56 changes: 28 additions & 28 deletions dict/dict.cpp
Expand Up @@ -33,7 +33,7 @@ class Image;
Dict::Dict(CCUtil *ccutil)
: letter_is_okay_(&tesseract::Dict::def_letter_is_okay),
probability_in_context_(&tesseract::Dict::def_probability_in_context),
params_model_classify_(NULL),
params_model_classify_(nullptr),
ccutil_(ccutil),
STRING_MEMBER(user_words_file, "", "A filename of user-provided words.",
getCCUtil()->params()),
Expand Down Expand Up @@ -164,29 +164,29 @@ Dict::Dict(CCUtil *ccutil)
" are specified, since overly generic patterns can result in"
" dawg search exploring an overly large number of options.",
getCCUtil()->params()) {
dang_ambigs_table_ = NULL;
replace_ambigs_table_ = NULL;
dang_ambigs_table_ = nullptr;
replace_ambigs_table_ = nullptr;
reject_offset_ = 0.0;
go_deeper_fxn_ = NULL;
hyphen_word_ = NULL;
go_deeper_fxn_ = nullptr;
hyphen_word_ = nullptr;
last_word_on_line_ = false;
hyphen_unichar_id_ = INVALID_UNICHAR_ID;
document_words_ = NULL;
dawg_cache_ = NULL;
document_words_ = nullptr;
dawg_cache_ = nullptr;
dawg_cache_is_ours_ = false;
pending_words_ = NULL;
bigram_dawg_ = NULL;
freq_dawg_ = NULL;
punc_dawg_ = NULL;
unambig_dawg_ = NULL;
pending_words_ = nullptr;
bigram_dawg_ = nullptr;
freq_dawg_ = nullptr;
punc_dawg_ = nullptr;
unambig_dawg_ = nullptr;
wordseg_rating_adjust_factor_ = -1.0f;
output_ambig_words_file_ = NULL;
output_ambig_words_file_ = nullptr;
}

Dict::~Dict() {
End();
delete hyphen_word_;
if (output_ambig_words_file_ != NULL) fclose(output_ambig_words_file_);
if (output_ambig_words_file_ != nullptr) fclose(output_ambig_words_file_);
}

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

if (dawg_cache != NULL) {
if (dawg_cache != nullptr) {
dawg_cache_ = dawg_cache;
dawg_cache_is_ours_ = false;
} else {
Expand Down Expand Up @@ -330,7 +330,7 @@ bool Dict::FinishLoad() {
SuccessorList *lst = new SuccessorList();
for (int j = 0; j < dawgs_.length(); ++j) {
const Dawg *other = dawgs_[j];
if (dawg != NULL && other != NULL &&
if (dawg != nullptr && other != nullptr &&
(dawg->lang() == other->lang()) &&
kDawgSuccessors[dawg->type()][other->type()]) *lst += j;
}
Expand All @@ -350,14 +350,14 @@ void Dict::End() {
dawg_cache_->FreeDawg(bigram_dawg_);
if (dawg_cache_is_ours_) {
delete dawg_cache_;
dawg_cache_ = NULL;
dawg_cache_ = nullptr;
}
successors_.delete_data_pointers();
dawgs_.clear();
successors_.clear();
document_words_ = NULL;
document_words_ = nullptr;
delete pending_words_;
pending_words_ = NULL;
pending_words_ = nullptr;
}

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

if (!dawg && !punc_dawg) {
// shouldn't happen.
Expand Down Expand Up @@ -499,7 +499,7 @@ int Dict::def_letter_is_okay(void* void_dawg_args,
}
if (dawg->permuter() > curr_perm) curr_perm = dawg->permuter();
if (dawg->end_of_word(edge) &&
(punc_dawg == NULL || punc_dawg->end_of_word(pos.punc_ref)))
(punc_dawg == nullptr || punc_dawg->end_of_word(pos.punc_ref)))
dawg_args->valid_end = true;
dawg_args->updated_dawgs->add_unique(
DawgPosition(pos.dawg_index, edge, pos.punc_index, pos.punc_ref,
Expand Down Expand Up @@ -581,11 +581,11 @@ void Dict::init_active_dawgs(DawgPositionVector *active_dawgs,
void Dict::default_dawgs(DawgPositionVector *dawg_pos_vec,
bool suppress_patterns) const {
bool punc_dawg_available =
(punc_dawg_ != NULL) &&
(punc_dawg_ != nullptr) &&
punc_dawg_->edge_char_of(0, Dawg::kPatternUnicharID, true) != NO_EDGE;

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

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

bool Dict::valid_bigram(const WERD_CHOICE &word1,
const WERD_CHOICE &word2) const {
if (bigram_dawg_ == NULL) return false;
if (bigram_dawg_ == nullptr) return false;

// Extract the core word from the middle of each word with any digits
// replaced with question marks.
Expand Down Expand Up @@ -838,7 +838,7 @@ bool Dict::valid_punctuation(const WERD_CHOICE &word) {
}
}
for (i = 0; i < dawgs_.size(); ++i) {
if (dawgs_[i] != NULL &&
if (dawgs_[i] != nullptr &&
dawgs_[i]->type() == DAWG_TYPE_PUNCTUATION &&
dawgs_[i]->word_in_dawg(new_word)) return true;
}
Expand Down
10 changes: 5 additions & 5 deletions dict/dict.h
Expand Up @@ -132,7 +132,7 @@ class Dict {
}
/// If this word is hyphenated copy the base word (the part on
/// the line before) of a hyphenated word into the given word.
/// This function assumes that word is not NULL.
/// This function assumes that word is not nullptr.
inline void copy_hyphen_info(WERD_CHOICE *word) const {
if (this->hyphenated()) {
*word = *hyphen_word_;
Expand Down Expand Up @@ -308,9 +308,9 @@ class Dict {

// Resets the document dictionary analogous to ResetAdaptiveClassifier.
void ResetDocumentDictionary() {
if (pending_words_ != NULL)
if (pending_words_ != nullptr)
pending_words_->clear();
if (document_words_ != NULL)
if (document_words_ != nullptr)
document_words_->clear();
}

Expand Down Expand Up @@ -341,7 +341,7 @@ class Dict {
* can be obtained from dawg_args->updated_dawgs passed to
* def_letter_is_okay for word_index-1.
* Note: the function assumes that active_dawgs, nd updated_dawgs
* member variables of dawg_args are not NULL.
* member variables of dawg_args are not nullptr.
*
* Output:
* The function fills in dawg_args->updated_dawgs vector with the
Expand Down Expand Up @@ -401,7 +401,7 @@ class Dict {
float ParamsModelClassify(const char *lang, void *path);
// Call params_model_classify_ member function.
float CallParamsModelClassify(void *path) {
ASSERT_HOST(params_model_classify_ != NULL); // ASSERT_HOST -> assert
ASSERT_HOST(params_model_classify_ != nullptr); // ASSERT_HOST -> assert
return (this->*params_model_classify_)(
getCCUtil()->lang.string(), path);
}
Expand Down
6 changes: 3 additions & 3 deletions dict/hyphen.cpp
Expand Up @@ -31,9 +31,9 @@ namespace tesseract {
// clear hyphen_active_dawgs_, hyphen_constraints_ update last_word_on_line_.
void Dict::reset_hyphen_vars(bool last_word_on_line) {
if (!(last_word_on_line_ == true && last_word_on_line == false)) {
if (hyphen_word_ != NULL) {
if (hyphen_word_ != nullptr) {
delete hyphen_word_;
hyphen_word_ = NULL;
hyphen_word_ = nullptr;
hyphen_active_dawgs_.clear();
}
}
Expand All @@ -48,7 +48,7 @@ void Dict::reset_hyphen_vars(bool last_word_on_line) {
// hyphen_active_dawgs_.
void Dict::set_hyphen_word(const WERD_CHOICE &word,
const DawgPositionVector &active_dawgs) {
if (hyphen_word_ == NULL) {
if (hyphen_word_ == nullptr) {
hyphen_word_ = new WERD_CHOICE(word.unicharset());
hyphen_word_->make_bad();
}
Expand Down
24 changes: 12 additions & 12 deletions dict/permdawg.cpp
Expand Up @@ -73,8 +73,8 @@ void Dict::go_deeper_dawg_fxn(
GenericVector<UNICHAR_ID> encoding;
const char *ngram_str = getUnicharset().id_to_unichar(orig_uch_id);
// Since the string came out of the unicharset, failure is impossible.
ASSERT_HOST(getUnicharset().encode_string(ngram_str, true, &encoding, NULL,
NULL));
ASSERT_HOST(getUnicharset().encode_string(ngram_str, true, &encoding, nullptr,
nullptr));
bool unigrams_ok = true;
// Construct DawgArgs that reflect the current state.
DawgPositionVector unigram_active_dawgs = *(more_args->active_dawgs);
Expand Down Expand Up @@ -119,21 +119,21 @@ void Dict::go_deeper_dawg_fxn(
tprintf("found word = %s\n", word->debug_string().string());
}
if (strcmp(output_ambig_words_file.string(), "") != 0) {
if (output_ambig_words_file_ == NULL) {
if (output_ambig_words_file_ == nullptr) {
output_ambig_words_file_ =
fopen(output_ambig_words_file.string(), "wb+");
if (output_ambig_words_file_ == NULL) {
if (output_ambig_words_file_ == nullptr) {
tprintf("Failed to open output_ambig_words_file %s\n",
output_ambig_words_file.string());
exit(1);
}
STRING word_str;
word->string_and_lengths(&word_str, NULL);
word->string_and_lengths(&word_str, nullptr);
word_str += " ";
fprintf(output_ambig_words_file_, "%s", word_str.string());
}
STRING word_str;
word->string_and_lengths(&word_str, NULL);
word->string_and_lengths(&word_str, nullptr);
word_str += " ";
fprintf(output_ambig_words_file_, "%s", word_str.string());
}
Expand Down Expand Up @@ -187,8 +187,8 @@ WERD_CHOICE *Dict::dawg_permute_and_select(
float certainties[MAX_WERD_LENGTH];
this->go_deeper_fxn_ = &tesseract::Dict::go_deeper_dawg_fxn;
int attempts_left = max_permuter_attempts;
permute_choices((dawg_debug_level) ? "permute_dawg_debug" : NULL,
char_choices, 0, NULL, &word, certainties, &rating_limit, best_choice,
permute_choices((dawg_debug_level) ? "permute_dawg_debug" : nullptr,
char_choices, 0, nullptr, &word, certainties, &rating_limit, best_choice,
&attempts_left, &dawg_args);
delete[] active_dawgs;
return best_choice;
Expand Down Expand Up @@ -301,7 +301,7 @@ void Dict::append_choices(
* present and whether they can be concatenated.
*
* The given prev_char_frag_info contains:
* - fragment: if not NULL contains information about immediately
* - fragment: if not nullptr contains information about immediately
* preceding fragmented character choice
* - num_fragments: number of fragments that have been used so far
* to construct a character
Expand All @@ -311,7 +311,7 @@ void Dict::append_choices(
* ratings concatenated so far
*
* The output char_frag_info is filled in as follows:
* - character: is set to be NULL if the choice is a non-matching
* - character: is set to be nullptr if the choice is a non-matching
* or non-ending fragment piece; is set to unichar of the given choice
* if it represents a regular character or a matching ending fragment
* - fragment,num_fragments,certainty,rating are set as described above
Expand All @@ -326,7 +326,7 @@ bool Dict::fragment_state_okay(UNICHAR_ID curr_unichar_id,
const CHAR_FRAGMENT *this_fragment =
getUnicharset().get_fragment(curr_unichar_id);
const CHAR_FRAGMENT *prev_fragment =
prev_char_frag_info != NULL ? prev_char_frag_info->fragment : NULL;
prev_char_frag_info != nullptr ? prev_char_frag_info->fragment : nullptr;

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

0 comments on commit 16e00b5

Please sign in to comment.