diff --git a/src/ccmain/pagesegmain.cpp b/src/ccmain/pagesegmain.cpp index 5ebcb3f70a..acd6a5aaa5 100644 --- a/src/ccmain/pagesegmain.cpp +++ b/src/ccmain/pagesegmain.cpp @@ -108,8 +108,10 @@ int Tesseract::SegmentPage(const char *input_file, BLOCK_LIST *blocks, Tesseract // If a UNLV zone file can be found, use that instead of segmentation. if (!PSM_COL_FIND_ENABLED(pageseg_mode) && input_file != nullptr && input_file[0] != '\0') { std::string name = input_file; - std::size_t lastdot = name.find_last_of("."); - name = name.substr(0, lastdot); + auto lastdot = name.find_last_of('.'); + if (lastdot != std::string::npos) { + name.resize(lastdot); + } read_unlv_file(name, width, height, blocks); } if (blocks->empty()) { diff --git a/src/ccutil/ambigs.cpp b/src/ccutil/ambigs.cpp index 34d68968f8..5aafedb187 100644 --- a/src/ccutil/ambigs.cpp +++ b/src/ccutil/ambigs.cpp @@ -39,12 +39,9 @@ static const char kIllegalUnicharMsg[] = "Illegal unichar %s in ambiguity specif // UNICHAR_LEN * (MAX_AMBIG_SIZE + 1) for each part of the ambig const int kMaxAmbigStringSize = UNICHAR_LEN * (MAX_AMBIG_SIZE + 1); -AmbigSpec::AmbigSpec() { +AmbigSpec::AmbigSpec() : correct_ngram_id(INVALID_UNICHAR_ID), type(NOT_AMBIG), wrong_ngram_size(0) { wrong_ngram[0] = INVALID_UNICHAR_ID; correct_fragments[0] = INVALID_UNICHAR_ID; - correct_ngram_id = INVALID_UNICHAR_ID; - type = NOT_AMBIG; - wrong_ngram_size = 0; } // Initializes the ambigs by adding a nullptr pointer to each table. diff --git a/src/ccutil/unicharset.cpp b/src/ccutil/unicharset.cpp index c0aea1f3e6..b29ec3b7fe 100644 --- a/src/ccutil/unicharset.cpp +++ b/src/ccutil/unicharset.cpp @@ -824,7 +824,7 @@ bool UNICHARSET::load_via_fgets( stream >> std::setw(255) >> unichar >> std::hex >> properties >> std::dec; // stream.flags(std::ios::dec); if (stream.fail()) { - fprintf(stderr, "%s:%u failed\n", __FILE__, __LINE__); + fprintf(stderr, "%s:%d failed\n", __FILE__, __LINE__); return false; } auto position = stream.tellg(); diff --git a/src/classify/adaptive.cpp b/src/classify/adaptive.cpp index 3139cce9be..1b7bf5fb0a 100644 --- a/src/classify/adaptive.cpp +++ b/src/classify/adaptive.cpp @@ -59,13 +59,12 @@ PERM_CONFIG_STRUCT::~PERM_CONFIG_STRUCT() { delete[] Ambigs; } -ADAPT_CLASS_STRUCT::ADAPT_CLASS_STRUCT() { - NumPermConfigs = 0; - MaxNumTimesSeen = 0; - TempProtos = NIL_LIST; - - PermProtos = NewBitVector(MAX_NUM_PROTOS); - PermConfigs = NewBitVector(MAX_NUM_CONFIGS); +ADAPT_CLASS_STRUCT::ADAPT_CLASS_STRUCT() : + NumPermConfigs(0), + MaxNumTimesSeen(0), + PermProtos(NewBitVector(MAX_NUM_PROTOS)), + PermConfigs(NewBitVector(MAX_NUM_CONFIGS)), + TempProtos(NIL_LIST) { zero_all_bits(PermProtos, WordsInVectorOfSize(MAX_NUM_PROTOS)); zero_all_bits(PermConfigs, WordsInVectorOfSize(MAX_NUM_CONFIGS)); @@ -124,16 +123,13 @@ int Classify::GetFontinfoId(ADAPT_CLASS_STRUCT *Class, uint8_t ConfigId) { /// /// @param MaxProtoId max id of any proto in new config /// @param FontinfoId font information from pre-trained templates -TEMP_CONFIG_STRUCT::TEMP_CONFIG_STRUCT(int maxProtoId, int fontinfoId) { - int NumProtos = maxProtoId + 1; - - Protos = NewBitVector(NumProtos); - - NumTimesSeen = 1; - MaxProtoId = maxProtoId; - ProtoVectorSize = WordsInVectorOfSize(NumProtos); +TEMP_CONFIG_STRUCT::TEMP_CONFIG_STRUCT(int maxProtoId, int fontinfoId) : + NumTimesSeen(1), + ProtoVectorSize(WordsInVectorOfSize(maxProtoId + 1)), + MaxProtoId(maxProtoId), + Protos(NewBitVector(maxProtoId + 1)), + FontinfoId(fontinfoId) { zero_all_bits(Protos, ProtoVectorSize); - FontinfoId = fontinfoId; } TEMP_CONFIG_STRUCT::~TEMP_CONFIG_STRUCT() { diff --git a/src/classify/clusttool.cpp b/src/classify/clusttool.cpp index 543378d6b3..de8b1f5cb8 100644 --- a/src/classify/clusttool.cpp +++ b/src/classify/clusttool.cpp @@ -277,7 +277,7 @@ void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto) { fprintf(File, "insignificant "); } WriteProtoStyle(File, static_cast(Proto->Style)); - fprintf(File, "%6d\n\t", Proto->NumSamples); + fprintf(File, "%6u\n\t", Proto->NumSamples); WriteNFloats(File, N, &Proto->Mean[0]); fprintf(File, "\t"); diff --git a/src/tesseract.cpp b/src/tesseract.cpp index 1ed7fcf398..ac42d2ec35 100644 --- a/src/tesseract.cpp +++ b/src/tesseract.cpp @@ -78,8 +78,8 @@ static void Win32WarningHandler(const char *module, const char *fmt, va_list ap) class AutoWin32ConsoleOutputCP { public: - explicit AutoWin32ConsoleOutputCP(UINT codeCP) { - oldCP_ = GetConsoleOutputCP(); + explicit AutoWin32ConsoleOutputCP(UINT codeCP) : + oldCP_(GetConsoleOutputCP()) { SetConsoleOutputCP(codeCP); } ~AutoWin32ConsoleOutputCP() { diff --git a/src/textord/devanagari_processing.cpp b/src/textord/devanagari_processing.cpp index bad6edb50f..13da1374c0 100644 --- a/src/textord/devanagari_processing.cpp +++ b/src/textord/devanagari_processing.cpp @@ -38,15 +38,16 @@ INT_VAR(devanagari_split_debuglevel, 0, "Debug level for split shiro-rekha proce BOOL_VAR(devanagari_split_debugimage, 0, "Whether to create a debug image for split shiro-rekha process."); -ShiroRekhaSplitter::ShiroRekhaSplitter() { - orig_pix_ = nullptr; - segmentation_block_list_ = nullptr; - splitted_image_ = nullptr; - global_xheight_ = kUnspecifiedXheight; - perform_close_ = false; - debug_image_ = nullptr; - pageseg_split_strategy_ = NO_SPLIT; - ocr_split_strategy_ = NO_SPLIT; +ShiroRekhaSplitter::ShiroRekhaSplitter() : + orig_pix_(nullptr), + splitted_image_(nullptr), + pageseg_split_strategy_(NO_SPLIT), + ocr_split_strategy_(NO_SPLIT), + debug_image_(nullptr), + segmentation_block_list_(nullptr), + global_xheight_(kUnspecifiedXheight), + perform_close_(false) +{ } ShiroRekhaSplitter::~ShiroRekhaSplitter() { diff --git a/src/textord/tabfind.cpp b/src/textord/tabfind.cpp index f6ba2b8477..fb6d99ae04 100644 --- a/src/textord/tabfind.cpp +++ b/src/textord/tabfind.cpp @@ -67,8 +67,8 @@ TabFind::TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVec : AlignedBlob(gridsize, bleft, tright) , resolution_(resolution) , image_origin_(0, tright.y() - 1) - , v_it_(&vectors_) { - width_cb_ = nullptr; + , v_it_(&vectors_) + , width_cb_(nullptr) { v_it_.add_list_after(vlines); SetVerticalSkewAndParallelize(vertical_x, vertical_y); using namespace std::placeholders; // for _1 diff --git a/src/training/pango/pango_font_info.cpp b/src/training/pango/pango_font_info.cpp index 5adbb26f9e..aefe73417e 100644 --- a/src/training/pango/pango_font_info.cpp +++ b/src/training/pango/pango_font_info.cpp @@ -521,9 +521,9 @@ bool FontUtils::IsAvailableFont(const char *input_query_desc, std::string *best_ *best_match = selected_desc_str; // Clip the ending ' 0' if there is one. It seems that, if there is no // point size on the end of the fontname, then Pango always appends ' 0'. - int len = best_match->size(); + auto len = best_match->size(); if (len > 2 && best_match->at(len - 1) == '0' && best_match->at(len - 2) == ' ') { - *best_match = best_match->substr(0, len - 2); + best_match->resize(len - 2); } } g_free(selected_desc_str); diff --git a/src/viewer/scrollview.cpp b/src/viewer/scrollview.cpp index f5336c589a..73bd3c5fc2 100644 --- a/src/viewer/scrollview.cpp +++ b/src/viewer/scrollview.cpp @@ -307,7 +307,7 @@ void ScrollView::Initialize(const char *name, int x_pos, int y_pos, int x_size, // Set up an actual Window on the client side. char message[kMaxMsgSize]; snprintf(message, sizeof(message), - "w%u = luajava.newInstance('com.google.scrollview.ui" + "w%d = luajava.newInstance('com.google.scrollview.ui" ".SVWindow','%s',%u,%u,%u,%u,%u,%u,%u)\n", window_id_, window_name_, window_id_, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size); @@ -393,7 +393,7 @@ void ScrollView::SendMsg(const char *format, ...) { va_end(args); char form[kMaxMsgSize]; - snprintf(form, sizeof(form), "w%u:%s\n", window_id_, message); + snprintf(form, sizeof(form), "w%d:%s\n", window_id_, message); stream_->Send(form); } @@ -532,7 +532,7 @@ void ScrollView::AlwaysOnTop(bool b) { // Adds a message entry to the message box. void ScrollView::AddMessage(const char *message) { char form[kMaxMsgSize]; - snprintf(form, sizeof(form), "w%u:%s", window_id_, message); + snprintf(form, sizeof(form), "w%d:%s", window_id_, message); char *esc = AddEscapeChars(form); SendMsg("addMessage(\"%s\")", esc); diff --git a/src/wordrec/wordrec.cpp b/src/wordrec/wordrec.cpp index ceaad04431..be6590688a 100644 --- a/src/wordrec/wordrec.cpp +++ b/src/wordrec/wordrec.cpp @@ -99,10 +99,10 @@ Wordrec::Wordrec() "Save alternative paths found during chopping" " and segmentation search", params()) - , pass2_ok_split(0.0f) { - prev_word_best_choice_ = nullptr; - language_model_ = std::make_unique(&get_fontinfo_table(), &(getDict())); - fill_lattice_ = nullptr; + , language_model_(std::make_unique(&get_fontinfo_table(), &(getDict()))) + , pass2_ok_split(0.0f) + , prev_word_best_choice_(nullptr) + , fill_lattice_(nullptr) { } } // namespace tesseract diff --git a/unittest/mastertrainer_test.cc b/unittest/mastertrainer_test.cc index b6dcc5bb5a..30f4bf4e04 100644 --- a/unittest/mastertrainer_test.cc +++ b/unittest/mastertrainer_test.cc @@ -156,9 +156,9 @@ class MasterTrainerTest : public testing::Test { return file::JoinPath(FLAGS_test_tmpdir, name); } - MasterTrainerTest() { - shape_table_ = nullptr; - master_trainer_ = nullptr; + MasterTrainerTest() : + shape_table_(nullptr), + master_trainer_(nullptr) { } ~MasterTrainerTest() override { delete shape_table_;