RAII: TessBaseAPI::GetUTF8Text()

This commit is contained in:
Raf Schietekat 2017-05-10 11:36:01 +02:00
parent 4840c65bf0
commit f75665c34f
2 changed files with 5 additions and 6 deletions

View File

@ -1980,9 +1980,9 @@ bool TessBaseAPI::AdaptToWordStr(PageSegMode mode, const char* wordstr) {
PageSegMode current_psm = GetPageSegMode();
SetPageSegMode(mode);
SetVariable("classify_enable_learning", "0");
char* text = GetUTF8Text();
const std::unique_ptr<const char[]> text(GetUTF8Text());
if (debug) {
tprintf("Trying to adapt \"%s\" to \"%s\"\n", text, wordstr);
tprintf("Trying to adapt \"%s\" to \"%s\"\n", text.get(), wordstr);
}
if (text != NULL) {
PAGE_RES_IT it(page_res_);
@ -2022,7 +2022,6 @@ bool TessBaseAPI::AdaptToWordStr(PageSegMode mode, const char* wordstr) {
tesseract_->EnableLearning = true;
tesseract_->LearnWord(NULL, word_res);
}
delete [] text;
} else {
success = false;
}

View File

@ -19,6 +19,7 @@
#include "config_auto.h"
#endif
#include <memory> // std::unique_ptr
#include <string.h>
#include "baseapi.h"
#include "genericvector.h"
@ -122,13 +123,12 @@ TessTextRenderer::TessTextRenderer(const char *outputbase)
}
bool TessTextRenderer::AddImageHandler(TessBaseAPI* api) {
char* utf8 = api->GetUTF8Text();
const std::unique_ptr<const char[]> utf8(api->GetUTF8Text());
if (utf8 == NULL) {
return false;
}
AppendString(utf8);
delete[] utf8;
AppendString(utf8.get());
bool pageBreak = false;
api->GetBoolVariable("include_page_breaks", &pageBreak);