Skip to content

Commit 1dab239

Browse files
committed
RAII: *::GetBoxText()
1 parent b7b68a6 commit 1dab239

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

api/baseapi.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1702,8 +1702,9 @@ const int kMaxBytesPerLine = kNumbersPerBlob * (kBytesPer64BitNumber + 1) + 1 +
17021702

17031703
/**
17041704
* The recognized text is returned as a char* which is coded
1705-
* as a UTF8 box file and must be freed with the delete [] operator.
1705+
* as a UTF8 box file.
17061706
* page_number is a 0-base page index that will appear in the box file.
1707+
* Returned string must be freed with the delete [] operator.
17071708
*/
17081709
char* TessBaseAPI::GetBoxText(int page_number) {
17091710
if (tesseract_ == NULL ||

api/baseapi.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,10 @@ class TESS_API TessBaseAPI {
612612

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

api/renderer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,10 @@ TessBoxTextRenderer::TessBoxTextRenderer(const char *outputbase)
251251
}
252252

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

257-
AppendString(text);
258-
delete[] text;
257+
AppendString(text.get());
259258

260259
return true;
261260
}

0 commit comments

Comments
 (0)