Skip to content

Commit

Permalink
ccutil: 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 e74d997 commit 57755a2
Show file tree
Hide file tree
Showing 40 changed files with 726 additions and 726 deletions.
50 changes: 25 additions & 25 deletions ccutil/ambigs.cpp
Expand Up @@ -45,16 +45,16 @@ AmbigSpec::AmbigSpec() {

ELISTIZE(AmbigSpec)

// Initializes the ambigs by adding a NULL pointer to each table.
// Initializes the ambigs by adding a nullptr pointer to each table.
void UnicharAmbigs::InitUnicharAmbigs(const UNICHARSET& unicharset,
bool use_ambigs_for_adaption) {
for (int i = 0; i < unicharset.size(); ++i) {
replace_ambigs_.push_back(NULL);
dang_ambigs_.push_back(NULL);
one_to_one_definite_ambigs_.push_back(NULL);
replace_ambigs_.push_back(nullptr);
dang_ambigs_.push_back(nullptr);
one_to_one_definite_ambigs_.push_back(nullptr);
if (use_ambigs_for_adaption) {
ambigs_for_adaption_.push_back(NULL);
reverse_ambigs_for_adaption_.push_back(NULL);
ambigs_for_adaption_.push_back(nullptr);
reverse_ambigs_for_adaption_.push_back(nullptr);
}
}
}
Expand Down Expand Up @@ -89,15 +89,15 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,

// Determine the version of the ambigs file.
int version = 0;
ASSERT_HOST(ambig_file->FGets(buffer, kBufferSize) != NULL &&
ASSERT_HOST(ambig_file->FGets(buffer, kBufferSize) != nullptr &&
strlen(buffer) > 0);
if (*buffer == 'v') {
version = static_cast<int>(strtol(buffer+1, NULL, 10));
version = static_cast<int>(strtol(buffer+1, nullptr, 10));
++line_num;
} else {
ambig_file->Rewind();
}
while (ambig_file->FGets(buffer, kBufferSize) != NULL) {
while (ambig_file->FGets(buffer, kBufferSize) != nullptr) {
chomp_string(buffer);
if (debug_level > 2) tprintf("read line %s\n", buffer);
++line_num;
Expand All @@ -117,7 +117,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
// Update one_to_one_definite_ambigs_.
if (test_ambig_part_size == 1 &&
replacement_ambig_part_size == 1 && type == DEFINITE_AMBIG) {
if (one_to_one_definite_ambigs_[test_unichar_ids[0]] == NULL) {
if (one_to_one_definite_ambigs_[test_unichar_ids[0]] == nullptr) {
one_to_one_definite_ambigs_[test_unichar_ids[0]] = new UnicharIdVector();
}
one_to_one_definite_ambigs_[test_unichar_ids[0]]->push_back(
Expand All @@ -129,9 +129,9 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
// Silently ignore invalid strings, as before, so it is safe to use a
// universal ambigs file.
if (unicharset->encode_string(replacement_string, true, &encoding,
NULL, NULL)) {
nullptr, nullptr)) {
for (i = 0; i < test_ambig_part_size; ++i) {
if (ambigs_for_adaption_[test_unichar_ids[i]] == NULL) {
if (ambigs_for_adaption_[test_unichar_ids[i]] == nullptr) {
ambigs_for_adaption_[test_unichar_ids[i]] = new UnicharIdVector();
}
adaption_ambigs_entry = ambigs_for_adaption_[test_unichar_ids[i]];
Expand Down Expand Up @@ -160,10 +160,10 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
if (use_ambigs_for_adaption) {
for (i = 0; i < ambigs_for_adaption_.size(); ++i) {
adaption_ambigs_entry = ambigs_for_adaption_[i];
if (adaption_ambigs_entry == NULL) continue;
if (adaption_ambigs_entry == nullptr) continue;
for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
UNICHAR_ID ambig_id = (*adaption_ambigs_entry)[j];
if (reverse_ambigs_for_adaption_[ambig_id] == NULL) {
if (reverse_ambigs_for_adaption_[ambig_id] == nullptr) {
reverse_ambigs_for_adaption_[ambig_id] = new UnicharIdVector();
}
reverse_ambigs_for_adaption_[ambig_id]->push_back(i);
Expand All @@ -178,7 +178,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
(tbl == 0) ? replace_ambigs_ : dang_ambigs_;
for (i = 0; i < print_table.size(); ++i) {
AmbigSpec_LIST *lst = print_table[i];
if (lst == NULL) continue;
if (lst == nullptr) continue;
if (!lst->empty()) {
tprintf("%s Ambiguities for %s:\n",
(tbl == 0) ? "Replaceable" : "Dangerous",
Expand All @@ -200,7 +200,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
ambigs_for_adaption_ : reverse_ambigs_for_adaption_;
for (i = 0; i < vec.size(); ++i) {
adaption_ambigs_entry = vec[i];
if (adaption_ambigs_entry != NULL) {
if (adaption_ambigs_entry != nullptr) {
tprintf("%sAmbigs for adaption for %s:\n",
(vec_id == 0) ? "" : "Reverse ",
unicharset->debug_str(i).string());
Expand Down Expand Up @@ -231,8 +231,8 @@ bool UnicharAmbigs::ParseAmbiguityLine(
}
// Encode wrong-string.
GenericVector<UNICHAR_ID> unichars;
if (!unicharset.encode_string(fields[0].string(), true, &unichars, NULL,
NULL)) {
if (!unicharset.encode_string(fields[0].string(), true, &unichars, nullptr,
nullptr)) {
return false;
}
*test_ambig_part_size = unichars.size();
Expand All @@ -246,8 +246,8 @@ bool UnicharAmbigs::ParseAmbiguityLine(
test_unichar_ids[i] = unichars[i];
test_unichar_ids[unichars.size()] = INVALID_UNICHAR_ID;
// Encode replacement-string to check validity.
if (!unicharset.encode_string(fields[1].string(), true, &unichars, NULL,
NULL)) {
if (!unicharset.encode_string(fields[1].string(), true, &unichars, nullptr,
nullptr)) {
return false;
}
*replacement_ambig_part_size = unichars.size();
Expand Down Expand Up @@ -278,7 +278,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
return false;
}
for (i = 0; i < *test_ambig_part_size; ++i) {
if (!(token = strtok_r(NULL, kAmbigDelimiters, &next_token))) break;
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token))) break;
if (!unicharset.contains_unichar(token)) {
if (debug_level) tprintf(kIllegalUnicharMsg, token);
break;
Expand All @@ -288,7 +288,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
test_unichar_ids[i] = INVALID_UNICHAR_ID;

if (i != *test_ambig_part_size ||
!(token = strtok_r(NULL, kAmbigDelimiters, &next_token)) ||
!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token)) ||
!sscanf(token, "%d", replacement_ambig_part_size) ||
*replacement_ambig_part_size <= 0) {
if (debug_level) tprintf(kIllegalMsg, line_num);
Expand All @@ -301,7 +301,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
}
replacement_string[0] = '\0';
for (i = 0; i < *replacement_ambig_part_size; ++i) {
if (!(token = strtok_r(NULL, kAmbigDelimiters, &next_token))) break;
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token))) break;
strcat(replacement_string, token);
if (!unicharset.contains_unichar(token)) {
if (debug_level) tprintf(kIllegalUnicharMsg, token);
Expand All @@ -322,7 +322,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
// Note that if m > 1, an ngram will be inserted into the
// modified word, not the individual unigrams. Tesseract
// has limited support for ngram unichar (e.g. dawg permuter).
if (!(token = strtok_r(NULL, kAmbigDelimiters, &next_token)) ||
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token)) ||
!sscanf(token, "%d", type)) {
if (debug_level) tprintf(kIllegalMsg, line_num);
return false;
Expand Down Expand Up @@ -381,7 +381,7 @@ bool UnicharAmbigs::InsertIntoTable(

// Add AmbigSpec for this ambiguity to the corresponding AmbigSpec_LIST.
// Keep AmbigSpec_LISTs sorted by AmbigSpec.wrong_ngram.
if (table[test_unichar_ids[0]] == NULL) {
if (table[test_unichar_ids[0]] == nullptr) {
table[test_unichar_ids[0]] = new AmbigSpec_LIST();
}
if (table[test_unichar_ids[0]]->add_sorted(
Expand Down
8 changes: 4 additions & 4 deletions ccutil/ambigs.h
Expand Up @@ -152,7 +152,7 @@ class UnicharAmbigs {
const UnicharAmbigsVector &dang_ambigs() const { return dang_ambigs_; }
const UnicharAmbigsVector &replace_ambigs() const { return replace_ambigs_; }

// Initializes the ambigs by adding a NULL pointer to each table.
// Initializes the ambigs by adding a nullptr pointer to each table.
void InitUnicharAmbigs(const UNICHARSET& unicharset,
bool use_ambigs_for_adaption);

Expand All @@ -178,7 +178,7 @@ class UnicharAmbigs {
// Returns definite 1-1 ambigs for the given unichar id.
inline const UnicharIdVector *OneToOneDefiniteAmbigs(
UNICHAR_ID unichar_id) const {
if (one_to_one_definite_ambigs_.empty()) return NULL;
if (one_to_one_definite_ambigs_.empty()) return nullptr;
return one_to_one_definite_ambigs_[unichar_id];
}

Expand All @@ -189,7 +189,7 @@ class UnicharAmbigs {
// m will return a pointer to a vector with unichar ids of r,n,i.
inline const UnicharIdVector *AmbigsForAdaption(
UNICHAR_ID unichar_id) const {
if (ambigs_for_adaption_.empty()) return NULL;
if (ambigs_for_adaption_.empty()) return nullptr;
return ambigs_for_adaption_[unichar_id];
}

Expand All @@ -198,7 +198,7 @@ class UnicharAmbigs {
// some ambiguity pair).
inline const UnicharIdVector *ReverseAmbigsForAdaption(
UNICHAR_ID unichar_id) const {
if (reverse_ambigs_for_adaption_.empty()) return NULL;
if (reverse_ambigs_for_adaption_.empty()) return nullptr;
return reverse_ambigs_for_adaption_[unichar_id];
}

Expand Down
6 changes: 3 additions & 3 deletions ccutil/basedir.cpp
Expand Up @@ -28,12 +28,12 @@
// any paths.
TESS_API void truncate_path(const char *code_path, STRING* trunc_path) {
int trunc_index = -1;
if (code_path != NULL) {
if (code_path != nullptr) {
const char* last_slash = strrchr(code_path, '/');
if (last_slash != NULL && last_slash + 1 - code_path > trunc_index)
if (last_slash != nullptr && last_slash + 1 - code_path > trunc_index)
trunc_index = last_slash + 1 - code_path;
last_slash = strrchr(code_path, '\\');
if (last_slash != NULL && last_slash + 1 - code_path > trunc_index)
if (last_slash != nullptr && last_slash + 1 - code_path > trunc_index)
trunc_index = last_slash + 1 - code_path;
}
*trunc_path = code_path;
Expand Down
2 changes: 1 addition & 1 deletion ccutil/bitvector.cpp
Expand Up @@ -106,7 +106,7 @@ const int BitVector::hamming_table_[256] = {
};


BitVector::BitVector() : bit_size_(0), array_(NULL) {}
BitVector::BitVector() : bit_size_(0), array_(nullptr) {}

BitVector::BitVector(int length) : bit_size_(length) {
array_ = new uint32_t[WordLength()];
Expand Down
2 changes: 1 addition & 1 deletion ccutil/ccutil.cpp
Expand Up @@ -35,7 +35,7 @@ CCUtilMutex::CCUtilMutex() {
#ifdef _WIN32
mutex_ = CreateMutex(0, FALSE, 0);
#else
pthread_mutex_init(&mutex_, NULL);
pthread_mutex_init(&mutex_, nullptr);
#endif
}

Expand Down

0 comments on commit 57755a2

Please sign in to comment.