Skip to content

Commit 57755a2

Browse files
committed
ccutil: Replace NULL by nullptr
Signed-off-by: Stefan Weil <[email protected]>
1 parent e74d997 commit 57755a2

40 files changed

+726
-726
lines changed

ccutil/ambigs.cpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ AmbigSpec::AmbigSpec() {
4545

4646
ELISTIZE(AmbigSpec)
4747

48-
// Initializes the ambigs by adding a NULL pointer to each table.
48+
// Initializes the ambigs by adding a nullptr pointer to each table.
4949
void UnicharAmbigs::InitUnicharAmbigs(const UNICHARSET& unicharset,
5050
bool use_ambigs_for_adaption) {
5151
for (int i = 0; i < unicharset.size(); ++i) {
52-
replace_ambigs_.push_back(NULL);
53-
dang_ambigs_.push_back(NULL);
54-
one_to_one_definite_ambigs_.push_back(NULL);
52+
replace_ambigs_.push_back(nullptr);
53+
dang_ambigs_.push_back(nullptr);
54+
one_to_one_definite_ambigs_.push_back(nullptr);
5555
if (use_ambigs_for_adaption) {
56-
ambigs_for_adaption_.push_back(NULL);
57-
reverse_ambigs_for_adaption_.push_back(NULL);
56+
ambigs_for_adaption_.push_back(nullptr);
57+
reverse_ambigs_for_adaption_.push_back(nullptr);
5858
}
5959
}
6060
}
@@ -89,15 +89,15 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
8989

9090
// Determine the version of the ambigs file.
9191
int version = 0;
92-
ASSERT_HOST(ambig_file->FGets(buffer, kBufferSize) != NULL &&
92+
ASSERT_HOST(ambig_file->FGets(buffer, kBufferSize) != nullptr &&
9393
strlen(buffer) > 0);
9494
if (*buffer == 'v') {
95-
version = static_cast<int>(strtol(buffer+1, NULL, 10));
95+
version = static_cast<int>(strtol(buffer+1, nullptr, 10));
9696
++line_num;
9797
} else {
9898
ambig_file->Rewind();
9999
}
100-
while (ambig_file->FGets(buffer, kBufferSize) != NULL) {
100+
while (ambig_file->FGets(buffer, kBufferSize) != nullptr) {
101101
chomp_string(buffer);
102102
if (debug_level > 2) tprintf("read line %s\n", buffer);
103103
++line_num;
@@ -117,7 +117,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
117117
// Update one_to_one_definite_ambigs_.
118118
if (test_ambig_part_size == 1 &&
119119
replacement_ambig_part_size == 1 && type == DEFINITE_AMBIG) {
120-
if (one_to_one_definite_ambigs_[test_unichar_ids[0]] == NULL) {
120+
if (one_to_one_definite_ambigs_[test_unichar_ids[0]] == nullptr) {
121121
one_to_one_definite_ambigs_[test_unichar_ids[0]] = new UnicharIdVector();
122122
}
123123
one_to_one_definite_ambigs_[test_unichar_ids[0]]->push_back(
@@ -129,9 +129,9 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
129129
// Silently ignore invalid strings, as before, so it is safe to use a
130130
// universal ambigs file.
131131
if (unicharset->encode_string(replacement_string, true, &encoding,
132-
NULL, NULL)) {
132+
nullptr, nullptr)) {
133133
for (i = 0; i < test_ambig_part_size; ++i) {
134-
if (ambigs_for_adaption_[test_unichar_ids[i]] == NULL) {
134+
if (ambigs_for_adaption_[test_unichar_ids[i]] == nullptr) {
135135
ambigs_for_adaption_[test_unichar_ids[i]] = new UnicharIdVector();
136136
}
137137
adaption_ambigs_entry = ambigs_for_adaption_[test_unichar_ids[i]];
@@ -160,10 +160,10 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
160160
if (use_ambigs_for_adaption) {
161161
for (i = 0; i < ambigs_for_adaption_.size(); ++i) {
162162
adaption_ambigs_entry = ambigs_for_adaption_[i];
163-
if (adaption_ambigs_entry == NULL) continue;
163+
if (adaption_ambigs_entry == nullptr) continue;
164164
for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
165165
UNICHAR_ID ambig_id = (*adaption_ambigs_entry)[j];
166-
if (reverse_ambigs_for_adaption_[ambig_id] == NULL) {
166+
if (reverse_ambigs_for_adaption_[ambig_id] == nullptr) {
167167
reverse_ambigs_for_adaption_[ambig_id] = new UnicharIdVector();
168168
}
169169
reverse_ambigs_for_adaption_[ambig_id]->push_back(i);
@@ -178,7 +178,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
178178
(tbl == 0) ? replace_ambigs_ : dang_ambigs_;
179179
for (i = 0; i < print_table.size(); ++i) {
180180
AmbigSpec_LIST *lst = print_table[i];
181-
if (lst == NULL) continue;
181+
if (lst == nullptr) continue;
182182
if (!lst->empty()) {
183183
tprintf("%s Ambiguities for %s:\n",
184184
(tbl == 0) ? "Replaceable" : "Dangerous",
@@ -200,7 +200,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET& encoder_set,
200200
ambigs_for_adaption_ : reverse_ambigs_for_adaption_;
201201
for (i = 0; i < vec.size(); ++i) {
202202
adaption_ambigs_entry = vec[i];
203-
if (adaption_ambigs_entry != NULL) {
203+
if (adaption_ambigs_entry != nullptr) {
204204
tprintf("%sAmbigs for adaption for %s:\n",
205205
(vec_id == 0) ? "" : "Reverse ",
206206
unicharset->debug_str(i).string());
@@ -231,8 +231,8 @@ bool UnicharAmbigs::ParseAmbiguityLine(
231231
}
232232
// Encode wrong-string.
233233
GenericVector<UNICHAR_ID> unichars;
234-
if (!unicharset.encode_string(fields[0].string(), true, &unichars, NULL,
235-
NULL)) {
234+
if (!unicharset.encode_string(fields[0].string(), true, &unichars, nullptr,
235+
nullptr)) {
236236
return false;
237237
}
238238
*test_ambig_part_size = unichars.size();
@@ -246,8 +246,8 @@ bool UnicharAmbigs::ParseAmbiguityLine(
246246
test_unichar_ids[i] = unichars[i];
247247
test_unichar_ids[unichars.size()] = INVALID_UNICHAR_ID;
248248
// Encode replacement-string to check validity.
249-
if (!unicharset.encode_string(fields[1].string(), true, &unichars, NULL,
250-
NULL)) {
249+
if (!unicharset.encode_string(fields[1].string(), true, &unichars, nullptr,
250+
nullptr)) {
251251
return false;
252252
}
253253
*replacement_ambig_part_size = unichars.size();
@@ -278,7 +278,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
278278
return false;
279279
}
280280
for (i = 0; i < *test_ambig_part_size; ++i) {
281-
if (!(token = strtok_r(NULL, kAmbigDelimiters, &next_token))) break;
281+
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token))) break;
282282
if (!unicharset.contains_unichar(token)) {
283283
if (debug_level) tprintf(kIllegalUnicharMsg, token);
284284
break;
@@ -288,7 +288,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
288288
test_unichar_ids[i] = INVALID_UNICHAR_ID;
289289

290290
if (i != *test_ambig_part_size ||
291-
!(token = strtok_r(NULL, kAmbigDelimiters, &next_token)) ||
291+
!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token)) ||
292292
!sscanf(token, "%d", replacement_ambig_part_size) ||
293293
*replacement_ambig_part_size <= 0) {
294294
if (debug_level) tprintf(kIllegalMsg, line_num);
@@ -301,7 +301,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
301301
}
302302
replacement_string[0] = '\0';
303303
for (i = 0; i < *replacement_ambig_part_size; ++i) {
304-
if (!(token = strtok_r(NULL, kAmbigDelimiters, &next_token))) break;
304+
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token))) break;
305305
strcat(replacement_string, token);
306306
if (!unicharset.contains_unichar(token)) {
307307
if (debug_level) tprintf(kIllegalUnicharMsg, token);
@@ -322,7 +322,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(
322322
// Note that if m > 1, an ngram will be inserted into the
323323
// modified word, not the individual unigrams. Tesseract
324324
// has limited support for ngram unichar (e.g. dawg permuter).
325-
if (!(token = strtok_r(NULL, kAmbigDelimiters, &next_token)) ||
325+
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token)) ||
326326
!sscanf(token, "%d", type)) {
327327
if (debug_level) tprintf(kIllegalMsg, line_num);
328328
return false;
@@ -381,7 +381,7 @@ bool UnicharAmbigs::InsertIntoTable(
381381

382382
// Add AmbigSpec for this ambiguity to the corresponding AmbigSpec_LIST.
383383
// Keep AmbigSpec_LISTs sorted by AmbigSpec.wrong_ngram.
384-
if (table[test_unichar_ids[0]] == NULL) {
384+
if (table[test_unichar_ids[0]] == nullptr) {
385385
table[test_unichar_ids[0]] = new AmbigSpec_LIST();
386386
}
387387
if (table[test_unichar_ids[0]]->add_sorted(

ccutil/ambigs.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class UnicharAmbigs {
152152
const UnicharAmbigsVector &dang_ambigs() const { return dang_ambigs_; }
153153
const UnicharAmbigsVector &replace_ambigs() const { return replace_ambigs_; }
154154

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

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

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

@@ -198,7 +198,7 @@ class UnicharAmbigs {
198198
// some ambiguity pair).
199199
inline const UnicharIdVector *ReverseAmbigsForAdaption(
200200
UNICHAR_ID unichar_id) const {
201-
if (reverse_ambigs_for_adaption_.empty()) return NULL;
201+
if (reverse_ambigs_for_adaption_.empty()) return nullptr;
202202
return reverse_ambigs_for_adaption_[unichar_id];
203203
}
204204

ccutil/basedir.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
// any paths.
2929
TESS_API void truncate_path(const char *code_path, STRING* trunc_path) {
3030
int trunc_index = -1;
31-
if (code_path != NULL) {
31+
if (code_path != nullptr) {
3232
const char* last_slash = strrchr(code_path, '/');
33-
if (last_slash != NULL && last_slash + 1 - code_path > trunc_index)
33+
if (last_slash != nullptr && last_slash + 1 - code_path > trunc_index)
3434
trunc_index = last_slash + 1 - code_path;
3535
last_slash = strrchr(code_path, '\\');
36-
if (last_slash != NULL && last_slash + 1 - code_path > trunc_index)
36+
if (last_slash != nullptr && last_slash + 1 - code_path > trunc_index)
3737
trunc_index = last_slash + 1 - code_path;
3838
}
3939
*trunc_path = code_path;

ccutil/bitvector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const int BitVector::hamming_table_[256] = {
106106
};
107107

108108

109-
BitVector::BitVector() : bit_size_(0), array_(NULL) {}
109+
BitVector::BitVector() : bit_size_(0), array_(nullptr) {}
110110

111111
BitVector::BitVector(int length) : bit_size_(length) {
112112
array_ = new uint32_t[WordLength()];

ccutil/ccutil.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CCUtilMutex::CCUtilMutex() {
3535
#ifdef _WIN32
3636
mutex_ = CreateMutex(0, FALSE, 0);
3737
#else
38-
pthread_mutex_init(&mutex_, NULL);
38+
pthread_mutex_init(&mutex_, nullptr);
3939
#endif
4040
}
4141

0 commit comments

Comments
 (0)