Skip to content

Commit

Permalink
RAII: TessBaseAPI::GetUTF8Text()
Browse files Browse the repository at this point in the history
  • Loading branch information
rfschtkt committed May 11, 2017
1 parent 4840c65 commit f75665c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions api/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "config_auto.h"
#endif

#include <memory> // std::unique_ptr
#include <string.h>
#include "baseapi.h"
#include "genericvector.h"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f75665c

Please sign in to comment.