Commit 63f44630 for tesseract

commit 63f446302878ad38f9b76732280cc6a9811cdc88
Author: Stefan Weil <sw@weilnetz.de>
Date:   Thu Apr 8 10:29:45 2021 +0200

    Add const attribute to some functions (API change)

    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/include/tesseract/baseapi.h b/include/tesseract/baseapi.h
index c30c3c46..c08b477a 100644
--- a/include/tesseract/baseapi.h
+++ b/include/tesseract/baseapi.h
@@ -158,7 +158,7 @@ public:
   /**
    * Get value of named variable as a string, if it exists.
    */
-  bool GetVariableAsString(const char *name, std::string *val);
+  bool GetVariableAsString(const char *name, std::string *val) const;

   /**
    * Instances are now mostly thread-safe and totally independent,
@@ -530,7 +530,7 @@ public:
    */
   char *GetUTF8Text();

-  size_t GetNumberOfTables();
+  size_t GetNumberOfTables() const;

   /// Return the i-th table bounding box coordinates
   ///
@@ -699,9 +699,9 @@ public:
    * @warning temporary! This function will be removed from here and placed
    * in a separate API at some future time.
    */
-  int IsValidWord(const char *word);
+  int IsValidWord(const char *word) const;
   // Returns true if utf8_character is defined in the UniCharset.
-  bool IsValidCharacter(const char *utf8_character);
+  bool IsValidCharacter(const char *utf8_character) const;

   bool GetTextDirection(int *out_offset, float *out_slope);

@@ -727,7 +727,7 @@ public:
                                 bool **vertical_writing);

   /** This method returns the string form of the specified unichar. */
-  const char *GetUnichar(int unichar_id);
+  const char *GetUnichar(int unichar_id) const;

   /** Return the pointer to the i-th dawg loaded into tesseract_ object. */
   const Dawg *GetDawg(int i) const;
@@ -779,7 +779,7 @@ protected:
    * and assuming a single character reject marker for each rejected character.
    * Also return the number of recognized blobs in blob_count.
    */
-  int TextLength(int *blob_count);
+  int TextLength(int *blob_count) const;

   //// paragraphs.cpp ////////////////////////////////////////////////////
   void DetectParagraphs(bool after_text_recognition);
diff --git a/include/tesseract/osdetect.h b/include/tesseract/osdetect.h
index 8052d2d2..40444c3c 100644
--- a/include/tesseract/osdetect.h
+++ b/include/tesseract/osdetect.h
@@ -99,7 +99,7 @@ public:
   ScriptDetector(const std::vector<int> *allowed_scripts, OSResults *osr,
                  tesseract::Tesseract *tess);
   void detect_blob(BLOB_CHOICE_LIST *scores);
-  bool must_stop(int orientation);
+  bool must_stop(int orientation) const;

 private:
   OSResults *osr_;
diff --git a/include/tesseract/renderer.h b/include/tesseract/renderer.h
index eaca00cd..dad79955 100644
--- a/include/tesseract/renderer.h
+++ b/include/tesseract/renderer.h
@@ -90,7 +90,7 @@ public:
   }

   // Is everything fine? Otherwise something went wrong.
-  bool happy() {
+  bool happy() const {
     return happy_;
   }

diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp
index 786c425d..dd3c51d1 100644
--- a/src/api/baseapi.cpp
+++ b/src/api/baseapi.cpp
@@ -327,7 +327,7 @@ bool TessBaseAPI::GetDoubleVariable(const char *name, double *value) const {
 }

 /** Get value of named variable as a string, if it exists. */
-bool TessBaseAPI::GetVariableAsString(const char *name, std::string *val) {
+bool TessBaseAPI::GetVariableAsString(const char *name, std::string *val) const {
   return ParamUtils::GetParamAsString(name, tesseract_->params(), val);
 }

@@ -1349,7 +1349,7 @@ char *TessBaseAPI::GetUTF8Text() {
   return result;
 }

-size_t TessBaseAPI::GetNumberOfTables()
+size_t TessBaseAPI::GetNumberOfTables() const
 {
   return constUniqueInstance<std::vector<TessTable>>().size();
 }
@@ -1973,11 +1973,11 @@ void TessBaseAPI::ClearPersistentCache() {
  * Check whether a word is valid according to Tesseract's language model
  * returns 0 if the word is invalid, non-zero if valid
  */
-int TessBaseAPI::IsValidWord(const char *word) {
+int TessBaseAPI::IsValidWord(const char *word) const {
   return tesseract_->getDict().valid_word(word);
 }
 // Returns true if utf8_character is defined in the UniCharset.
-bool TessBaseAPI::IsValidCharacter(const char *utf8_character) {
+bool TessBaseAPI::IsValidCharacter(const char *utf8_character) const {
   return tesseract_->unicharset.contains_unichar(utf8_character);
 }

@@ -2225,7 +2225,7 @@ void TessBaseAPI::ClearResults() {
  * character.
  * Also return the number of recognized blobs in blob_count.
  */
-int TessBaseAPI::TextLength(int *blob_count) {
+int TessBaseAPI::TextLength(int *blob_count) const {
   if (tesseract_ == nullptr || page_res_ == nullptr) {
     return 0;
   }
@@ -2352,7 +2352,7 @@ void TessBaseAPI::DetectParagraphs(bool after_text_recognition) {
 }

 /** This method returns the string form of the specified unichar. */
-const char *TessBaseAPI::GetUnichar(int unichar_id) {
+const char *TessBaseAPI::GetUnichar(int unichar_id) const {
   return tesseract_->unicharset.id_to_unichar(unichar_id);
 }

diff --git a/src/ccmain/osdetect.cpp b/src/ccmain/osdetect.cpp
index 56cc564b..5f545a84 100644
--- a/src/ccmain/osdetect.cpp
+++ b/src/ccmain/osdetect.cpp
@@ -555,7 +555,7 @@ void ScriptDetector::detect_blob(BLOB_CHOICE_LIST *scores) {
   } // iterate over each orientation
 }

-bool ScriptDetector::must_stop(int orientation) {
+bool ScriptDetector::must_stop(int orientation) const {
   osr_->update_best_script(orientation);
   return osr_->best_result.sconfidence > 1;
 }
diff --git a/src/ccmain/paramsd.h b/src/ccmain/paramsd.h
index 0035cda4..5e2a57e4 100644
--- a/src/ccmain/paramsd.h
+++ b/src/ccmain/paramsd.h
@@ -65,10 +65,10 @@ public:
   const char *GetName() const;
   const char *GetDescription() const;

-  int GetId() {
+  int GetId() const {
     return my_id_;
   }
-  bool HasChanged() {
+  bool HasChanged() const {
     return changed_;
   }

diff --git a/src/ccstruct/blobbox.h b/src/ccstruct/blobbox.h
index 56a288fe..1d6a0777 100644
--- a/src/ccstruct/blobbox.h
+++ b/src/ccstruct/blobbox.h
@@ -720,10 +720,8 @@ public:

   void print_rows() { // debug info
     TO_ROW_IT row_it = &row_list;
-    TO_ROW *row;
-
     for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
-      row = row_it.data();
+      auto row = row_it.data();
       tprintf("Row range (%g,%g), para_c=%g, blobcount=%" PRId32 "\n", row->min_y(), row->max_y(),
               row->parallel_c(), row->blob_list()->length());
     }
diff --git a/src/ccstruct/ocrrow.cpp b/src/ccstruct/ocrrow.cpp
index f02f0749..5e6eba40 100644
--- a/src/ccstruct/ocrrow.cpp
+++ b/src/ccstruct/ocrrow.cpp
@@ -166,7 +166,7 @@ void ROW::move(      // reposition row

 void ROW::print( // print
     FILE *fp     // file to print on
-) {
+) const {
   tprintf("Kerning= %d\n", kerning);
   tprintf("Spacing= %d\n", spacing);
   bound_box.print();
diff --git a/src/ccstruct/ocrrow.h b/src/ccstruct/ocrrow.h
index dff96398..4955cd28 100644
--- a/src/ccstruct/ocrrow.h
+++ b/src/ccstruct/ocrrow.h
@@ -127,7 +127,7 @@ public:
       const ICOORD vec); // by vector

   void print(    // print
-      FILE *fp); // file to print on
+      FILE *fp) const; // file to print on

 #ifndef GRAPHICS_DISABLED
   void plot(                     // draw one
diff --git a/src/ccstruct/pageres.cpp b/src/ccstruct/pageres.cpp
index 534088fc..1005dc3b 100644
--- a/src/ccstruct/pageres.cpp
+++ b/src/ccstruct/pageres.cpp
@@ -726,7 +726,7 @@ void WERD_RES::PrintBestChoices() const {

 // Returns the sum of the widths of the blob between start_blob and last_blob
 // inclusive.
-int WERD_RES::GetBlobsWidth(int start_blob, int last_blob) {
+int WERD_RES::GetBlobsWidth(int start_blob, int last_blob) const {
   int result = 0;
   for (int b = start_blob; b <= last_blob; ++b) {
     result += blob_widths[b];
@@ -737,7 +737,7 @@ int WERD_RES::GetBlobsWidth(int start_blob, int last_blob) {
   return result;
 }
 // Returns the width of a gap between the specified blob and the next one.
-int WERD_RES::GetBlobsGap(int blob_index) {
+int WERD_RES::GetBlobsGap(int blob_index) const {
   if (blob_index < 0 || blob_index >= blob_gaps.size()) {
     return 0;
   }
diff --git a/src/ccstruct/pageres.h b/src/ccstruct/pageres.h
index 3658dcb1..0ce033f8 100644
--- a/src/ccstruct/pageres.h
+++ b/src/ccstruct/pageres.h
@@ -546,9 +546,9 @@ public:

   // Returns the sum of the widths of the blob between start_blob and last_blob
   // inclusive.
-  int GetBlobsWidth(int start_blob, int last_blob);
+  int GetBlobsWidth(int start_blob, int last_blob) const;
   // Returns the width of a gap between the specified blob and the next one.
-  int GetBlobsGap(int blob_index);
+  int GetBlobsGap(int blob_index) const;

   // Returns the BLOB_CHOICE corresponding to the given index in the
   // best choice word taken from the appropriate cell in the ratings MATRIX.
diff --git a/src/ccstruct/pdblock.h b/src/ccstruct/pdblock.h
index b27fa1f9..b7b2b8dd 100644
--- a/src/ccstruct/pdblock.h
+++ b/src/ccstruct/pdblock.h
@@ -130,7 +130,7 @@ public:
   void forward();

   /// test end
-  bool cycled_rects() {
+  bool cycled_rects() const {
     return left_it.cycled_list() && right_it.cycled_list();
   }

diff --git a/src/ccstruct/quadlsq.h b/src/ccstruct/quadlsq.h
index e33f8443..850b1b6b 100644
--- a/src/ccstruct/quadlsq.h
+++ b/src/ccstruct/quadlsq.h
@@ -2,7 +2,6 @@
  * File:        quadlsq.h  (Formerly qlsq.h)
  * Description: Code for least squares approximation of quadratics.
  * Author:      Ray Smith
- * Created:     Wed Oct  6 15:14:23 BST 1993
  *
  * (C) Copyright 1993, Hewlett-Packard Ltd.
  ** Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,13 +42,13 @@ public:

   void fit(        // fit the given
       int degree); // return actual
-  double get_a() { // get x squard
+  double get_a() const { // get x squard
     return a;
   }
-  double get_b() { // get x squard
+  double get_b() const { // get x squard
     return b;
   }
-  double get_c() { // get x squard
+  double get_c() const { // get x squard
     return c;
   }

diff --git a/src/ccstruct/werd.cpp b/src/ccstruct/werd.cpp
index 12932fa3..681e259f 100644
--- a/src/ccstruct/werd.cpp
+++ b/src/ccstruct/werd.cpp
@@ -259,7 +259,7 @@ void WERD::copy_on(WERD *other) {
  * Display members
  */

-void WERD::print() {
+void WERD::print() const {
   tprintf("Blanks= %d\n", blanks);
   bounding_box().print();
   tprintf("Flags = %lu = 0%lo\n", flags.to_ulong(), flags.to_ulong());
diff --git a/src/ccstruct/werd.h b/src/ccstruct/werd.h
index e93da345..db1b0ee4 100644
--- a/src/ccstruct/werd.h
+++ b/src/ccstruct/werd.h
@@ -151,7 +151,7 @@ public:
   void copy_on(WERD *other);

   // tprintf word metadata (but not blob innards)
-  void print();
+  void print() const;

 #ifndef GRAPHICS_DISABLED
   // plot word on window in a uniform colour
diff --git a/src/ccutil/params.h b/src/ccutil/params.h
index 693f58da..02186cdf 100644
--- a/src/ccutil/params.h
+++ b/src/ccutil/params.h
@@ -247,11 +247,11 @@ public:
   const char *c_str() const {
     return value_.c_str();
   }
-  bool contains(char c) {
+  bool contains(char c) const {
     return value_.find(c) != std::string::npos;
   }
-  bool empty() {
-    return value_.length() <= 0;
+  bool empty() const {
+    return value_.empty();
   }
   bool operator==(const std::string &other) {
     return value_ == other;
diff --git a/src/ccutil/qrsequence.h b/src/ccutil/qrsequence.h
index fd767e0a..974ff616 100644
--- a/src/ccutil/qrsequence.h
+++ b/src/ccutil/qrsequence.h
@@ -2,7 +2,6 @@
 // File:        qrsequence.h
 // Description: Quasi-random sequence generator class.
 // Author:      Ranjith Unnikrishnan
-// Created:     Wed May 20 2009
 //
 // Class to generate a (deterministic) quasi-random Van der Corput sequence that
 // covers the interval [0,N) without repetition.