RAII: *::GetBoxText()

This commit is contained in:
Raf Schietekat 2017-05-10 13:09:06 +02:00
parent b7b68a65dd
commit 1dab23916f
3 changed files with 6 additions and 6 deletions

View File

@ -1702,8 +1702,9 @@ const int kMaxBytesPerLine = kNumbersPerBlob * (kBytesPer64BitNumber + 1) + 1 +
/** /**
* The recognized text is returned as a char* which is coded * 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. * 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) { char* TessBaseAPI::GetBoxText(int page_number) {
if (tesseract_ == NULL || if (tesseract_ == NULL ||

View File

@ -612,10 +612,10 @@ class TESS_API TessBaseAPI {
/** /**
* The recognized text is returned as a char* which is coded in the same * 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 * format as a box file used in training.
* the delete [] operator.
* Constructs coordinates in the original image - not just the rectangle. * 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. * 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); char* GetBoxText(int page_number);

View File

@ -251,11 +251,10 @@ TessBoxTextRenderer::TessBoxTextRenderer(const char *outputbase)
} }
bool TessBoxTextRenderer::AddImageHandler(TessBaseAPI* api) { 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; if (text == NULL) return false;
AppendString(text); AppendString(text.get());
delete[] text;
return true; return true;
} }