Skip to content

Commit

Permalink
Simplify code which tests for non-empty StringParam
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Mar 24, 2019
1 parent f9860cd commit b1e305f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/ccmain/tessedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Now just code to load the language model and various
* engine-specific data files.
* Author: Ray Smith
* Created: Tue Jan 07 15:21:46 GMT 1992
*
* (C) Copyright 1992, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -155,7 +154,7 @@ bool Tesseract::init_tesseract_lang_data(
}
}

if (((STRING&)tessedit_write_params_to_file).length() > 0) {
if (!tessedit_write_params_to_file.empty()) {
FILE* params_file = fopen(tessedit_write_params_to_file.string(), "wb");
if (params_file != nullptr) {
ParamUtils::PrintParams(params_file, this->params());
Expand Down
20 changes: 8 additions & 12 deletions src/dict/dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,10 @@ void Dict::Load(const STRING& lang, TessdataManager* data_file) {
}

STRING name;
if (((STRING&)user_words_suffix).length() > 0 ||
((STRING&)user_words_file).length() > 0) {
if (!user_words_suffix.empty() || !user_words_file.empty()) {
Trie* trie_ptr = new Trie(DAWG_TYPE_WORD, lang, USER_DAWG_PERM,
getUnicharset().size(), dawg_debug_level);
if (((STRING&)user_words_file).length() > 0) {
if (!user_words_file.empty()) {
name = user_words_file;
} else {
name = getCCUtil()->language_data_path_prefix;
Expand All @@ -270,12 +269,11 @@ void Dict::Load(const STRING& lang, TessdataManager* data_file) {
}
}

if (((STRING&)user_patterns_suffix).length() > 0 ||
((STRING&)user_patterns_file).length() > 0) {
if (!user_patterns_suffix.empty() || !user_patterns_file.empty()) {
Trie* trie_ptr = new Trie(DAWG_TYPE_PATTERN, lang, USER_PATTERN_PERM,
getUnicharset().size(), dawg_debug_level);
trie_ptr->initialize_patterns(&(getUnicharset()));
if (((STRING&)user_patterns_file).length() > 0) {
if (!user_patterns_file.empty()) {
name = user_patterns_file;
} else {
name = getCCUtil()->language_data_path_prefix;
Expand Down Expand Up @@ -320,11 +318,10 @@ void Dict::LoadLSTM(const STRING& lang, TessdataManager* data_file) {
// stolen from Dict::Load (but needs params_ from Tesseract
// langdata/config/api):
STRING name;
if (((STRING&)user_words_suffix).length() > 0 ||
((STRING&)user_words_file).length() > 0) {
if (!user_words_suffix.empty() || !user_words_file.empty()) {
Trie* trie_ptr = new Trie(DAWG_TYPE_WORD, lang, USER_DAWG_PERM,
getUnicharset().size(), dawg_debug_level);
if (((STRING&)user_words_file).length() > 0) {
if (!user_words_file.empty()) {
name = user_words_file;
} else {
name = getCCUtil()->language_data_path_prefix;
Expand All @@ -339,12 +336,11 @@ void Dict::LoadLSTM(const STRING& lang, TessdataManager* data_file) {
}
}

if (((STRING&)user_patterns_suffix).length() > 0 ||
((STRING&)user_patterns_file).length() > 0) {
if (!user_patterns_suffix.empty() || !user_patterns_file.empty()) {
Trie* trie_ptr = new Trie(DAWG_TYPE_PATTERN, lang, USER_PATTERN_PERM,
getUnicharset().size(), dawg_debug_level);
trie_ptr->initialize_patterns(&(getUnicharset()));
if (((STRING&)user_patterns_file).length() > 0) {
if (!user_patterns_file.empty()) {
name = user_patterns_file;
} else {
name = getCCUtil()->language_data_path_prefix;
Expand Down

0 comments on commit b1e305f

Please sign in to comment.