Skip to content

Commit

Permalink
textord: 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 6e2750c commit 222f5b9
Show file tree
Hide file tree
Showing 52 changed files with 997 additions and 997 deletions.
42 changes: 21 additions & 21 deletions textord/alignedblob.cpp
Expand Up @@ -161,13 +161,13 @@ bool AlignedBlob::WithinTestRegion(int detail_level, int x, int y) {
ScrollView* AlignedBlob::DisplayTabs(const char* window_name,
ScrollView* tab_win) {
#ifndef GRAPHICS_DISABLED
if (tab_win == NULL)
if (tab_win == nullptr)
tab_win = MakeWindow(0, 50, window_name);
// For every tab in the grid, display it.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
gsearch.StartFullSearch();
BLOBNBOX* bbox;
while ((bbox = gsearch.NextFullSearch()) != NULL) {
while ((bbox = gsearch.NextFullSearch()) != nullptr) {
const TBOX& box = bbox->bounding_box();
int left_x = box.left();
int right_x = box.right();
Expand Down Expand Up @@ -219,7 +219,7 @@ static bool AtLeast2LineCrossings(BLOBNBOX_CLIST* blobs) {
// search parameters are determined by the AlignedBlobParams.
// vertical_x and y are updated with an estimate of the real
// vertical direction. (skew finding.)
// Returns NULL if no decent vector can be found.
// Returns nullptr if no decent vector can be found.
TabVector* AlignedBlob::FindVerticalAlignment(AlignedBlobParams align_params,
BLOBNBOX* bbox,
int* vertical_x,
Expand Down Expand Up @@ -305,7 +305,7 @@ TabVector* AlignedBlob::FindVerticalAlignment(AlignedBlobParams align_params,
pt_count, align_params.min_points, end_y - start_y,
align_params.min_length, abs(end_x - start_x) * kMinTabGradient);
}
return NULL;
return nullptr;
}

// Find a set of blobs that are aligned in the given vertical
Expand All @@ -325,7 +325,7 @@ int AlignedBlob::AlignTabs(const AlignedBlobParams& params,
box.print();
}
int x_start = params.right_tab ? box.right() : box.left();
while (bbox != NULL) {
while (bbox != nullptr) {
// Add the blob to the list if the appropriate side is a tab candidate,
// or if we are working on a ragged tab.
TabType type = params.right_tab ? bbox->right_tab_type()
Expand All @@ -340,10 +340,10 @@ int AlignedBlob::AlignTabs(const AlignedBlobParams& params,
}
// Find the next blob that is aligned with the current one.
// FindAlignedBlob guarantees that forward progress will be made in the
// top_to_bottom direction, and therefore eventually it will return NULL,
// making this while (bbox != NULL) loop safe.
// top_to_bottom direction, and therefore eventually it will return nullptr,
// making this while (bbox != nullptr) loop safe.
bbox = FindAlignedBlob(params, top_to_bottom, bbox, x_start, end_y);
if (bbox != NULL) {
if (bbox != nullptr) {
box = bbox->bounding_box();
if (!params.ragged)
x_start = params.right_tab ? box.right() : box.left();
Expand All @@ -359,8 +359,8 @@ int AlignedBlob::AlignTabs(const AlignedBlobParams& params,
// Search vertically for a blob that is aligned with the input bbox.
// The search parameters are determined by AlignedBlobParams.
// top_to_bottom tells whether to search down or up.
// The return value is NULL if nothing was found in the search box
// or if a blob was found in the gutter. On a NULL return, end_y
// The return value is nullptr if nothing was found in the search box
// or if a blob was found in the gutter. On a nullptr return, end_y
// is set to the edge of the search box or the leading edge of the
// gutter blob if one was found.
BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
Expand Down Expand Up @@ -412,13 +412,13 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
xmin, xmax, start_y, p.max_v_gap, p.min_gutter);
vsearch.StartVerticalSearch(xmin, xmax, start_y);
// result stores the best real return value.
BLOBNBOX* result = NULL;
BLOBNBOX* result = nullptr;
// The backup_result is not a tab candidate and can be used if no
// real tab candidate result is found.
BLOBNBOX* backup_result = NULL;
BLOBNBOX* backup_result = nullptr;
// neighbour is the blob that is currently being investigated.
BLOBNBOX* neighbour = NULL;
while ((neighbour = vsearch.NextVerticalSearch(top_to_bottom)) != NULL) {
BLOBNBOX* neighbour = nullptr;
while ((neighbour = vsearch.NextVerticalSearch(top_to_bottom)) != nullptr) {
if (neighbour == bbox)
continue;
TBOX nbox = neighbour->bounding_box();
Expand All @@ -437,9 +437,9 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
// more than one blob in a grid cell. See comment in AlignTabs.
if ((n_y < start_y) != top_to_bottom || nbox.y_overlap(box))
continue; // Only look in the required direction.
if (result != NULL && result->bounding_box().y_gap(nbox) > gridsize())
if (result != nullptr && result->bounding_box().y_gap(nbox) > gridsize())
return result; // This result is clear.
if (backup_result != NULL && p.ragged && result == NULL &&
if (backup_result != nullptr && p.ragged && result == nullptr &&
backup_result->bounding_box().y_gap(nbox) > gridsize())
return backup_result; // This result is clear.

Expand All @@ -466,7 +466,7 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
*end_y = top_to_bottom ? nbox.top() : nbox.bottom();
if (WithinTestRegion(2, x_start, start_y))
tprintf("gutter\n");
return NULL;
return nullptr;
}
if (!p.right_tab &&
n_left < x_at_n_y - p.l_align_tolerance &&
Expand All @@ -478,7 +478,7 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
*end_y = top_to_bottom ? nbox.top() : nbox.bottom();
if (WithinTestRegion(2, x_start, start_y))
tprintf("gutter\n");
return NULL;
return nullptr;
}
if ((p.right_tab && neighbour->leader_on_right()) ||
(!p.right_tab && neighbour->leader_on_left()))
Expand All @@ -494,7 +494,7 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
TabType n_type = p.right_tab ? neighbour->right_tab_type()
: neighbour->left_tab_type();
if (n_type != TT_NONE && (p.ragged || n_type != TT_MAYBE_RAGGED)) {
if (result == NULL) {
if (result == nullptr) {
result = neighbour;
} else {
// Keep the closest neighbour by Euclidean distance.
Expand All @@ -510,7 +510,7 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
if (new_dist < old_dist)
result = neighbour;
}
} else if (backup_result == NULL) {
} else if (backup_result == nullptr) {
if (WithinTestRegion(2, x_start, start_y))
tprintf("Backup\n");
backup_result = neighbour;
Expand All @@ -525,7 +525,7 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
}
}
}
return result != NULL ? result : backup_result;
return result != nullptr ? result : backup_result;
}

} // namespace tesseract.
Expand Down
6 changes: 3 additions & 3 deletions textord/alignedblob.h
Expand Up @@ -95,7 +95,7 @@ class AlignedBlob : public BlobGrid {
// search parameters are determined by the AlignedBlobParams.
// vertical_x and y are updated with an estimate of the real
// vertical direction. (skew finding.)
// Returns NULL if no decent vector can be found.
// Returns nullptr if no decent vector can be found.
TabVector* FindVerticalAlignment(AlignedBlobParams align_params,
BLOBNBOX* bbox,
int* vertical_x, int* vertical_y);
Expand All @@ -112,8 +112,8 @@ class AlignedBlob : public BlobGrid {
// Search vertically for a blob that is aligned with the input bbox.
// The search parameters are determined by AlignedBlobParams.
// top_to_bottom tells whether to search down or up.
// The return value is NULL if nothing was found in the search box
// or if a blob was found in the gutter. On a NULL return, end_y
// The return value is nullptr if nothing was found in the search box
// or if a blob was found in the gutter. On a nullptr return, end_y
// is set to the edge of the search box or the leading edge of the
// gutter blob if one was found.
BLOBNBOX* FindAlignedBlob(const AlignedBlobParams& p,
Expand Down
10 changes: 5 additions & 5 deletions textord/baselinedetect.cpp
Expand Up @@ -706,10 +706,10 @@ void BaselineBlock::RefineLineSpacing(const GenericVector<double>& positions) {
double spacing_plus = line_spacing_ / (1.0 + 1.0 / index_range);
// Try the hypotheses that there might be index_range +/- 1 line spaces.
errors[1] = FitLineSpacingModel(positions, spacing_plus,
&spacings[1], &offsets[1], NULL);
&spacings[1], &offsets[1], nullptr);
double spacing_minus = line_spacing_ / (1.0 - 1.0 / index_range);
errors[2] = FitLineSpacingModel(positions, spacing_minus,
&spacings[2], &offsets[2], NULL);
&spacings[2], &offsets[2], nullptr);
for (int i = 1; i <= 2; ++i) {
if (errors[i] < errors[0]) {
spacings[0] = spacings[i];
Expand Down Expand Up @@ -740,7 +740,7 @@ double BaselineBlock::FitLineSpacingModel(
if (m_in == 0.0f || positions.size() < 2) {
*m_out = m_in;
*c_out = 0.0;
if (index_delta != NULL) *index_delta = 0;
if (index_delta != nullptr) *index_delta = 0;
return 0.0;
}
GenericVector<double> offsets;
Expand Down Expand Up @@ -776,7 +776,7 @@ double BaselineBlock::FitLineSpacingModel(
*c_out, llsq.c(*m_out));
}
// Index_delta is the number of hypothesized line gaps present.
if (index_delta != NULL)
if (index_delta != nullptr)
*index_delta = max_index - min_index;
// Use the regression model's intercept to compute the error, as it may be
// a full line-spacing in disagreement with the median.
Expand All @@ -802,7 +802,7 @@ BaselineDetect::BaselineDetect(int debug_level, const FCOORD& page_skew,
// block. Ideally no baselines should be required, but currently
// make_words crashes if a baseline and xheight are not provided, so we
// include non-text blocks here, but flag them for special treatment.
bool non_text = pb != NULL && !pb->IsText();
bool non_text = pb != nullptr && !pb->IsText();
blocks_.push_back(new BaselineBlock(debug_level_, non_text, to_block));
}
}
Expand Down
12 changes: 6 additions & 6 deletions textord/bbgrid.cpp
Expand Up @@ -64,24 +64,24 @@ void GridBase::ClipGridCoords(int* x, int* y) const {
}

IntGrid::IntGrid() {
grid_ = NULL;
grid_ = nullptr;
}

IntGrid::IntGrid(int gridsize, const ICOORD& bleft, const ICOORD& tright)
: grid_(NULL) {
: grid_(nullptr) {
Init(gridsize, bleft, tright);
}

IntGrid::~IntGrid() {
if (grid_ != NULL)
if (grid_ != nullptr)
delete [] grid_;
}

// (Re)Initialize the grid. The gridsize is the size in pixels of each cell,
// and bleft, tright are the bounding box of everything to go in it.
void IntGrid::Init(int gridsize, const ICOORD& bleft, const ICOORD& tright) {
GridBase::Init(gridsize, bleft, tright);
if (grid_ != NULL)
if (grid_ != nullptr)
delete [] grid_;
grid_ = new int[gridbuckets_];
Clear();
Expand Down Expand Up @@ -109,7 +109,7 @@ void IntGrid::Rotate(const FCOORD& rotation) {
TBOX box(bleft(), tright());
box.rotate(rotation);
int* old_grid = grid_;
grid_ = NULL;
grid_ = nullptr;
Init(gridsize(), box.botleft(), box.topright());
// Iterate over the old grid, copying data to the rotated position in the new.
int oldi = 0;
Expand Down Expand Up @@ -201,7 +201,7 @@ Pix* IntGrid::ThresholdToPix(int threshold) const {
GridCellValue(x - 1, y) > 0 && GridCellValue(x + 1, y) > 0 &&
GridCellValue(x, y - 1) > 0 && GridCellValue(x, y + 1) > 0) {
pixRasterop(pix, x * cellsize, tright().y() - ((y + 1) * cellsize),
cellsize, cellsize, PIX_SET, NULL, 0, 0);
cellsize, cellsize, PIX_SET, nullptr, 0, 0);
}
}
}
Expand Down

0 comments on commit 222f5b9

Please sign in to comment.