Skip to content

Commit

Permalink
Remove assertions for unsupported locale settings
Browse files Browse the repository at this point in the history
The latest code passed all unittests with locale de_DE.UTF-8
and has fixed the locale issues which were reported on GitHub.
Therefore the assertions can be removed.

Any remaining locale issue will be fixed when it is identified.
To help finding such remaining isses, debug code now uses the
user's locale settings instead of the default "C" locale for all
executables which use TessBaseAPI.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed May 16, 2019
1 parent 77f9bad commit 331cc84
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <unistd.h>
#endif // _WIN32

#include <clocale> // for LC_ALL, LC_CTYPE, LC_NUMERIC
#include <cmath> // for round, M_PI
#include <cstdint> // for int32_t
#include <cstring> // for strcmp, strcpy
Expand Down Expand Up @@ -209,13 +208,16 @@ TessBaseAPI::TessBaseAPI()
rect_height_(0),
image_width_(0),
image_height_(0) {
const char *locale;
locale = std::setlocale(LC_ALL, nullptr);
ASSERT_HOST(!strcmp(locale, "C") || !strcmp(locale, "C.UTF-8"));
locale = std::setlocale(LC_CTYPE, nullptr);
ASSERT_HOST(!strcmp(locale, "C") || !strcmp(locale, "C.UTF-8"));
locale = std::setlocale(LC_NUMERIC, nullptr);
ASSERT_HOST(!strcmp(locale, "C") || !strcmp(locale, "C.UTF-8"));
#if defined(DEBUG)
// The Tesseract executables would use the "C" locale by default,
// but other software which is linked against the Tesseract library
// typically uses the locale from the user's environment.
// Here the default is overridden to allow debugging of potential
// problems caused by the locale settings.

// Use the current locale if building debug code.
std::locale::global(std::locale(""));
#endif
}

TessBaseAPI::~TessBaseAPI() {
Expand Down

0 comments on commit 331cc84

Please sign in to comment.