Skip to content

Commit

Permalink
RAII: *::GetBoxText()
Browse files Browse the repository at this point in the history
  • Loading branch information
rfschtkt committed May 11, 2017
1 parent b7b68a6 commit 1dab239
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,9 @@ const int kMaxBytesPerLine = kNumbersPerBlob * (kBytesPer64BitNumber + 1) + 1 +

/**
* The recognized text is returned as a char* which is coded
* as a UTF8 box file and must be freed with the delete [] operator.
* as a UTF8 box file.
* page_number is a 0-base page index that will appear in the box file.
* Returned string must be freed with the delete [] operator.
*/
char* TessBaseAPI::GetBoxText(int page_number) {
if (tesseract_ == NULL ||
Expand Down
4 changes: 2 additions & 2 deletions api/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,10 @@ class TESS_API TessBaseAPI {

/**
* The recognized text is returned as a char* which is coded in the same
* format as a box file used in training. Returned string must be freed with
* the delete [] operator.
* format as a box file used in training.
* Constructs coordinates in the original image - not just the rectangle.
* page_number is a 0-based page index that will appear in the box file.
* Returned string must be freed with the delete [] operator.
*/
char* GetBoxText(int page_number);

Expand Down
5 changes: 2 additions & 3 deletions api/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,10 @@ TessBoxTextRenderer::TessBoxTextRenderer(const char *outputbase)
}

bool TessBoxTextRenderer::AddImageHandler(TessBaseAPI* api) {
char* text = api->GetBoxText(imagenum());
const std::unique_ptr<const char[]> text(api->GetBoxText(imagenum()));
if (text == NULL) return false;

AppendString(text);
delete[] text;
AppendString(text.get());

return true;
}
Expand Down

0 comments on commit 1dab239

Please sign in to comment.