Merge pull request #3309 from stweil/std

Replace more STRING and GenericVector variables and other code maintenance
This commit is contained in:
Egor Pugin 2021-02-24 01:04:03 +03:00 committed by GitHub
commit c877c368a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 144 additions and 148 deletions

View File

@ -229,12 +229,11 @@ BlobSpecialTextType EquationDetect::EstimateTypeForUnichar(
// Exclude some special texts that are likely to be confused as math symbol.
static GenericVector<UNICHAR_ID> ids_to_exclude;
if (ids_to_exclude.empty()) {
static const STRING kCharsToEx[] = {"'", "`", "\"", "\\", ",", ".",
"", "", "", "", "", "", ""};
int i = 0;
while (kCharsToEx[i] != "") {
static const char* kCharsToEx[] = {"'", "`", "\"", "\\", ",", ".",
"", "", "", "", "", ""};
for (auto i = 0; i < countof(kCharsToEx); i++) {
ids_to_exclude.push_back(
unicharset.unichar_to_id(kCharsToEx[i++].c_str()));
unicharset.unichar_to_id(kCharsToEx[i]));
}
ids_to_exclude.sort();
}

View File

@ -267,24 +267,19 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
int16_t total_score = 0;
int16_t word_count = 0;
int16_t done_word_count = 0;
int16_t word_len;
int16_t i;
int16_t offset;
WERD_RES *word; // current word
int16_t prev_word_score = 0;
bool prev_word_done = false;
bool prev_char_1 = false; // prev ch a "1/I/l"?
bool prev_char_digit = false; // prev ch 2..9 or 0
bool current_char_1 = false;
bool current_word_ok_so_far;
STRING punct_chars = "!\"`',.:;";
const char* punct_chars = "!\"`',.:;";
bool prev_char_punct = false;
bool current_char_punct = false;
bool word_done = false;
do {
word = word_res_it.data();
word_done = fixspace_thinks_word_done(word);
// current word
WERD_RES* word = word_res_it.data();
bool word_done = fixspace_thinks_word_done(word);
word_count++;
if (word->tess_failed) {
total_score += prev_word_score;
@ -300,8 +295,8 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
Yes IF it didn't end in a 1 when the first char of this word is a digit
AND it didn't end in a digit when the first char of this word is a 1
*/
word_len = word->reject_map.length();
current_word_ok_so_far = false;
auto word_len = word->reject_map.length();
bool current_word_ok_so_far = false;
if (!((prev_char_1 && digit_or_numeric_punct(word, 0)) ||
(prev_char_digit && (
(word_done &&
@ -326,7 +321,7 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
/* Add 1 to total score for every joined 1 regardless of context and
rejtn */
for (i = 0, prev_char_1 = false; i < word_len; i++) {
current_char_1 = word->best_choice->unichar_string()[i] == '1';
bool current_char_1 = word->best_choice->unichar_string()[i] == '1';
if (prev_char_1 || (current_char_1 && (i > 0)))
total_score++;
prev_char_1 = current_char_1;
@ -337,8 +332,9 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
if (tessedit_prefer_joined_punct) {
for (i = 0, offset = 0, prev_char_punct = false; i < word_len;
offset += word->best_choice->unichar_lengths()[i++]) {
current_char_punct =
punct_chars.contains(word->best_choice->unichar_string()[offset]);
bool current_char_punct =
strchr(punct_chars,
word->best_choice->unichar_string()[offset]) != nullptr;
if (prev_char_punct || (current_char_punct && i > 0))
total_score++;
prev_char_punct = current_char_punct;

View File

@ -32,8 +32,6 @@
#include "svmnode.h" // for SVMenuNode
#include "tesseractclass.h" // for Tesseract
#include "genericvector.h" // for GenericVector
#include <cstdio> // for fclose, fopen, fprintf, sprintf, FILE
#include <cstdlib> // for atoi
#include <cstring> // for strcmp, strcspn, strlen, strncpy

View File

@ -41,7 +41,7 @@ FILE* Tesseract::init_recog_training(const char* filename) {
getDict().stopper_no_acceptable_choices.set_value(1);
}
STRING output_fname = filename;
std::string output_fname = filename;
const char* lastdot = strrchr(output_fname.c_str(), '.');
if (lastdot != nullptr)
output_fname[lastdot - output_fname.c_str()] = '\0';

View File

@ -43,12 +43,13 @@ int16_t Tesseract::safe_dict_word(const WERD_RES *werd_res) {
#include "docqual.h"
#include "tesseractclass.h"
#include "genericvector.h"
#include "helpers.h"
#include <algorithm> // for std::sort
#include <cctype>
#include <cerrno>
#include <cstring>
#include <vector> // for std::vector
namespace tesseract {
@ -230,12 +231,12 @@ float compute_reject_threshold(WERD_CHOICE* word) {
float gapstart; // bottom of gap
int blob_count = word->length();
GenericVector<float> ratings;
ratings.resize_no_init(blob_count);
std::vector<float> ratings;
ratings.reserve(blob_count);
for (int i = 0; i < blob_count; ++i) {
ratings[i] = word->certainty(i);
ratings.push_back(word->certainty(i));
}
ratings.sort();
std::sort(ratings.begin(), ratings.end());
gapstart = ratings[0] - 1; // all reject if none better
if (blob_count >= 3) {
for (int index = 0; index < blob_count - 1; index++) {

View File

@ -141,7 +141,8 @@ void ResultIterator::CalculateBlobOrder(
// Step 1: Scan for and mark European Number sequences
// [:ET:]*[:EN:]+(([:ES:]|[:CS:])?[:EN:]+)*[:ET:]*
GenericVector<int> letter_types;
std::vector<int> letter_types;
letter_types.reserve(word_length_);
for (int i = 0; i < word_length_; i++) {
letter_types.push_back(it_->word()->SymbolDirection(i));
}

View File

@ -134,8 +134,8 @@ void BlamerBundle::FillDebugString(const STRING &msg,
const WERD_CHOICE *choice,
STRING *debug) {
(*debug) += "Truth ";
for (int i = 0; i < this->truth_text_.size(); ++i) {
(*debug) += this->truth_text_[i];
for (auto& text : this->truth_text_) {
(*debug) += text;
}
if (!this->truth_has_char_boxes_) (*debug) += " (no char boxes)";
if (choice != nullptr) {

View File

@ -31,12 +31,12 @@
#include "rect.h" // for TBOX
#include "tprintf.h" // for tprintf
#include "genericvector.h" // for GenericVector
#include <tesseract/unichar.h> // for UNICHAR_ID
#include <tesseract/unichar.h> // for UNICHAR_ID
#include "strngs.h" // for STRING
#include <cstdint> // for int16_t
#include <cstring> // for memcpy
#include <vector> // for std::vector
namespace tesseract {
@ -119,8 +119,9 @@ struct BlamerBundle {
// Accessors.
STRING TruthString() const {
STRING truth_str;
for (int i = 0; i < truth_text_.size(); ++i)
truth_str += truth_text_[i];
for (auto& text : truth_text_) {
truth_str += text;
}
return truth_str;
}
IncorrectResultReason incorrect_result_reason() const {
@ -326,7 +327,7 @@ struct BlamerBundle {
// (filled in by WERD_RES::SetupForRecognition()).
tesseract::BoxWord norm_truth_word_;
// Contains ground truth unichar for each of the bounding boxes in truth_word.
GenericVector<STRING> truth_text_;
std::vector<STRING> truth_text_;
// The reason for incorrect OCR result.
IncorrectResultReason incorrect_result_reason_;
// Debug text associated with the blame.
@ -335,8 +336,8 @@ struct BlamerBundle {
STRING misadaption_debug_;
// Vectors populated by SegSearch to indicate column and row indices that
// correspond to blobs with correct bounding boxes.
GenericVector<int> correct_segmentation_cols_;
GenericVector<int> correct_segmentation_rows_;
std::vector<int> correct_segmentation_cols_;
std::vector<int> correct_segmentation_rows_;
// Best rating for correctly segmented path
// (set and used by SegSearch when looking for blame).
float best_correctly_segmented_rating_;

View File

@ -200,7 +200,7 @@ class TESS_API BLOCK : public ELIST_LINK
int16_t font_class = 0; ///< correct font class
int32_t xheight = 0; ///< height of chars
float cell_over_xheight_ = 0.0f; ///< Ratio of cell height to xheight.
STRING filename; ///< name of block
std::string filename; ///< name of block
ROW_LIST rows; ///< rows in block
PARA_LIST paras_; ///< paragraphs of block
C_BLOB_LIST c_blobs; ///< before textord

View File

@ -25,9 +25,8 @@
#include "points.h" // for operator+=, FCOORD, ICOORD
#include "genericvector.h" // for GenericVector
#include <allheaders.h> // for pixCreate, pixGetDepth
#include <vector> // for std::vector
namespace tesseract {
@ -441,8 +440,8 @@ int16_t C_BLOB::EstimateBaselinePosition() {
if (outlines.empty() || perimeter() > width * kMaxPerimeterWidthRatio)
return bottom; // This is only for non-CJK blobs.
// Get the minimum y coordinate at each x-coordinate.
GenericVector<int> y_mins;
y_mins.init_to_size(width + 1, box.top());
std::vector<int> y_mins;
y_mins.resize(width + 1, box.top());
C_OUTLINE_IT it(&outlines);
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
C_OUTLINE* outline = it.data();

View File

@ -22,6 +22,7 @@
#include "bits16.h"
#include "elst2.h"
#include "params.h"
#include "genericvector.h" // GenericVector
#include "stepblob.h"
#include "strngs.h"

View File

@ -18,7 +18,9 @@
#include "params.h"
#include "helpers.h" // for chomp_string
#include "host.h" // tesseract/export.h, windows.h for MAX_PATH
#include "serialis.h" // for TFile
#include "tprintf.h"
#include <climits> // for INT_MIN, INT_MAX

View File

@ -19,10 +19,10 @@
#ifndef PARAMS_H
#define PARAMS_H
#include "genericvector.h"
#include "strngs.h"
#include <cstdio>
#include <vector>
namespace tesseract {
@ -40,10 +40,10 @@ enum SetParamConstraint {
};
struct ParamsVectors {
GenericVector<IntParam*> int_params;
GenericVector<BoolParam*> bool_params;
GenericVector<StringParam*> string_params;
GenericVector<DoubleParam*> double_params;
std::vector<IntParam*> int_params;
std::vector<BoolParam*> bool_params;
std::vector<StringParam*> string_params;
std::vector<DoubleParam*> double_params;
};
// Utility functions for working with Tesseract parameters.
@ -71,24 +71,23 @@ class TESS_API ParamUtils {
// appropriate type) if it was found in the vector obtained from
// GlobalParams() or in the given member_params.
template <class T>
static T* FindParam(const char* name, const GenericVector<T*>& global_vec,
const GenericVector<T*>& member_vec) {
int i;
for (i = 0; i < global_vec.size(); ++i) {
if (strcmp(global_vec[i]->name_str(), name) == 0) return global_vec[i];
static T* FindParam(const char* name, const std::vector<T*>& global_vec,
const std::vector<T*>& member_vec) {
for (auto* param : global_vec) {
if (strcmp(param->name_str(), name) == 0) return param;
}
for (i = 0; i < member_vec.size(); ++i) {
if (strcmp(member_vec[i]->name_str(), name) == 0) return member_vec[i];
for (auto* param : member_vec) {
if (strcmp(param->name_str(), name) == 0) return param;
}
return nullptr;
}
// Removes the given pointer to the param from the given vector.
template <class T>
static void RemoveParam(T* param_ptr, GenericVector<T*>* vec) {
for (int i = 0; i < vec->size(); ++i) {
if ((*vec)[i] == param_ptr) {
vec->remove(i);
return;
static void RemoveParam(T* param_ptr, std::vector<T*>* vec) {
for (auto it = vec->begin(); it != vec->end(); ++it) {
if (*it == param_ptr) {
vec->erase(it);
break;
}
}
}
@ -151,11 +150,11 @@ class IntParam : public Param {
void set_value(int32_t value) { value_ = value; }
void ResetToDefault() { value_ = default_; }
void ResetFrom(const ParamsVectors* vec) {
for (int i = 0; i < vec->int_params.size(); ++i) {
if (strcmp(vec->int_params[i]->name_str(), name_) == 0) {
for (auto* param : vec->int_params) {
if (strcmp(param->name_str(), name_) == 0) {
// printf("overriding param %s=%d by =%d\n", name_, value_,
// *vec->int_params[i]);
value_ = *vec->int_params[i];
// param);
value_ = *param;
break;
}
}
@ -165,7 +164,7 @@ class IntParam : public Param {
int32_t value_;
int32_t default_;
// Pointer to the vector that contains this param (not owned by this class).
GenericVector<IntParam*>* params_vec_;
std::vector<IntParam*>* params_vec_;
};
class BoolParam : public Param {
@ -184,11 +183,11 @@ class BoolParam : public Param {
void set_value(bool value) { value_ = value; }
void ResetToDefault() { value_ = default_; }
void ResetFrom(const ParamsVectors* vec) {
for (int i = 0; i < vec->bool_params.size(); ++i) {
if (strcmp(vec->bool_params[i]->name_str(), name_) == 0) {
for (auto* param : vec->bool_params) {
if (strcmp(param->name_str(), name_) == 0) {
// printf("overriding param %s=%s by =%s\n", name_, value_ ? "true" :
// "false", *vec->bool_params[i] ? "true" : "false");
value_ = *vec->bool_params[i];
// "false", *param ? "true" : "false");
value_ = *param;
break;
}
}
@ -198,7 +197,7 @@ class BoolParam : public Param {
bool value_;
bool default_;
// Pointer to the vector that contains this param (not owned by this class).
GenericVector<BoolParam*>* params_vec_;
std::vector<BoolParam*>* params_vec_;
};
class StringParam : public Param {
@ -220,11 +219,11 @@ class StringParam : public Param {
void set_value(const STRING& value) { value_ = value; }
void ResetToDefault() { value_ = default_; }
void ResetFrom(const ParamsVectors* vec) {
for (int i = 0; i < vec->string_params.size(); ++i) {
if (strcmp(vec->string_params[i]->name_str(), name_) == 0) {
for (auto* param : vec->string_params) {
if (strcmp(param->name_str(), name_) == 0) {
// printf("overriding param %s=%s by =%s\n", name_, value_,
// vec->string_params[i]->c_str());
value_ = *vec->string_params[i];
// param->c_str());
value_ = *param;
break;
}
}
@ -234,7 +233,7 @@ class StringParam : public Param {
STRING value_;
STRING default_;
// Pointer to the vector that contains this param (not owned by this class).
GenericVector<StringParam*>* params_vec_;
std::vector<StringParam*>* params_vec_;
};
class DoubleParam : public Param {
@ -253,11 +252,11 @@ class DoubleParam : public Param {
void set_value(double value) { value_ = value; }
void ResetToDefault() { value_ = default_; }
void ResetFrom(const ParamsVectors* vec) {
for (int i = 0; i < vec->double_params.size(); ++i) {
if (strcmp(vec->double_params[i]->name_str(), name_) == 0) {
for (auto* param : vec->double_params) {
if (strcmp(param->name_str(), name_) == 0) {
// printf("overriding param %s=%f by =%f\n", name_, value_,
// *vec->double_params[i]);
value_ = *vec->double_params[i];
// *param);
value_ = *param;
break;
}
}
@ -267,7 +266,7 @@ class DoubleParam : public Param {
double value_;
double default_;
// Pointer to the vector that contains this param (not owned by this class).
GenericVector<DoubleParam*>* params_vec_;
std::vector<DoubleParam*>* params_vec_;
};
// Global parameter lists.

View File

@ -24,7 +24,6 @@
#include "serialis.h" // for TFile
#include <cassert> // for assert
#include <cstdlib> // for malloc, free
#include <locale> // for std::locale::classic
#include <sstream> // for std::stringstream

View File

@ -32,6 +32,7 @@
#include "errcode.h"
#include "helpers.h"
#include "genericvector.h"
#include "serialis.h"
#include <tesseract/version.h>
#include "tprintf.h"

View File

@ -54,8 +54,6 @@ const double kMaxRowSize = 2.5;
// Number of filled columns required to form a strong table row.
// For small tables, this is an absolute number.
const double kGoodRowNumberOfColumnsSmall[] = { 2, 2, 2, 2, 2, 3, 3 };
const int kGoodRowNumberOfColumnsSmallSize =
sizeof(kGoodRowNumberOfColumnsSmall) / sizeof(double) - 1;
// For large tables, it is a relative number
const double kGoodRowNumberOfColumnsLarge = 0.7;
// The amount of area that must be covered in a cell by ColPartitions to
@ -1055,11 +1053,12 @@ bool TableRecognizer::IsWeakTableRow(StructuredTable* table, int row) {
if (!table->VerifyRowFilled(row))
return false;
double threshold = 0.0;
if (table->column_count() > kGoodRowNumberOfColumnsSmallSize)
threshold = table->column_count() * kGoodRowNumberOfColumnsLarge;
else
double threshold;
if (table->column_count() < countof(kGoodRowNumberOfColumnsSmall)) {
threshold = kGoodRowNumberOfColumnsSmall[table->column_count()];
} else {
threshold = table->column_count() * kGoodRowNumberOfColumnsLarge;
}
return table->CountFilledCellsInRow(row) < threshold;
}

View File

@ -11,7 +11,8 @@
#include <cmath> // for std::isnan, NAN
#include <locale> // for std::locale::classic
#include <sstream> // for std::stringstream
#include <tesseract/baseapi.h> // TessBaseAPI::Version
#include <vector> // for std::vector
#include <tesseract/baseapi.h> // TessBaseAPI::Version
#include "commandlineflags.h"
#include "errcode.h"
#include "tprintf.h" // for tprintf
@ -20,7 +21,7 @@ namespace tesseract {
static bool IntFlagExists(const char* flag_name, int32_t* value) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<IntParam*> empty;
std::vector<IntParam*> empty;
IntParam *p = ParamUtils::FindParam<IntParam>(
full_flag_name.c_str(), GlobalParams()->int_params, empty);
if (p == nullptr) return false;
@ -31,7 +32,7 @@ static bool IntFlagExists(const char* flag_name, int32_t* value) {
static bool DoubleFlagExists(const char* flag_name, double* value) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<DoubleParam*> empty;
std::vector<DoubleParam*> empty;
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
full_flag_name.c_str(), GlobalParams()->double_params, empty);
if (p == nullptr) return false;
@ -42,7 +43,7 @@ static bool DoubleFlagExists(const char* flag_name, double* value) {
static bool BoolFlagExists(const char* flag_name, bool* value) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<BoolParam*> empty;
std::vector<BoolParam*> empty;
BoolParam *p = ParamUtils::FindParam<BoolParam>(
full_flag_name.c_str(), GlobalParams()->bool_params, empty);
if (p == nullptr) return false;
@ -53,7 +54,7 @@ static bool BoolFlagExists(const char* flag_name, bool* value) {
static bool StringFlagExists(const char* flag_name, const char** value) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<StringParam*> empty;
std::vector<StringParam*> empty;
StringParam *p = ParamUtils::FindParam<StringParam>(
full_flag_name.c_str(), GlobalParams()->string_params, empty);
*value = (p != nullptr) ? p->c_str() : nullptr;
@ -63,7 +64,7 @@ static bool StringFlagExists(const char* flag_name, const char** value) {
static void SetIntFlagValue(const char* flag_name, const int32_t new_val) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<IntParam*> empty;
std::vector<IntParam*> empty;
IntParam *p = ParamUtils::FindParam<IntParam>(
full_flag_name.c_str(), GlobalParams()->int_params, empty);
ASSERT_HOST(p != nullptr);
@ -73,7 +74,7 @@ static void SetIntFlagValue(const char* flag_name, const int32_t new_val) {
static void SetDoubleFlagValue(const char* flag_name, const double new_val) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<DoubleParam*> empty;
std::vector<DoubleParam*> empty;
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
full_flag_name.c_str(), GlobalParams()->double_params, empty);
ASSERT_HOST(p != nullptr);
@ -83,7 +84,7 @@ static void SetDoubleFlagValue(const char* flag_name, const double new_val) {
static void SetBoolFlagValue(const char* flag_name, const bool new_val) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<BoolParam*> empty;
std::vector<BoolParam*> empty;
BoolParam *p = ParamUtils::FindParam<BoolParam>(
full_flag_name.c_str(), GlobalParams()->bool_params, empty);
ASSERT_HOST(p != nullptr);
@ -93,7 +94,7 @@ static void SetBoolFlagValue(const char* flag_name, const bool new_val) {
static void SetStringFlagValue(const char* flag_name, const char* new_val) {
STRING full_flag_name("FLAGS_");
full_flag_name += flag_name;
GenericVector<StringParam*> empty;
std::vector<StringParam*> empty;
StringParam *p = ParamUtils::FindParam<StringParam>(
full_flag_name.c_str(), GlobalParams()->string_params, empty);
ASSERT_HOST(p != nullptr);

View File

@ -22,6 +22,7 @@
#include <allheaders.h> // from leptonica
#include "boxchar.h"
#include "helpers.h" // for TRand
#include "ligature_table.h"
#include "normstrngs.h"
#include "tlog.h"

View File

@ -282,7 +282,7 @@ TEST_F(TesseractTest, InitConfigOnlyTest) {
const char* langs[] = {"eng", "chi_tra", "jpn", "vie"};
std::unique_ptr<tesseract::TessBaseAPI> api;
CycleTimer timer;
for (size_t i = 0; i < ARRAYSIZE(langs); ++i) {
for (size_t i = 0; i < countof(langs); ++i) {
api.reset(new tesseract::TessBaseAPI);
timer.Restart();
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), langs[i],
@ -296,7 +296,7 @@ TEST_F(TesseractTest, InitConfigOnlyTest) {
vars_vec.push_back("tessedit_init_config_only");
vars_values.push_back("1");
LOG(INFO) << "Switching to config only initialization:";
for (size_t i = 0; i < ARRAYSIZE(langs); ++i) {
for (size_t i = 0; i < countof(langs); ++i) {
api.reset(new tesseract::TessBaseAPI);
timer.Restart();
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), langs[i],

View File

@ -44,7 +44,7 @@ class CommandlineflagsTest : public ::testing::Test {
TEST_F(CommandlineflagsTest, RemoveFlags) {
const char* const_argv[] = {"Progname", "--foo_int", "3", "file1.h",
"file2.h"};
int argc = ARRAYSIZE(const_argv);
int argc = countof(const_argv);
char** argv = const_cast<char**>(const_argv);
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
@ -58,7 +58,7 @@ TEST_F(CommandlineflagsTest, RemoveFlags) {
#if 0 // TODO: this test needs an update (it currently fails).
TEST_F(CommandlineflagsTest, PrintUsageAndExit) {
const char* argv[] = { "Progname", "--help" };
EXPECT_EXIT(TestParser("Progname [flags]", ARRAYSIZE(argv), argv),
EXPECT_EXIT(TestParser("Progname [flags]", countof(argv), argv),
::testing::ExitedWithCode(0),
"USAGE: Progname \\[flags\\]");
}
@ -66,32 +66,32 @@ TEST_F(CommandlineflagsTest, PrintUsageAndExit) {
TEST_F(CommandlineflagsTest, ExitsWithErrorOnInvalidFlag) {
const char* argv[] = {"", "--test_nonexistent_flag"};
EXPECT_EXIT(TestParser(ARRAYSIZE(argv), argv), ::testing::ExitedWithCode(1),
EXPECT_EXIT(TestParser(countof(argv), argv), ::testing::ExitedWithCode(1),
"ERROR: Non-existent flag");
}
TEST_F(CommandlineflagsTest, ParseIntegerFlags) {
const char* argv[] = {"", "--foo_int=3", "--bar_int", "-4"};
TestParser(ARRAYSIZE(argv), argv);
TestParser(countof(argv), argv);
EXPECT_EQ(3, FLAGS_foo_int);
EXPECT_EQ(-4, FLAGS_bar_int);
const char* arg_no_value[] = {"", "--bar_int"};
EXPECT_EXIT(TestParser(ARRAYSIZE(arg_no_value), arg_no_value),
EXPECT_EXIT(TestParser(countof(arg_no_value), arg_no_value),
::testing::ExitedWithCode(1), "ERROR");
const char* arg_invalid_value[] = {"", "--bar_int", "--foo_int=3"};
EXPECT_EXIT(TestParser(ARRAYSIZE(arg_invalid_value), arg_invalid_value),
EXPECT_EXIT(TestParser(countof(arg_invalid_value), arg_invalid_value),
::testing::ExitedWithCode(1), "ERROR");
const char* arg_bad_format[] = {"", "--bar_int="};
EXPECT_EXIT(TestParser(ARRAYSIZE(arg_bad_format), arg_bad_format),
EXPECT_EXIT(TestParser(countof(arg_bad_format), arg_bad_format),
::testing::ExitedWithCode(1), "ERROR");
}
TEST_F(CommandlineflagsTest, ParseDoubleFlags) {
const char* argv[] = {"", "--foo_double=3.14", "--bar_double", "1.2"};
TestParser(ARRAYSIZE(argv), argv);
TestParser(countof(argv), argv);
EXPECT_EQ(3.14, FLAGS_foo_double);
EXPECT_EQ(1.2, FLAGS_bar_double);
@ -107,7 +107,7 @@ TEST_F(CommandlineflagsTest, ParseDoubleFlags) {
TEST_F(CommandlineflagsTest, ParseStringFlags) {
const char* argv[] = {"", "--foo_string=abc", "--bar_string", "def"};
TestParser(ARRAYSIZE(argv), argv);
TestParser(countof(argv), argv);
EXPECT_STREQ("abc", FLAGS_foo_string.c_str());
EXPECT_STREQ("def", FLAGS_bar_string.c_str());
@ -126,7 +126,7 @@ TEST_F(CommandlineflagsTest, ParseBoolFlags) {
const char* argv[] = {"", "--foo_bool=true", "--bar_bool=1"};
FLAGS_foo_bool.set_value(false);
FLAGS_bar_bool.set_value(false);
TestParser(ARRAYSIZE(argv), argv);
TestParser(countof(argv), argv);
// Verify changed value
EXPECT_TRUE(FLAGS_foo_bool);
EXPECT_TRUE(FLAGS_bar_bool);
@ -152,7 +152,7 @@ TEST_F(CommandlineflagsTest, ParseBoolFlags) {
TEST_F(CommandlineflagsTest, ParseOldFlags) {
EXPECT_STREQ("", FLAGS_q.c_str());
const char* argv[] = {"", "-q", "text"};
TestParser(ARRAYSIZE(argv), argv);
TestParser(countof(argv), argv);
EXPECT_STREQ("text", FLAGS_q.c_str());
}
} // namespace

View File

@ -35,7 +35,7 @@ class HeapTest : public testing::Test {
virtual ~HeapTest();
// Pushes the test data onto both the heap and the KDVector.
void PushTestData(GenericHeap<IntKDPair>* heap, KDVector* v) {
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
for (size_t i = 0; i < countof(test_data); ++i) {
IntKDPair pair(test_data[i], i);
heap->Push(&pair);
v->push_back(pair);
@ -138,7 +138,7 @@ TEST_F(HeapTest, RevalueTest) {
GenericHeap<PtrPair> heap;
GenericVector<PtrPair> v;
// Push the test data onto both the heap and the vector.
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
for (size_t i = 0; i < countof(test_data); ++i) {
PtrPair h_pair;
h_pair.key() = test_data[i];
PtrPair v_pair;

View File

@ -59,8 +59,6 @@ public:
}
};
#define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
// /usr/include/tensorflow/core/platform/default/logging.h defines the CHECK* macros.
#if !defined(CHECK)
#define CHECK(condition) \

View File

@ -85,7 +85,7 @@ TEST_F(LigatureTableTest, TestCustomLigatures) {
"act", "a\uE003", "publiſh", "publi\uE006", "ſince",
"\uE007nce", "aſleep", "a\uE008eep", "neceſſary", "nece\uE009ary",
};
for (size_t i = 0; i < ARRAYSIZE(kTestCases); i += 2) {
for (size_t i = 0; i < countof(kTestCases); i += 2) {
EXPECT_STREQ(kTestCases[i + 1],
lig_table_->AddLigatures(kTestCases[i], nullptr).c_str());
EXPECT_STREQ(kTestCases[i],
@ -101,7 +101,7 @@ TEST_F(LigatureTableTest, TestRemovesCustomLigatures) {
"\uE003ion",
"fiction",
};
for (size_t i = 0; i < ARRAYSIZE(kTestCases); i += 3) {
for (size_t i = 0; i < countof(kTestCases); i += 3) {
EXPECT_STREQ(kTestCases[i + 1],
lig_table_->AddLigatures(kTestCases[i], nullptr).c_str());
EXPECT_STREQ(kTestCases[i + 2],

View File

@ -112,13 +112,13 @@ TEST(NormstrngsTest, DetectsCorrectText) {
}
TEST(NormstrngsTest, DetectsIncorrectText) {
for (size_t i = 0; i < ARRAYSIZE(kBadlyFormedHinWords); ++i) {
for (size_t i = 0; i < countof(kBadlyFormedHinWords); ++i) {
EXPECT_FALSE(NormalizeUTF8String(UnicodeNormMode::kNFKC, OCRNorm::kNone,
GraphemeNorm::kNormalize,
kBadlyFormedHinWords[i], nullptr))
<< kBadlyFormedHinWords[i];
}
for (size_t i = 0; i < ARRAYSIZE(kBadlyFormedThaiWords); ++i) {
for (size_t i = 0; i < countof(kBadlyFormedThaiWords); ++i) {
EXPECT_FALSE(NormalizeUTF8String(UnicodeNormMode::kNFKC, OCRNorm::kNone,
GraphemeNorm::kNormalize,
kBadlyFormedThaiWords[i], nullptr))

View File

@ -28,7 +28,7 @@ class NthItemTest : public testing::Test {
virtual ~NthItemTest();
// Pushes the test data onto the KDVector.
void PushTestData(KDVector* v) {
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
for (size_t i = 0; i < countof(test_data); ++i) {
IntKDPair pair(test_data[i], i);
v->push_back(pair);
}
@ -69,7 +69,7 @@ TEST_F(NthItemTest, BoringTest) {
KDVector v;
// Push the test data onto the KDVector.
int test_data[] = {8, 8, 8, 8, 8, 7, 7, 7, 7};
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
for (size_t i = 0; i < countof(test_data); ++i) {
IntKDPair pair(test_data[i], i);
v.push_back(pair);
}

View File

@ -169,7 +169,7 @@ TEST_F(PangoFontInfoTest, CanDropUncoveredChars) {
"\u200C", // U+200C (ZWJ)
"\u200D" // U+200D (ZWNJ)
};
for (size_t i = 0; i < ARRAYSIZE(kJoiners); ++i) {
for (size_t i = 0; i < countof(kJoiners); ++i) {
word = kJoiners[i];
EXPECT_EQ(0, font_info_.DropUncoveredChars(&word));
EXPECT_STREQ(kJoiners[i], word.c_str());
@ -253,7 +253,7 @@ TEST_F(FontUtilsTest, DoesFindBestFonts) {
std::string best_list = FontUtils::BestFonts(ch_map, &font_flags);
EXPECT_TRUE(best_list.size());
// All fonts except Lohit Hindi should render English text.
EXPECT_EQ(ARRAYSIZE(kExpectedFontNames) - 1, font_flags.size());
EXPECT_EQ(countof(kExpectedFontNames) - 1, font_flags.size());
CountUnicodeChars(kKorText, &ch_map);
best_list = FontUtils::BestFonts(ch_map, &font_flags);
@ -319,7 +319,7 @@ TEST_F(FontUtilsTest, GetAllRenderableCharacters) {
// Check that none of the included fonts cover the Mongolian or Ogham space
// characters.
for (size_t f = 0; f < ARRAYSIZE(kExpectedFontNames); ++f) {
for (size_t f = 0; f < countof(kExpectedFontNames); ++f) {
SCOPED_TRACE(absl::StrCat("Testing ", kExpectedFontNames[f]));
FontUtils::GetAllRenderableCharacters(kExpectedFontNames[f], &unicode_mask);
#if 0 // TODO: check fails because DejaVu Sans Ultra-Light supports ogham

View File

@ -243,7 +243,7 @@ const TextAndModel kTwoSimpleParagraphs[] = {
TEST(ParagraphsTest, TestSimpleParagraphDetection) {
TestParagraphDetection(kTwoSimpleParagraphs,
ABSL_ARRAYSIZE(kTwoSimpleParagraphs));
countof(kTwoSimpleParagraphs));
}
const TextAndModel kFewCluesWithCrown[] = {
@ -260,7 +260,7 @@ const TextAndModel kFewCluesWithCrown[] = {
TEST(ParagraphsTest, TestFewCluesWithCrown) {
TestParagraphDetection(kFewCluesWithCrown,
ABSL_ARRAYSIZE(kFewCluesWithCrown));
countof(kFewCluesWithCrown));
}
const TextAndModel kCrownedParagraph[] = {
@ -278,7 +278,7 @@ const TextAndModel kCrownedParagraph[] = {
};
TEST(ParagraphsTest, TestCrownParagraphDetection) {
TestParagraphDetection(kCrownedParagraph, ABSL_ARRAYSIZE(kCrownedParagraph));
TestParagraphDetection(kCrownedParagraph, countof(kCrownedParagraph));
}
const TextAndModel kFlushLeftParagraphs[] = {
@ -298,7 +298,7 @@ const TextAndModel kFlushLeftParagraphs[] = {
TEST(ParagraphsText, TestRealFlushLeftParagraphs) {
TestParagraphDetection(kFlushLeftParagraphs,
ABSL_ARRAYSIZE(kFlushLeftParagraphs));
countof(kFlushLeftParagraphs));
}
const TextAndModel kSingleFullPageContinuation[] = {
@ -320,7 +320,7 @@ const TextAndModel kSingleFullPageContinuation[] = {
TEST(ParagraphsTest, TestSingleFullPageContinuation) {
const TextAndModel* correct = kSingleFullPageContinuation;
int num_rows = ABSL_ARRAYSIZE(kSingleFullPageContinuation);
int num_rows = countof(kSingleFullPageContinuation);
std::vector<RowInfo> row_infos;
GenericVector<PARA*> row_owners;
PARA_LIST paragraphs;
@ -346,7 +346,7 @@ const TextAndModel kRightAligned[] = {
};
TEST(ParagraphsTest, TestRightAlignedParagraph) {
TestParagraphDetection(kRightAligned, ABSL_ARRAYSIZE(kRightAligned));
TestParagraphDetection(kRightAligned, countof(kRightAligned));
}
const TextAndModel kTinyParagraphs[] = {
@ -368,7 +368,7 @@ const TextAndModel kTinyParagraphs[] = {
};
TEST(ParagraphsTest, TestTinyParagraphs) {
TestParagraphDetection(kTinyParagraphs, ABSL_ARRAYSIZE(kTinyParagraphs));
TestParagraphDetection(kTinyParagraphs, countof(kTinyParagraphs));
}
const TextAndModel kComplexPage1[] = {
@ -418,7 +418,7 @@ const TextAndModel kComplexPage1[] = {
};
TEST(ParagraphsTest, TestComplexPage1) {
TestParagraphDetection(kComplexPage1, ABSL_ARRAYSIZE(kComplexPage1));
TestParagraphDetection(kComplexPage1, countof(kComplexPage1));
}
// The same as above, but wider.
@ -467,7 +467,7 @@ const TextAndModel kComplexPage2[] = {
};
TEST(ParagraphsTest, TestComplexPage2) {
TestParagraphDetection(kComplexPage2, ABSL_ARRAYSIZE(kComplexPage2));
TestParagraphDetection(kComplexPage2, countof(kComplexPage2));
}
const TextAndModel kSubtleCrown[] = {
@ -483,11 +483,11 @@ const TextAndModel kSubtleCrown[] = {
};
TEST(ParagraphsTest, TestSubtleCrown) {
TestParagraphDetection(kSubtleCrown, ABSL_ARRAYSIZE(kSubtleCrown) - 1);
TestParagraphDetection(kSubtleCrown, countof(kSubtleCrown) - 1);
}
TEST(ParagraphsTest, TestStrayLineInBlock) {
TestParagraphDetection(kSubtleCrown, ABSL_ARRAYSIZE(kSubtleCrown));
TestParagraphDetection(kSubtleCrown, countof(kSubtleCrown));
}
const TextAndModel kUnlvRep3AO[] = {
@ -531,7 +531,7 @@ const TextAndModel kUnlvRep3AO[] = {
};
TEST(ParagraphsTest, TestUnlvInsurance) {
TestParagraphDetection(kUnlvRep3AO, ABSL_ARRAYSIZE(kUnlvRep3AO));
TestParagraphDetection(kUnlvRep3AO, countof(kUnlvRep3AO));
}
// The basic outcome we want for something with a bunch of leader dots is that
@ -556,7 +556,7 @@ const TextAndModel kTableOfContents[] = {
};
TEST(ParagraphsTest, TestSplitsOutLeaderLines) {
TestParagraphDetection(kTableOfContents, ABSL_ARRAYSIZE(kTableOfContents));
TestParagraphDetection(kTableOfContents, countof(kTableOfContents));
}
const TextAndModel kTextWithSourceCode[] = {
@ -592,7 +592,7 @@ const TextAndModel kTextWithSourceCode[] = {
TEST(ParagraphsTest, NotDistractedBySourceCode) {
TestParagraphDetection(kTextWithSourceCode,
ABSL_ARRAYSIZE(kTextWithSourceCode));
countof(kTextWithSourceCode));
}
const TextAndModel kOldManAndSea[] = {
@ -659,7 +659,7 @@ const TextAndModel kOldManAndSea[] = {
};
TEST(ParagraphsTest, NotOverlyAggressiveWithBlockQuotes) {
TestParagraphDetection(kOldManAndSea, ABSL_ARRAYSIZE(kOldManAndSea));
TestParagraphDetection(kOldManAndSea, countof(kOldManAndSea));
}
const TextAndModel kNewZealandIndex[] = {
@ -697,7 +697,7 @@ const TextAndModel kNewZealandIndex[] = {
};
TEST(ParagraphsTest, IndexPageTest) {
TestParagraphDetection(kNewZealandIndex, ABSL_ARRAYSIZE(kNewZealandIndex));
TestParagraphDetection(kNewZealandIndex, countof(kNewZealandIndex));
}
// TODO(eger): Add some right-to-left examples, and fix the algorithm as needed.

View File

@ -486,12 +486,12 @@ TEST_F(ResultIteratorTest, DualStartTextlineOrderTest) {
7, 6,
5, ResultIterator::kMinorRunEnd};
ExpectTextlineReadingOrder(true, word_dirs, ABSL_ARRAYSIZE(word_dirs),
ExpectTextlineReadingOrder(true, word_dirs, countof(word_dirs),
reading_order_ltr_context,
ABSL_ARRAYSIZE(reading_order_ltr_context));
ExpectTextlineReadingOrder(false, word_dirs, ABSL_ARRAYSIZE(word_dirs),
countof(reading_order_ltr_context));
ExpectTextlineReadingOrder(false, word_dirs, countof(word_dirs),
reading_order_rtl_context,
ABSL_ARRAYSIZE(reading_order_rtl_context));
countof(reading_order_rtl_context));
}
// Tests that clearly left-direction text (with no right-to-left indications)
@ -506,12 +506,12 @@ TEST_F(ResultIteratorTest, LeftwardTextlineOrderTest) {
ResultIterator::kMinorRunStart, 0, 1, 2, 3, 4, 5, 6, 7,
ResultIterator::kMinorRunEnd};
ExpectTextlineReadingOrder(true, word_dirs, ABSL_ARRAYSIZE(word_dirs),
ExpectTextlineReadingOrder(true, word_dirs, countof(word_dirs),
reading_order_ltr_context,
ABSL_ARRAYSIZE(reading_order_ltr_context));
ExpectTextlineReadingOrder(false, word_dirs, ABSL_ARRAYSIZE(word_dirs),
countof(reading_order_ltr_context));
ExpectTextlineReadingOrder(false, word_dirs, countof(word_dirs),
reading_order_rtl_context,
ABSL_ARRAYSIZE(reading_order_rtl_context));
countof(reading_order_rtl_context));
}
// Test that right-direction text comes out strictly right-to-left in
@ -520,9 +520,9 @@ TEST_F(ResultIteratorTest, RightwardTextlineOrderTest) {
const StrongScriptDirection word_dirs[] = {dR, dR, dN, dR, dN, dN, dR, dR};
// The order here is just right-to-left, nothing fancy.
int reading_order_rtl_context[] = {7, 6, 5, 4, 3, 2, 1, 0};
ExpectTextlineReadingOrder(false, word_dirs, ABSL_ARRAYSIZE(word_dirs),
ExpectTextlineReadingOrder(false, word_dirs, countof(word_dirs),
reading_order_rtl_context,
ABSL_ARRAYSIZE(reading_order_rtl_context));
countof(reading_order_rtl_context));
}
TEST_F(ResultIteratorTest, TextlineOrderSanityCheck) {

View File

@ -24,7 +24,7 @@ class STATSTest : public testing::Test {
void SetUp() {
std::locale::global(std::locale(""));
stats_.set_range(0, 16);
for (size_t i = 0; i < ARRAYSIZE(kTestData); ++i)
for (size_t i = 0; i < countof(kTestData); ++i)
stats_.add(i, kTestData[i]);
}