提交 16e00b59 编写于 作者: S Stefan Weil

dict: Replace NULL by nullptr

Signed-off-by: NStefan Weil <sw@weilnetz.de>
上级 800b290d
......@@ -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];
......@@ -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 &&
......@@ -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());
}
......
......@@ -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()),
......@@ -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() {
......@@ -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 {
......@@ -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;
}
......@@ -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
......@@ -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.
......@@ -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,
......@@ -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];
......@@ -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
......@@ -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;
......@@ -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.
......@@ -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;
}
......
......@@ -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_;
......@@ -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();
}
......@@ -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
......@@ -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);
}
......
......@@ -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();
}
}
......@@ -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();
}
......
......@@ -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);
......@@ -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());
}
......@@ -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;
......@@ -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
......@@ -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
......@@ -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)) {
......@@ -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(
......
......@@ -108,7 +108,7 @@ bool Dict::AcceptableChoice(const WERD_CHOICE& best_choice,
}
bool Dict::AcceptableResult(WERD_RES *word) const {
if (word->best_choice == NULL) return false;
if (word->best_choice == nullptr) return false;
float CertaintyThreshold = stopper_nondict_certainty_base - reject_offset_;
int WordSize;
......@@ -212,7 +212,7 @@ bool Dict::NoDangerousAmbig(WERD_CHOICE *best_choice,
wrong_ngram[wrong_ngram_index] = curr_unichar_id;
if (curr_unichar_id == INVALID_UNICHAR_ID ||
curr_unichar_id >= table.size() ||
table[curr_unichar_id] == NULL) {
table[curr_unichar_id] == nullptr) {
continue; // there is no ambig spec for this unichar id
}
AmbigSpec_IT spec_it(table[curr_unichar_id]);
......@@ -230,7 +230,7 @@ bool Dict::NoDangerousAmbig(WERD_CHOICE *best_choice,
}
if (compare == 0) {
// Record the place where we found an ambiguity.
if (fixpt != NULL) {
if (fixpt != nullptr) {
UNICHAR_ID leftmost_id = ambig_spec->correct_fragments[0];
fixpt->push_back(DANGERR_INFO(
blob_index, blob_index + num_wrong_blobs, replace,
......@@ -315,7 +315,7 @@ bool Dict::NoDangerousAmbig(WERD_CHOICE *best_choice,
tprintf ("Stopper: Possible ambiguous word = %s\n",
alt_word->debug_string().string());
}
if (fixpt != NULL) {
if (fixpt != nullptr) {
// Note: Currently character choices combined from fragments can only
// be generated by NoDangrousAmbigs(). This code should be updated if
// the capability to produce classifications combined from character
......@@ -356,7 +356,7 @@ bool Dict::NoDangerousAmbig(WERD_CHOICE *best_choice,
}
delete alt_word;
}
if (output_ambig_words_file_ != NULL) {
if (output_ambig_words_file_ != nullptr) {
fprintf(output_ambig_words_file_, "\n");
}
......@@ -384,16 +384,16 @@ void Dict::ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size,
// replaced choices.
float new_rating = 0.0f;
float new_certainty = 0.0f;
BLOB_CHOICE* old_choice = NULL;
BLOB_CHOICE* old_choice = nullptr;
for (i = 0; i < wrong_ngram_begin_index + wrong_ngram_size; ++i) {
if (i >= wrong_ngram_begin_index) {
int num_blobs = werd_choice->state(i);
int col = begin_blob_index + num_blobs_to_replace;
int row = col + num_blobs - 1;
BLOB_CHOICE_LIST* choices = ratings->get(col, row);
ASSERT_HOST(choices != NULL);
ASSERT_HOST(choices != nullptr);
old_choice = FindMatchingChoice(werd_choice->unichar_id(i), choices);
ASSERT_HOST(old_choice != NULL);
ASSERT_HOST(old_choice != nullptr);
new_rating += old_choice->rating();
new_certainty += old_choice->certainty();
num_blobs_to_replace += num_blobs;
......@@ -408,11 +408,11 @@ void Dict::ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size,
if (!coord.Valid(*ratings)) {
ratings->IncreaseBandSize(coord.row - coord.col + 1);
}
if (ratings->get(coord.col, coord.row) == NULL)
if (ratings->get(coord.col, coord.row) == nullptr)
ratings->put(coord.col, coord.row, new BLOB_CHOICE_LIST);
BLOB_CHOICE_LIST* new_choices = ratings->get(coord.col, coord.row);
BLOB_CHOICE* choice = FindMatchingChoice(correct_ngram_id, new_choices);
if (choice != NULL) {
if (choice != nullptr) {
// Already there. Upgrade if new rating better.
if (new_rating < choice->rating())
choice->set_rating(new_rating);
......
......@@ -177,7 +177,7 @@ void Trie::add_word_ending(EDGE_RECORD *edge_ptr,
bool Trie::add_word_to_dawg(const WERD_CHOICE &word,
const GenericVector<bool> *repetitions) {
if (word.length() <= 0) return false; // can't add empty words
if (repetitions != NULL) ASSERT_HOST(repetitions->size() == word.length());
if (repetitions != nullptr) ASSERT_HOST(repetitions->size() == word.length());
// Make sure the word does not contain invalid unchar ids.
for (int i = 0; i < word.length(); ++i) {
if (word.unichar_id(i) < 0 ||
......@@ -200,7 +200,7 @@ bool Trie::add_word_to_dawg(const WERD_CHOICE &word,
UNICHAR_ID unichar_id;
for (i = 0; i < word.length() - 1; ++i) {
unichar_id = word.unichar_id(i);
marker_flag = (repetitions != NULL) ? (*repetitions)[i] : false;
marker_flag = (repetitions != nullptr) ? (*repetitions)[i] : false;
if (debug_level_ > 1) tprintf("Adding letter %d\n", unichar_id);
if (still_finding_chars) {
found = edge_char_of(last_node, NO_EDGE, FORWARD_EDGE, word_end,
......@@ -247,7 +247,7 @@ bool Trie::add_word_to_dawg(const WERD_CHOICE &word,
}
the_next_node = 0;
unichar_id = word.unichar_id(i);
marker_flag = (repetitions != NULL) ? (*repetitions)[i] : false;
marker_flag = (repetitions != nullptr) ? (*repetitions)[i] : false;
if (debug_level_ > 1) tprintf("Adding letter %d\n", unichar_id);
if (still_finding_chars &&
edge_char_of(last_node, NO_EDGE, FORWARD_EDGE, false,
......@@ -302,9 +302,9 @@ bool Trie::read_word_list(const char *filename,
int word_count = 0;
word_file = fopen(filename, "rb");
if (word_file == NULL) return false;
if (word_file == nullptr) return false;
while (fgets(line_str, sizeof(line_str), word_file) != NULL) {
while (fgets(line_str, sizeof(line_str), word_file) != nullptr) {
chomp_string(line_str); // remove newline
STRING word_str(line_str);
++word_count;
......@@ -407,14 +407,14 @@ bool Trie::read_pattern_list(const char *filename,
}
FILE *pattern_file = fopen(filename, "rb");
if (pattern_file == NULL) {
if (pattern_file == nullptr) {
tprintf("Error opening pattern file %s\n", filename);
return false;
}
int pattern_count = 0;
char string[CHARS_PER_LINE];
while (fgets(string, CHARS_PER_LINE, pattern_file) != NULL) {
while (fgets(string, CHARS_PER_LINE, pattern_file) != nullptr) {
chomp_string(string); // remove newline
// Parse the pattern and construct a unichar id vector.
// Record the number of repetitions of each unichar in the parallel vector.
......@@ -483,7 +483,7 @@ bool Trie::read_pattern_list(const char *filename,
void Trie::remove_edge_linkage(NODE_REF node1, NODE_REF node2, int direction,
bool word_end, UNICHAR_ID unichar_id) {
EDGE_RECORD *edge_ptr = NULL;
EDGE_RECORD *edge_ptr = nullptr;
EDGE_INDEX edge_index = 0;
ASSERT_HOST(edge_char_of(node1, node2, direction, word_end,
unichar_id, &edge_ptr, &edge_index));
......@@ -579,7 +579,7 @@ bool Trie::eliminate_redundant_edges(NODE_REF node,
NODE_REF next_node2 = next_node_from_edge_rec(edge2);
TRIE_NODE_RECORD *next_node2_ptr = nodes_[next_node2];
// Translate all edges going to/from next_node2 to go to/from next_node1.
EDGE_RECORD *edge_ptr = NULL;
EDGE_RECORD *edge_ptr = nullptr;
EDGE_INDEX edge_index;
int i;
// The backward link in node to next_node2 will be zeroed out by the caller.
......
......@@ -257,7 +257,7 @@ class Trie : public Dawg {
// Adds a word to the Trie (creates the necessary nodes and edges).
//
// If repetitions vector is not NULL, each entry in the vector indicates
// If repetitions vector is not nullptr, each entry in the vector indicates
// whether the unichar id with the corresponding index in the word is allowed
// to repeat an unlimited number of times. For each entry that is true, MARKER
// flag of the corresponding edge created for this unichar id is set to true).
......@@ -267,7 +267,7 @@ class Trie : public Dawg {
bool add_word_to_dawg(const WERD_CHOICE &word,
const GenericVector<bool> *repetitions);
bool add_word_to_dawg(const WERD_CHOICE &word) {
return add_word_to_dawg(word, NULL);
return add_word_to_dawg(word, nullptr);
}
protected:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册