tesseract  4.0.0-1-g2a2b
UNICHARSET Class Reference

#include <unicharset.h>

Public Types

enum  Direction {
  U_LEFT_TO_RIGHT = 0, U_RIGHT_TO_LEFT = 1, U_EUROPEAN_NUMBER = 2, U_EUROPEAN_NUMBER_SEPARATOR = 3,
  U_EUROPEAN_NUMBER_TERMINATOR = 4, U_ARABIC_NUMBER = 5, U_COMMON_NUMBER_SEPARATOR = 6, U_BLOCK_SEPARATOR = 7,
  U_SEGMENT_SEPARATOR = 8, U_WHITE_SPACE_NEUTRAL = 9, U_OTHER_NEUTRAL = 10, U_LEFT_TO_RIGHT_EMBEDDING = 11,
  U_LEFT_TO_RIGHT_OVERRIDE = 12, U_RIGHT_TO_LEFT_ARABIC = 13, U_RIGHT_TO_LEFT_EMBEDDING = 14, U_RIGHT_TO_LEFT_OVERRIDE = 15,
  U_POP_DIRECTIONAL_FORMAT = 16, U_DIR_NON_SPACING_MARK = 17, U_BOUNDARY_NEUTRAL = 18, U_CHAR_DIRECTION_COUNT
}
 

Public Member Functions

 UNICHARSET ()
 
 ~UNICHARSET ()
 
UNICHAR_ID unichar_to_id (const char *const unichar_repr) const
 
UNICHAR_ID unichar_to_id (const char *const unichar_repr, int length) const
 
int step (const char *str) const
 
bool encodable_string (const char *str, int *first_bad_position) const
 
bool encode_string (const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
 
const char * id_to_unichar (UNICHAR_ID id) const
 
const char * id_to_unichar_ext (UNICHAR_ID id) const
 
STRING debug_str (UNICHAR_ID id) const
 
STRING debug_str (const char *unichar_repr) const
 
void unichar_insert (const char *const unichar_repr, OldUncleanUnichars old_style)
 
void unichar_insert (const char *const unichar_repr)
 
void unichar_insert_backwards_compatible (const char *const unichar_repr)
 
bool contains_unichar_id (UNICHAR_ID unichar_id) const
 
bool contains_unichar (const char *const unichar_repr) const
 
bool contains_unichar (const char *const unichar_repr, int length) const
 
bool eq (UNICHAR_ID unichar_id, const char *const unichar_repr) const
 
void delete_pointers_in_unichars ()
 
void clear ()
 
int size () const
 
void reserve (int unichars_number)
 
bool save_to_file (const char *const filename) const
 
bool save_to_file (FILE *file) const
 
bool save_to_file (tesseract::TFile *file) const
 
bool save_to_string (STRING *str) const
 
bool load_from_inmemory_file (const char *const memory, int mem_size, bool skip_fragments)
 
bool load_from_inmemory_file (const char *const memory, int mem_size)
 
bool load_from_file (const char *const filename, bool skip_fragments)
 
bool load_from_file (const char *const filename)
 
bool load_from_file (FILE *file, bool skip_fragments)
 
bool load_from_file (FILE *file)
 
bool load_from_file (tesseract::TFile *file, bool skip_fragments)
 
void post_load_setup ()
 
bool major_right_to_left () const
 
void set_black_and_whitelist (const char *blacklist, const char *whitelist, const char *unblacklist)
 
void set_isalpha (UNICHAR_ID unichar_id, bool value)
 
void set_islower (UNICHAR_ID unichar_id, bool value)
 
void set_isupper (UNICHAR_ID unichar_id, bool value)
 
void set_isdigit (UNICHAR_ID unichar_id, bool value)
 
void set_ispunctuation (UNICHAR_ID unichar_id, bool value)
 
void set_isngram (UNICHAR_ID unichar_id, bool value)
 
void set_script (UNICHAR_ID unichar_id, const char *value)
 
void set_other_case (UNICHAR_ID unichar_id, UNICHAR_ID other_case)
 
void set_direction (UNICHAR_ID unichar_id, UNICHARSET::Direction value)
 
void set_mirror (UNICHAR_ID unichar_id, UNICHAR_ID mirror)
 
void set_normed (UNICHAR_ID unichar_id, const char *normed)
 
void set_normed_ids (UNICHAR_ID unichar_id)
 
bool get_isalpha (UNICHAR_ID unichar_id) const
 
bool get_islower (UNICHAR_ID unichar_id) const
 
bool get_isupper (UNICHAR_ID unichar_id) const
 
bool get_isdigit (UNICHAR_ID unichar_id) const
 
bool get_ispunctuation (UNICHAR_ID unichar_id) const
 
bool get_isngram (UNICHAR_ID unichar_id) const
 
bool get_isprivate (UNICHAR_ID unichar_id) const
 
bool top_bottom_useful () const
 
void set_ranges_empty ()
 
void SetPropertiesFromOther (const UNICHARSET &src)
 
void PartialSetPropertiesFromOther (int start_index, const UNICHARSET &src)
 
void ExpandRangesFromOther (const UNICHARSET &src)
 
void CopyFrom (const UNICHARSET &src)
 
void AppendOtherUnicharset (const UNICHARSET &src)
 
bool SizesDistinct (UNICHAR_ID id1, UNICHAR_ID id2) const
 
void get_top_bottom (UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
 
void set_top_bottom (UNICHAR_ID unichar_id, int min_bottom, int max_bottom, int min_top, int max_top)
 
void get_width_stats (UNICHAR_ID unichar_id, float *width, float *width_sd) const
 
void set_width_stats (UNICHAR_ID unichar_id, float width, float width_sd)
 
void get_bearing_stats (UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
 
void set_bearing_stats (UNICHAR_ID unichar_id, float bearing, float bearing_sd)
 
void get_advance_stats (UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
 
void set_advance_stats (UNICHAR_ID unichar_id, float advance, float advance_sd)
 
bool PropertiesIncomplete (UNICHAR_ID unichar_id) const
 
bool IsSpaceDelimited (UNICHAR_ID unichar_id) const
 
int get_script (UNICHAR_ID unichar_id) const
 
unsigned int get_properties (UNICHAR_ID unichar_id) const
 
char get_chartype (UNICHAR_ID unichar_id) const
 
UNICHAR_ID get_other_case (UNICHAR_ID unichar_id) const
 
Direction get_direction (UNICHAR_ID unichar_id) const
 
UNICHAR_ID get_mirror (UNICHAR_ID unichar_id) const
 
UNICHAR_ID to_lower (UNICHAR_ID unichar_id) const
 
UNICHAR_ID to_upper (UNICHAR_ID unichar_id) const
 
bool has_special_codes () const
 
bool AnyRepeatedUnicodes () const
 
const CHAR_FRAGMENTget_fragment (UNICHAR_ID unichar_id) const
 
bool get_isalpha (const char *const unichar_repr) const
 
bool get_islower (const char *const unichar_repr) const
 
bool get_isupper (const char *const unichar_repr) const
 
bool get_isdigit (const char *const unichar_repr) const
 
bool get_ispunctuation (const char *const unichar_repr) const
 
unsigned int get_properties (const char *const unichar_repr) const
 
char get_chartype (const char *const unichar_repr) const
 
int get_script (const char *const unichar_repr) const
 
const CHAR_FRAGMENTget_fragment (const char *const unichar_repr) const
 
bool get_isalpha (const char *const unichar_repr, int length) const
 
bool get_islower (const char *const unichar_repr, int length) const
 
bool get_isupper (const char *const unichar_repr, int length) const
 
bool get_isdigit (const char *const unichar_repr, int length) const
 
bool get_ispunctuation (const char *const unichar_repr, int length) const
 
const char * get_normed_unichar (UNICHAR_ID unichar_id) const
 
const GenericVector< UNICHAR_ID > & normed_ids (UNICHAR_ID unichar_id) const
 
int get_script (const char *const unichar_repr, int length) const
 
int get_script_table_size () const
 
const char * get_script_from_script_id (int id) const
 
int get_script_id_from_name (const char *script_name) const
 
bool is_null_script (const char *script) const
 
int add_script (const char *script)
 
bool get_enabled (UNICHAR_ID unichar_id) const
 
int null_sid () const
 
int common_sid () const
 
int latin_sid () const
 
int cyrillic_sid () const
 
int greek_sid () const
 
int han_sid () const
 
int hiragana_sid () const
 
int katakana_sid () const
 
int thai_sid () const
 
int hangul_sid () const
 
int default_sid () const
 
bool script_has_upper_lower () const
 
bool script_has_xheight () const
 

Static Public Member Functions

static STRING debug_utf8_str (const char *str)
 
static std::string CleanupString (const char *utf8_str)
 
static std::string CleanupString (const char *utf8_str, size_t length)
 

Static Public Attributes

static TESS_API const char * kCustomLigatures [][2]
 
static TESS_API const char * kSpecialUnicharCodes [SPECIAL_UNICHAR_CODES_COUNT]
 

Detailed Description

Definition at line 146 of file unicharset.h.

Member Enumeration Documentation

◆ Direction

Enumerator
U_LEFT_TO_RIGHT 
U_RIGHT_TO_LEFT 
U_EUROPEAN_NUMBER 
U_EUROPEAN_NUMBER_SEPARATOR 
U_EUROPEAN_NUMBER_TERMINATOR 
U_ARABIC_NUMBER 
U_COMMON_NUMBER_SEPARATOR 
U_BLOCK_SEPARATOR 
U_SEGMENT_SEPARATOR 
U_WHITE_SPACE_NEUTRAL 
U_OTHER_NEUTRAL 
U_LEFT_TO_RIGHT_EMBEDDING 
U_LEFT_TO_RIGHT_OVERRIDE 
U_RIGHT_TO_LEFT_ARABIC 
U_RIGHT_TO_LEFT_EMBEDDING 
U_RIGHT_TO_LEFT_OVERRIDE 
U_POP_DIRECTIONAL_FORMAT 
U_DIR_NON_SPACING_MARK 
U_BOUNDARY_NEUTRAL 
U_CHAR_DIRECTION_COUNT 

Definition at line 157 of file unicharset.h.

157  {
158  U_LEFT_TO_RIGHT = 0,
159  U_RIGHT_TO_LEFT = 1,
160  U_EUROPEAN_NUMBER = 2,
163  U_ARABIC_NUMBER = 5,
165  U_BLOCK_SEPARATOR = 7,
168  U_OTHER_NEUTRAL = 10,
176  U_BOUNDARY_NEUTRAL = 18,
178  };

Constructor & Destructor Documentation

◆ UNICHARSET()

UNICHARSET::UNICHARSET ( )

Definition at line 175 of file unicharset.cpp.

175  :
176  unichars(nullptr),
177  ids(),
178  size_used(0),
179  size_reserved(0),
180  script_table(nullptr),
181  script_table_size_used(0) {
182  clear();
183  for (int i = 0; i < SPECIAL_UNICHAR_CODES_COUNT; ++i) {
185  if (i == UNICHAR_JOINED)
186  set_isngram(i, true);
187  }
188 }
static TESS_API const char * kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT]
Definition: unicharset.h:154
void set_isngram(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:451
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
Definition: unicharset.cpp:625
void clear()
Definition: unicharset.h:301

◆ ~UNICHARSET()

UNICHARSET::~UNICHARSET ( )

Definition at line 190 of file unicharset.cpp.

190  {
191  clear();
192 }
void clear()
Definition: unicharset.h:301

Member Function Documentation

◆ add_script()

int UNICHARSET::add_script ( const char *  script)

Definition at line 1030 of file unicharset.cpp.

1030  {
1031  for (int i = 0; i < script_table_size_used; ++i) {
1032  if (strcmp(script, script_table[i]) == 0)
1033  return i;
1034  }
1035  if (script_table_size_reserved == 0) {
1036  script_table_size_reserved = 8;
1037  script_table = new char*[script_table_size_reserved];
1038  } else if (script_table_size_used >= script_table_size_reserved) {
1039  assert(script_table_size_used == script_table_size_reserved);
1040  script_table_size_reserved += script_table_size_reserved;
1041  char** new_script_table = new char*[script_table_size_reserved];
1042  memcpy(new_script_table, script_table,
1043  script_table_size_used * sizeof(char*));
1044  delete[] script_table;
1045  script_table = new_script_table;
1046  }
1047  script_table[script_table_size_used] = new char[strlen(script) + 1];
1048  strcpy(script_table[script_table_size_used], script);
1049  return script_table_size_used++;
1050 }

◆ AnyRepeatedUnicodes()

bool UNICHARSET::AnyRepeatedUnicodes ( ) const

Definition at line 1017 of file unicharset.cpp.

1017  {
1018  int start_id = 0;
1020  for (int id = start_id; id < size_used; ++id) {
1021  // Convert to unicodes.
1022  std::vector<char32> unicodes = UNICHAR::UTF8ToUTF32(get_normed_unichar(id));
1023  for (int u = 1; u < unicodes.size(); ++u) {
1024  if (unicodes[u - 1] == unicodes[u]) return true;
1025  }
1026  }
1027  return false;
1028 }
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
Definition: unicharset.h:823
bool has_special_codes() const
Definition: unicharset.h:717

◆ AppendOtherUnicharset()

void UNICHARSET::AppendOtherUnicharset ( const UNICHARSET src)

Definition at line 463 of file unicharset.cpp.

463  {
464  int initial_used = size_used;
465  for (int ch = 0; ch < src.size_used; ++ch) {
466  const UNICHAR_PROPERTIES& src_props = src.unichars[ch].properties;
467  const char* utf8 = src.id_to_unichar(ch);
468  int id = size_used;
469  if (contains_unichar(utf8)) {
470  id = unichar_to_id(utf8);
471  // Just expand current ranges.
472  unichars[id].properties.ExpandRangesFrom(src_props);
473  } else {
475  unichars[id].properties.SetRangesEmpty();
476  }
477  }
478  // Set properties, including mirror and other_case, WITHOUT reordering
479  // the unicharset.
480  PartialSetPropertiesFromOther(initial_used, src);
481 }
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
Definition: unicharset.cpp:404
void unichar_insert_backwards_compatible(const char *const unichar_repr)
Definition: unicharset.h:264
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:670
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290

◆ CleanupString() [1/2]

static std::string UNICHARSET::CleanupString ( const char *  utf8_str)
inlinestatic

Definition at line 241 of file unicharset.h.

241  {
242  return CleanupString(utf8_str, strlen(utf8_str));
243  }
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241

◆ CleanupString() [2/2]

std::string UNICHARSET::CleanupString ( const char *  utf8_str,
size_t  length 
)
static

Definition at line 1120 of file unicharset.cpp.

1120  {
1121  std::string result;
1122  result.reserve(length);
1123  char ch;
1124  while ((ch = *utf8_str) != '\0' && length-- > 0) {
1125  int key_index = 0;
1126  const char* key;
1127  while ((key = kCleanupMaps[key_index][0]) != nullptr) {
1128  int match = 0;
1129  while (key[match] != '\0' && key[match] == utf8_str[match]) ++match;
1130  if (key[match] == '\0') {
1131  utf8_str += match;
1132  break;
1133  }
1134  ++key_index;
1135  }
1136  if (key == nullptr) {
1137  result.push_back(ch);
1138  ++utf8_str;
1139  } else {
1140  result.append(kCleanupMaps[key_index][1]);
1141  }
1142  }
1143  return result;
1144 }

◆ clear()

void UNICHARSET::clear ( )
inline

Definition at line 301 of file unicharset.h.

301  {
302  if (script_table != nullptr) {
303  for (int i = 0; i < script_table_size_used; ++i)
304  delete[] script_table[i];
305  delete[] script_table;
306  script_table = nullptr;
307  script_table_size_used = 0;
308  }
309  if (unichars != nullptr) {
311  delete[] unichars;
312  unichars = nullptr;
313  }
314  script_table_size_reserved = 0;
315  size_reserved = 0;
316  size_used = 0;
317  ids.clear();
318  top_bottom_set_ = false;
319  script_has_upper_lower_ = false;
320  script_has_xheight_ = false;
321  old_style_included_ = false;
322  null_sid_ = 0;
323  common_sid_ = 0;
324  latin_sid_ = 0;
325  cyrillic_sid_ = 0;
326  greek_sid_ = 0;
327  han_sid_ = 0;
328  hiragana_sid_ = 0;
329  katakana_sid_ = 0;
330  thai_sid_ = 0;
331  hangul_sid_ = 0;
332  default_sid_ = 0;
333  }
void clear()
Definition: unicharmap.cpp:117
void delete_pointers_in_unichars()
Definition: unicharset.h:293

◆ common_sid()

int UNICHARSET::common_sid ( ) const
inline

Definition at line 879 of file unicharset.h.

879 { return common_sid_; }

◆ contains_unichar() [1/2]

bool UNICHARSET::contains_unichar ( const char *const  unichar_repr) const

Definition at line 670 of file unicharset.cpp.

670  {
671  std::string cleaned =
672  old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
673  return ids.contains(cleaned.data(), cleaned.size());
674 }
bool contains(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:81
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241

◆ contains_unichar() [2/2]

bool UNICHARSET::contains_unichar ( const char *const  unichar_repr,
int  length 
) const

Definition at line 676 of file unicharset.cpp.

677  {
678  if (length == 0) {
679  return false;
680  }
681  std::string cleaned(unichar_repr, length);
682  if (!old_style_included_) cleaned = CleanupString(unichar_repr, length);
683  return ids.contains(cleaned.data(), cleaned.size());
684 }
bool contains(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:81
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241

◆ contains_unichar_id()

bool UNICHARSET::contains_unichar_id ( UNICHAR_ID  unichar_id) const
inline

Definition at line 279 of file unicharset.h.

279  {
280  return unichar_id != INVALID_UNICHAR_ID && unichar_id < size_used &&
281  unichar_id >= 0;
282  }

◆ CopyFrom()

void UNICHARSET::CopyFrom ( const UNICHARSET src)

Definition at line 447 of file unicharset.cpp.

447  {
448  clear();
449  for (int ch = 0; ch < src.size_used; ++ch) {
450  const UNICHAR_PROPERTIES& src_props = src.unichars[ch].properties;
451  const char* utf8 = src.id_to_unichar(ch);
453  unichars[ch].properties.ExpandRangesFrom(src_props);
454  }
455  // Set properties, including mirror and other_case, WITHOUT reordering
456  // the unicharset.
458 }
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
Definition: unicharset.cpp:404
void unichar_insert_backwards_compatible(const char *const unichar_repr)
Definition: unicharset.h:264
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
void clear()
Definition: unicharset.h:301

◆ cyrillic_sid()

int UNICHARSET::cyrillic_sid ( ) const
inline

Definition at line 881 of file unicharset.h.

881 { return cyrillic_sid_; }

◆ debug_str() [1/2]

STRING UNICHARSET::debug_str ( UNICHAR_ID  id) const

Definition at line 342 of file unicharset.cpp.

342  {
343  if (id == INVALID_UNICHAR_ID) return STRING(id_to_unichar(id));
344  const CHAR_FRAGMENT *fragment = this->get_fragment(id);
345  if (fragment) {
346  return fragment->to_string();
347  }
348  const char* str = id_to_unichar(id);
349  STRING result = debug_utf8_str(str);
350  // Append a for lower alpha, A for upper alpha, and x if alpha but neither.
351  if (get_isalpha(id)) {
352  if (get_islower(id))
353  result += "a";
354  else if (get_isupper(id))
355  result += "A";
356  else
357  result += "x";
358  }
359  // Append 0 if a digit.
360  if (get_isdigit(id)) {
361  result += "0";
362  }
363  // Append p is a punctuation symbol.
364  if (get_ispunctuation(id)) {
365  result += "p";
366  }
367  return result;
368 }
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:493
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:514
static STRING to_string(const char *unichar, int pos, int total, bool natural)
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:507
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:729
Definition: strngs.h:45
static STRING debug_utf8_str(const char *str)
Definition: unicharset.cpp:318
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:500

◆ debug_str() [2/2]

STRING UNICHARSET::debug_str ( const char *  unichar_repr) const
inline

Definition at line 249 of file unicharset.h.

249  {
250  return debug_str(unichar_to_id(unichar_repr));
251  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:342

◆ debug_utf8_str()

STRING UNICHARSET::debug_utf8_str ( const char *  str)
static

Definition at line 318 of file unicharset.cpp.

318  {
319  STRING result = str;
320  result += " [";
321  int step = 1;
322  // Chop into unicodes and code each as hex.
323  for (int i = 0; str[i] != '\0'; i += step) {
324  char hex[sizeof(int) * 2 + 1];
325  step = UNICHAR::utf8_step(str + i);
326  if (step == 0) {
327  step = 1;
328  sprintf(hex, "%x", str[i]);
329  } else {
330  UNICHAR ch(str + i, step);
331  sprintf(hex, "%x", ch.first_uni());
332  }
333  result += hex;
334  result += " ";
335  }
336  result += "]";
337  return result;
338 }
int step(const char *str) const
Definition: unicharset.cpp:232
Definition: strngs.h:45

◆ default_sid()

int UNICHARSET::default_sid ( ) const
inline

Definition at line 888 of file unicharset.h.

888 { return default_sid_; }

◆ delete_pointers_in_unichars()

void UNICHARSET::delete_pointers_in_unichars ( )
inline

Definition at line 293 of file unicharset.h.

293  {
294  for (int i = 0; i < size_used; ++i) {
295  delete unichars[i].properties.fragment;
296  unichars[i].properties.fragment = nullptr;
297  }
298  }

◆ encodable_string()

bool UNICHARSET::encodable_string ( const char *  str,
int *  first_bad_position 
) const

Definition at line 243 of file unicharset.cpp.

244  {
245  GenericVector<UNICHAR_ID> encoding;
246  return encode_string(str, true, &encoding, nullptr, first_bad_position);
247 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:258

◆ encode_string()

bool UNICHARSET::encode_string ( const char *  str,
bool  give_up_on_failure,
GenericVector< UNICHAR_ID > *  encoding,
GenericVector< char > *  lengths,
int *  encoded_length 
) const

Definition at line 258 of file unicharset.cpp.

261  {
262  GenericVector<UNICHAR_ID> working_encoding;
263  GenericVector<char> working_lengths;
264  GenericVector<char> best_lengths;
265  encoding->truncate(0); // Just in case str is empty.
266  int str_length = strlen(str);
267  int str_pos = 0;
268  bool perfect = true;
269  while (str_pos < str_length) {
270  encode_string(str, str_pos, str_length, &working_encoding, &working_lengths,
271  &str_pos, encoding, &best_lengths);
272  if (str_pos < str_length) {
273  // This is a non-match. Skip one utf-8 character.
274  perfect = false;
275  if (give_up_on_failure) break;
276  int step = UNICHAR::utf8_step(str + str_pos);
277  if (step == 0) step = 1;
278  encoding->push_back(INVALID_UNICHAR_ID);
279  best_lengths.push_back(step);
280  str_pos += step;
281  working_encoding = *encoding;
282  working_lengths = best_lengths;
283  }
284  }
285  if (lengths != nullptr) *lengths = best_lengths;
286  if (encoded_length != nullptr) *encoded_length = str_pos;
287  return perfect;
288 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:258
int step(const char *str) const
Definition: unicharset.cpp:232
int push_back(T object)
void truncate(int size)

◆ eq()

bool UNICHARSET::eq ( UNICHAR_ID  unichar_id,
const char *const  unichar_repr 
) const

Definition at line 686 of file unicharset.cpp.

687  {
688  return strcmp(this->id_to_unichar(unichar_id), unichar_repr) == 0;
689 }
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290

◆ ExpandRangesFromOther()

void UNICHARSET::ExpandRangesFromOther ( const UNICHARSET src)

Definition at line 434 of file unicharset.cpp.

434  {
435  for (int ch = 0; ch < size_used; ++ch) {
436  const char* utf8 = id_to_unichar(ch);
437  UNICHAR_PROPERTIES properties;
438  if (src.GetStrProperties(utf8, &properties)) {
439  // Expand just the ranges from properties.
440  unichars[ch].properties.ExpandRangesFrom(properties);
441  }
442  }
443 }
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290

◆ get_advance_stats()

void UNICHARSET::get_advance_stats ( UNICHAR_ID  unichar_id,
float *  advance,
float *  advance_sd 
) const
inline

Definition at line 625 of file unicharset.h.

626  {
627  if (INVALID_UNICHAR_ID == unichar_id) {
628  *advance = *advance_sd = 0;
629  return;
630  }
631  ASSERT_HOST(contains_unichar_id(unichar_id));
632  *advance = unichars[unichar_id].properties.advance;
633  *advance_sd = unichars[unichar_id].properties.advance_sd;
634  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_bearing_stats()

void UNICHARSET::get_bearing_stats ( UNICHAR_ID  unichar_id,
float *  bearing,
float *  bearing_sd 
) const
inline

Definition at line 608 of file unicharset.h.

609  {
610  if (INVALID_UNICHAR_ID == unichar_id) {
611  *bearing = *bearing_sd = 0.0f;
612  return;
613  }
614  ASSERT_HOST(contains_unichar_id(unichar_id));
615  *bearing = unichars[unichar_id].properties.bearing;
616  *bearing_sd = unichars[unichar_id].properties.bearing_sd;
617  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_chartype() [1/2]

char UNICHARSET::get_chartype ( UNICHAR_ID  unichar_id) const

Definition at line 616 of file unicharset.cpp.

616  {
617  if (this->get_isupper(id)) return 'A';
618  if (this->get_islower(id)) return 'a';
619  if (this->get_isalpha(id)) return 'x';
620  if (this->get_isdigit(id)) return '0';
621  if (this->get_ispunctuation(id)) return 'p';
622  return 0;
623 }
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:493
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:514
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:507
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:500

◆ get_chartype() [2/2]

char UNICHARSET::get_chartype ( const char *const  unichar_repr) const
inline

Definition at line 766 of file unicharset.h.

766  {
767  return get_chartype(unichar_to_id(unichar_repr));
768  }
char get_chartype(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:616
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209

◆ get_direction()

Direction UNICHARSET::get_direction ( UNICHAR_ID  unichar_id) const
inline

Definition at line 685 of file unicharset.h.

685  {
686  if (INVALID_UNICHAR_ID == unichar_id) return UNICHARSET::U_OTHER_NEUTRAL;
687  ASSERT_HOST(contains_unichar_id(unichar_id));
688  return unichars[unichar_id].properties.direction;
689  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_enabled()

bool UNICHARSET::get_enabled ( UNICHAR_ID  unichar_id) const
inline

Definition at line 873 of file unicharset.h.

873  {
874  return unichars[unichar_id].properties.enabled;
875  }

◆ get_fragment() [1/2]

const CHAR_FRAGMENT* UNICHARSET::get_fragment ( UNICHAR_ID  unichar_id) const
inline

Definition at line 729 of file unicharset.h.

729  {
730  if (INVALID_UNICHAR_ID == unichar_id) return nullptr;
731  ASSERT_HOST(contains_unichar_id(unichar_id));
732  return unichars[unichar_id].properties.fragment;
733  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_fragment() [2/2]

const CHAR_FRAGMENT* UNICHARSET::get_fragment ( const char *const  unichar_repr) const
inline

Definition at line 779 of file unicharset.h.

779  {
780  if (unichar_repr == nullptr || unichar_repr[0] == '\0' ||
781  !ids.contains(unichar_repr, false)) {
782  return nullptr;
783  }
784  return get_fragment(unichar_to_id(unichar_repr));
785  }
bool contains(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:81
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:729

◆ get_isalpha() [1/3]

bool UNICHARSET::get_isalpha ( UNICHAR_ID  unichar_id) const
inline

Definition at line 486 of file unicharset.h.

486  {
487  if (INVALID_UNICHAR_ID == unichar_id) return false;
488  ASSERT_HOST(contains_unichar_id(unichar_id));
489  return unichars[unichar_id].properties.isalpha;
490  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_isalpha() [2/3]

bool UNICHARSET::get_isalpha ( const char *const  unichar_repr) const
inline

Definition at line 736 of file unicharset.h.

736  {
737  return get_isalpha(unichar_to_id(unichar_repr));
738  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486

◆ get_isalpha() [3/3]

bool UNICHARSET::get_isalpha ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 789 of file unicharset.h.

790  {
791  return get_isalpha(unichar_to_id(unichar_repr, length));
792  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486

◆ get_isdigit() [1/3]

bool UNICHARSET::get_isdigit ( UNICHAR_ID  unichar_id) const
inline

Definition at line 507 of file unicharset.h.

507  {
508  if (INVALID_UNICHAR_ID == unichar_id) return false;
509  ASSERT_HOST(contains_unichar_id(unichar_id));
510  return unichars[unichar_id].properties.isdigit;
511  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_isdigit() [2/3]

bool UNICHARSET::get_isdigit ( const char *const  unichar_repr) const
inline

Definition at line 751 of file unicharset.h.

751  {
752  return get_isdigit(unichar_to_id(unichar_repr));
753  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:507

◆ get_isdigit() [3/3]

bool UNICHARSET::get_isdigit ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 810 of file unicharset.h.

811  {
812  return get_isdigit(unichar_to_id(unichar_repr, length));
813  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:507

◆ get_islower() [1/3]

bool UNICHARSET::get_islower ( UNICHAR_ID  unichar_id) const
inline

Definition at line 493 of file unicharset.h.

493  {
494  if (INVALID_UNICHAR_ID == unichar_id) return false;
495  ASSERT_HOST(contains_unichar_id(unichar_id));
496  return unichars[unichar_id].properties.islower;
497  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_islower() [2/3]

bool UNICHARSET::get_islower ( const char *const  unichar_repr) const
inline

Definition at line 741 of file unicharset.h.

741  {
742  return get_islower(unichar_to_id(unichar_repr));
743  }
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:493
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209

◆ get_islower() [3/3]

bool UNICHARSET::get_islower ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 796 of file unicharset.h.

797  {
798  return get_islower(unichar_to_id(unichar_repr, length));
799  }
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:493
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209

◆ get_isngram()

bool UNICHARSET::get_isngram ( UNICHAR_ID  unichar_id) const
inline

Definition at line 521 of file unicharset.h.

521  {
522  if (INVALID_UNICHAR_ID == unichar_id) return false;
523  ASSERT_HOST(contains_unichar_id(unichar_id));
524  return unichars[unichar_id].properties.isngram;
525  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_isprivate()

bool UNICHARSET::get_isprivate ( UNICHAR_ID  unichar_id) const

Definition at line 387 of file unicharset.cpp.

387  {
388  UNICHAR uc(id_to_unichar(unichar_id), -1);
389  int uni = uc.first_uni();
390  return (uni >= 0xE000 && uni <= 0xF8FF);
391 }
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290

◆ get_ispunctuation() [1/3]

bool UNICHARSET::get_ispunctuation ( UNICHAR_ID  unichar_id) const
inline

Definition at line 514 of file unicharset.h.

514  {
515  if (INVALID_UNICHAR_ID == unichar_id) return false;
516  ASSERT_HOST(contains_unichar_id(unichar_id));
517  return unichars[unichar_id].properties.ispunctuation;
518  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_ispunctuation() [2/3]

bool UNICHARSET::get_ispunctuation ( const char *const  unichar_repr) const
inline

Definition at line 756 of file unicharset.h.

756  {
757  return get_ispunctuation(unichar_to_id(unichar_repr));
758  }
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:514
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209

◆ get_ispunctuation() [3/3]

bool UNICHARSET::get_ispunctuation ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 817 of file unicharset.h.

818  {
819  return get_ispunctuation(unichar_to_id(unichar_repr, length));
820  }
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:514
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209

◆ get_isupper() [1/3]

bool UNICHARSET::get_isupper ( UNICHAR_ID  unichar_id) const
inline

Definition at line 500 of file unicharset.h.

500  {
501  if (INVALID_UNICHAR_ID == unichar_id) return false;
502  ASSERT_HOST(contains_unichar_id(unichar_id));
503  return unichars[unichar_id].properties.isupper;
504  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_isupper() [2/3]

bool UNICHARSET::get_isupper ( const char *const  unichar_repr) const
inline

Definition at line 746 of file unicharset.h.

746  {
747  return get_isupper(unichar_to_id(unichar_repr));
748  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:500

◆ get_isupper() [3/3]

bool UNICHARSET::get_isupper ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 803 of file unicharset.h.

804  {
805  return get_isupper(unichar_to_id(unichar_repr, length));
806  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:500

◆ get_mirror()

UNICHAR_ID UNICHARSET::get_mirror ( UNICHAR_ID  unichar_id) const
inline

Definition at line 692 of file unicharset.h.

692  {
693  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
694  ASSERT_HOST(contains_unichar_id(unichar_id));
695  return unichars[unichar_id].properties.mirror;
696  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_normed_unichar()

const char* UNICHARSET::get_normed_unichar ( UNICHAR_ID  unichar_id) const
inline

Definition at line 823 of file unicharset.h.

823  {
824  if (unichar_id == UNICHAR_SPACE) return " ";
825  return unichars[unichar_id].properties.normed.string();
826  }

◆ get_other_case()

UNICHAR_ID UNICHARSET::get_other_case ( UNICHAR_ID  unichar_id) const
inline

Definition at line 678 of file unicharset.h.

678  {
679  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
680  ASSERT_HOST(contains_unichar_id(unichar_id));
681  return unichars[unichar_id].properties.other_case;
682  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_properties() [1/2]

unsigned int UNICHARSET::get_properties ( UNICHAR_ID  unichar_id) const

Definition at line 601 of file unicharset.cpp.

601  {
602  unsigned int properties = 0;
603  if (this->get_isalpha(id))
604  properties |= ISALPHA_MASK;
605  if (this->get_islower(id))
606  properties |= ISLOWER_MASK;
607  if (this->get_isupper(id))
608  properties |= ISUPPER_MASK;
609  if (this->get_isdigit(id))
610  properties |= ISDIGIT_MASK;
611  if (this->get_ispunctuation(id))
612  properties |= ISPUNCTUATION_MASK;
613  return properties;
614 }
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:493
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:514
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:507
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:500

◆ get_properties() [2/2]

unsigned int UNICHARSET::get_properties ( const char *const  unichar_repr) const
inline

Definition at line 762 of file unicharset.h.

762  {
763  return get_properties(unichar_to_id(unichar_repr));
764  }
unsigned int get_properties(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:601
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209

◆ get_script() [1/3]

int UNICHARSET::get_script ( UNICHAR_ID  unichar_id) const
inline

Definition at line 658 of file unicharset.h.

658  {
659  if (INVALID_UNICHAR_ID == unichar_id) return null_sid_;
660  ASSERT_HOST(contains_unichar_id(unichar_id));
661  return unichars[unichar_id].properties.script_id;
662  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_script() [2/3]

int UNICHARSET::get_script ( const char *const  unichar_repr) const
inline

Definition at line 773 of file unicharset.h.

773  {
774  return get_script(unichar_to_id(unichar_repr));
775  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:658

◆ get_script() [3/3]

int UNICHARSET::get_script ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 838 of file unicharset.h.

839  {
840  return get_script(unichar_to_id(unichar_repr, length));
841  }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:658

◆ get_script_from_script_id()

const char* UNICHARSET::get_script_from_script_id ( int  id) const
inline

Definition at line 849 of file unicharset.h.

849  {
850  if (id >= script_table_size_used || id < 0)
851  return null_script;
852  return script_table[id];
853  }

◆ get_script_id_from_name()

int UNICHARSET::get_script_id_from_name ( const char *  script_name) const

Definition at line 1109 of file unicharset.cpp.

1109  {
1110  for (int i = 0; i < script_table_size_used; ++i) {
1111  if (strcmp(script_name, script_table[i]) == 0)
1112  return i;
1113  }
1114  return 0; // 0 is always the null_script
1115 }

◆ get_script_table_size()

int UNICHARSET::get_script_table_size ( ) const
inline

Definition at line 844 of file unicharset.h.

844  {
845  return script_table_size_used;
846  }

◆ get_top_bottom()

void UNICHARSET::get_top_bottom ( UNICHAR_ID  unichar_id,
int *  min_bottom,
int *  max_bottom,
int *  min_top,
int *  max_top 
) const
inline

Definition at line 563 of file unicharset.h.

565  {
566  if (INVALID_UNICHAR_ID == unichar_id) {
567  *min_bottom = *min_top = 0;
568  *max_bottom = *max_top = 256; // kBlnCellHeight
569  return;
570  }
571  ASSERT_HOST(contains_unichar_id(unichar_id));
572  *min_bottom = unichars[unichar_id].properties.min_bottom;
573  *max_bottom = unichars[unichar_id].properties.max_bottom;
574  *min_top = unichars[unichar_id].properties.min_top;
575  *max_top = unichars[unichar_id].properties.max_top;
576  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ get_width_stats()

void UNICHARSET::get_width_stats ( UNICHAR_ID  unichar_id,
float *  width,
float *  width_sd 
) const
inline

Definition at line 591 of file unicharset.h.

592  {
593  if (INVALID_UNICHAR_ID == unichar_id) {
594  *width = 0.0f;
595  *width_sd = 0.0f;;
596  return;
597  }
598  ASSERT_HOST(contains_unichar_id(unichar_id));
599  *width = unichars[unichar_id].properties.width;
600  *width_sd = unichars[unichar_id].properties.width_sd;
601  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ greek_sid()

int UNICHARSET::greek_sid ( ) const
inline

Definition at line 882 of file unicharset.h.

882 { return greek_sid_; }

◆ han_sid()

int UNICHARSET::han_sid ( ) const
inline

Definition at line 883 of file unicharset.h.

883 { return han_sid_; }

◆ hangul_sid()

int UNICHARSET::hangul_sid ( ) const
inline

Definition at line 887 of file unicharset.h.

887 { return hangul_sid_; }

◆ has_special_codes()

bool UNICHARSET::has_special_codes ( ) const
inline

Definition at line 717 of file unicharset.h.

717  {
718  return get_fragment(UNICHAR_BROKEN) != nullptr &&
721  }
static TESS_API const char * kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT]
Definition: unicharset.h:154
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:729
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290

◆ hiragana_sid()

int UNICHARSET::hiragana_sid ( ) const
inline

Definition at line 884 of file unicharset.h.

884 { return hiragana_sid_; }

◆ id_to_unichar()

const char * UNICHARSET::id_to_unichar ( UNICHAR_ID  id) const

Definition at line 290 of file unicharset.cpp.

290  {
291  if (id == INVALID_UNICHAR_ID) {
292  return INVALID_UNICHAR;
293  }
294  ASSERT_HOST(id < this->size());
295  return unichars[id].representation;
296 }
int size() const
Definition: unicharset.h:336
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ id_to_unichar_ext()

const char * UNICHARSET::id_to_unichar_ext ( UNICHAR_ID  id) const

Definition at line 298 of file unicharset.cpp.

298  {
299  if (id == INVALID_UNICHAR_ID) {
300  return INVALID_UNICHAR;
301  }
302  ASSERT_HOST(id < this->size());
303  // Resolve from the kCustomLigatures table if this is a private encoding.
304  if (get_isprivate(id)) {
305  const char* ch = id_to_unichar(id);
306  for (int i = 0; kCustomLigatures[i][0] != nullptr; ++i) {
307  if (!strcmp(ch, kCustomLigatures[i][1])) {
308  return kCustomLigatures[i][0];
309  }
310  }
311  }
312  // Otherwise return the stored representation.
313  return unichars[id].representation;
314 }
static TESS_API const char * kCustomLigatures[][2]
Definition: unicharset.h:151
int size() const
Definition: unicharset.h:336
bool get_isprivate(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:387
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ is_null_script()

bool UNICHARSET::is_null_script ( const char *  script) const
inline

Definition at line 863 of file unicharset.h.

863  {
864  return script == null_script;
865  }

◆ IsSpaceDelimited()

bool UNICHARSET::IsSpaceDelimited ( UNICHAR_ID  unichar_id) const
inline

Definition at line 647 of file unicharset.h.

647  {
648  if (INVALID_UNICHAR_ID == unichar_id) return true;
649  int script_id = get_script(unichar_id);
650  return script_id != han_sid_ && script_id != thai_sid_ &&
651  script_id != hangul_sid_ && script_id != hiragana_sid_ &&
652  script_id != katakana_sid_;
653  }
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:658

◆ katakana_sid()

int UNICHARSET::katakana_sid ( ) const
inline

Definition at line 885 of file unicharset.h.

885 { return katakana_sid_; }

◆ latin_sid()

int UNICHARSET::latin_sid ( ) const
inline

Definition at line 880 of file unicharset.h.

880 { return latin_sid_; }

◆ load_from_file() [1/5]

bool UNICHARSET::load_from_file ( const char *const  filename,
bool  skip_fragments 
)
inline

Definition at line 383 of file unicharset.h.

383  {
384  FILE* file = fopen(filename, "rb");
385  if (file == nullptr) return false;
386  bool result = load_from_file(file, skip_fragments);
387  fclose(file);
388  return result;
389  }
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:383

◆ load_from_file() [2/5]

bool UNICHARSET::load_from_file ( const char *const  filename)
inline

Definition at line 391 of file unicharset.h.

391  {
392  return load_from_file(filename, false);
393  }
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:383

◆ load_from_file() [3/5]

bool UNICHARSET::load_from_file ( FILE *  file,
bool  skip_fragments 
)

Definition at line 774 of file unicharset.cpp.

774  {
775  LocalFilePointer lfp(file);
778  bool success = load_via_fgets(fgets_cb, skip_fragments);
779  delete fgets_cb;
780  return success;
781 }
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
char * fgets(char *dst, int size)
Definition: unicharset.cpp:767

◆ load_from_file() [4/5]

bool UNICHARSET::load_from_file ( FILE *  file)
inline

Definition at line 398 of file unicharset.h.

398 { return load_from_file(file, false); }
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:383

◆ load_from_file() [5/5]

bool UNICHARSET::load_from_file ( tesseract::TFile file,
bool  skip_fragments 
)

Definition at line 783 of file unicharset.cpp.

783  {
786  bool success = load_via_fgets(fgets_cb, skip_fragments);
787  delete fgets_cb;
788  return success;
789 }
char * FGets(char *buffer, int buffer_size)
Definition: serialis.cpp:248
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116

◆ load_from_inmemory_file() [1/2]

bool UNICHARSET::load_from_inmemory_file ( const char *const  memory,
int  mem_size,
bool  skip_fragments 
)

Definition at line 754 of file unicharset.cpp.

755  {
756  InMemoryFilePointer mem_fp(memory, mem_size);
759  bool success = load_via_fgets(fgets_cb, skip_fragments);
760  delete fgets_cb;
761  return success;
762 }
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
char * fgets(char *orig_dst, int size)
Definition: unicharset.cpp:732

◆ load_from_inmemory_file() [2/2]

bool UNICHARSET::load_from_inmemory_file ( const char *const  memory,
int  mem_size 
)
inline

Definition at line 376 of file unicharset.h.

376  {
377  return load_from_inmemory_file(memory, mem_size, false);
378  }
bool load_from_inmemory_file(const char *const memory, int mem_size, bool skip_fragments)
Definition: unicharset.cpp:754

◆ major_right_to_left()

bool UNICHARSET::major_right_to_left ( ) const

Definition at line 962 of file unicharset.cpp.

962  {
963  int ltr_count = 0;
964  int rtl_count = 0;
965  for (int id = 0; id < size_used; ++id) {
966  int dir = get_direction(id);
967  if (dir == UNICHARSET::U_LEFT_TO_RIGHT) ltr_count++;
968  if (dir == UNICHARSET::U_RIGHT_TO_LEFT ||
970  dir == UNICHARSET::U_ARABIC_NUMBER) rtl_count++;
971  }
972  return rtl_count > ltr_count;
973 }
Direction get_direction(UNICHAR_ID unichar_id) const
Definition: unicharset.h:685

◆ normed_ids()

const GenericVector<UNICHAR_ID>& UNICHARSET::normed_ids ( UNICHAR_ID  unichar_id) const
inline

Definition at line 830 of file unicharset.h.

830  {
831  return unichars[unichar_id].properties.normed_ids;
832  }

◆ null_sid()

int UNICHARSET::null_sid ( ) const
inline

Definition at line 878 of file unicharset.h.

878 { return null_sid_; }

◆ PartialSetPropertiesFromOther()

void UNICHARSET::PartialSetPropertiesFromOther ( int  start_index,
const UNICHARSET src 
)

Definition at line 404 of file unicharset.cpp.

405  {
406  for (int ch = start_index; ch < size_used; ++ch) {
407  const char* utf8 = id_to_unichar(ch);
408  UNICHAR_PROPERTIES properties;
409  if (src.GetStrProperties(utf8, &properties)) {
410  // Setup the script_id, other_case, and mirror properly.
411  const char* script = src.get_script_from_script_id(properties.script_id);
412  properties.script_id = add_script(script);
413  const char* other_case = src.id_to_unichar(properties.other_case);
414  if (contains_unichar(other_case)) {
415  properties.other_case = unichar_to_id(other_case);
416  } else {
417  properties.other_case = ch;
418  }
419  const char* mirror_str = src.id_to_unichar(properties.mirror);
420  if (contains_unichar(mirror_str)) {
421  properties.mirror = unichar_to_id(mirror_str);
422  } else {
423  properties.mirror = ch;
424  }
425  unichars[ch].properties.CopyFrom(properties);
426  set_normed_ids(ch);
427  }
428  }
429 }
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:849
void set_normed_ids(UNICHAR_ID unichar_id)
Definition: unicharset.cpp:372
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:670
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
int add_script(const char *script)

◆ post_load_setup()

void UNICHARSET::post_load_setup ( )

Definition at line 896 of file unicharset.cpp.

896  {
897  // Number of alpha chars with the case property minus those without,
898  // in order to determine that half the alpha chars have case.
899  int net_case_alphas = 0;
900  int x_height_alphas = 0;
901  int cap_height_alphas = 0;
902  top_bottom_set_ = false;
903  for (UNICHAR_ID id = 0; id < size_used; ++id) {
904  int min_bottom = 0;
905  int max_bottom = UINT8_MAX;
906  int min_top = 0;
907  int max_top = UINT8_MAX;
908  get_top_bottom(id, &min_bottom, &max_bottom, &min_top, &max_top);
909  if (min_top > 0)
910  top_bottom_set_ = true;
911  if (get_isalpha(id)) {
912  if (get_islower(id) || get_isupper(id))
913  ++net_case_alphas;
914  else
915  --net_case_alphas;
916  if (min_top < kMeanlineThreshold && max_top < kMeanlineThreshold)
917  ++x_height_alphas;
918  else if (min_top > kMeanlineThreshold && max_top > kMeanlineThreshold)
919  ++cap_height_alphas;
920  }
921  set_normed_ids(id);
922  }
923 
924  script_has_upper_lower_ = net_case_alphas > 0;
925  script_has_xheight_ = script_has_upper_lower_ ||
926  (x_height_alphas > cap_height_alphas * kMinXHeightFraction &&
927  cap_height_alphas > x_height_alphas * kMinCapHeightFraction);
928 
929  null_sid_ = get_script_id_from_name(null_script);
930  ASSERT_HOST(null_sid_ == 0);
931  common_sid_ = get_script_id_from_name("Common");
932  latin_sid_ = get_script_id_from_name("Latin");
933  cyrillic_sid_ = get_script_id_from_name("Cyrillic");
934  greek_sid_ = get_script_id_from_name("Greek");
935  han_sid_ = get_script_id_from_name("Han");
936  hiragana_sid_ = get_script_id_from_name("Hiragana");
937  katakana_sid_ = get_script_id_from_name("Katakana");
938  thai_sid_ = get_script_id_from_name("Thai");
939  hangul_sid_ = get_script_id_from_name("Hangul");
940 
941  // Compute default script. Use the highest-counting alpha script, that is
942  // not the common script, as that still contains some "alphas".
943  int* script_counts = new int[script_table_size_used];
944  memset(script_counts, 0, sizeof(*script_counts) * script_table_size_used);
945  for (int id = 0; id < size_used; ++id) {
946  if (get_isalpha(id)) {
947  ++script_counts[get_script(id)];
948  }
949  }
950  default_sid_ = 0;
951  for (int s = 1; s < script_table_size_used; ++s) {
952  if (script_counts[s] > script_counts[default_sid_] && s != common_sid_)
953  default_sid_ = s;
954  }
955  delete [] script_counts;
956 }
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:493
int UNICHAR_ID
Definition: unichar.h:35
void set_normed_ids(UNICHAR_ID unichar_id)
Definition: unicharset.cpp:372
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486
int get_script_id_from_name(const char *script_name) const
const double kMinXHeightFraction
Definition: unicharset.cpp:58
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:563
const double kMinCapHeightFraction
Definition: unicharset.cpp:59
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:500
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:658
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ PropertiesIncomplete()

bool UNICHARSET::PropertiesIncomplete ( UNICHAR_ID  unichar_id) const
inline

Definition at line 641 of file unicharset.h.

641  {
642  return unichars[unichar_id].properties.AnyRangeEmpty();
643  }

◆ reserve()

void UNICHARSET::reserve ( int  unichars_number)

Definition at line 194 of file unicharset.cpp.

194  {
195  if (unichars_number > size_reserved) {
196  UNICHAR_SLOT* unichars_new = new UNICHAR_SLOT[unichars_number];
197  for (int i = 0; i < size_used; ++i)
198  unichars_new[i] = unichars[i];
199  for (int j = size_used; j < unichars_number; ++j) {
200  unichars_new[j].properties.script_id = add_script(null_script);
201  }
202  delete[] unichars;
203  unichars = unichars_new;
204  size_reserved = unichars_number;
205  }
206 }
int add_script(const char *script)

◆ save_to_file() [1/3]

bool UNICHARSET::save_to_file ( const char *const  filename) const
inline

Definition at line 345 of file unicharset.h.

345  {
346  FILE* file = fopen(filename, "w+b");
347  if (file == nullptr) return false;
348  bool result = save_to_file(file);
349  fclose(file);
350  return result;
351  }
bool save_to_file(const char *const filename) const
Definition: unicharset.h:345

◆ save_to_file() [2/3]

bool UNICHARSET::save_to_file ( FILE *  file) const
inline

Definition at line 355 of file unicharset.h.

355  {
356  STRING str;
357  return save_to_string(&str) &&
358  tesseract::Serialize(file, &str[0], str.length());
359  }
bool Serialize(FILE *fp, const char *data, size_t n)
Definition: serialis.cpp:59
Definition: strngs.h:45
bool save_to_string(STRING *str) const
Definition: unicharset.cpp:691
int32_t length() const
Definition: strngs.cpp:191

◆ save_to_file() [3/3]

bool UNICHARSET::save_to_file ( tesseract::TFile file) const
inline

Definition at line 361 of file unicharset.h.

361  {
362  STRING str;
363  return save_to_string(&str) && file->Serialize(&str[0], str.length());
364  }
bool Serialize(const char *data, size_t count=1)
Definition: serialis.cpp:147
Definition: strngs.h:45
bool save_to_string(STRING *str) const
Definition: unicharset.cpp:691
int32_t length() const
Definition: strngs.cpp:191

◆ save_to_string()

bool UNICHARSET::save_to_string ( STRING str) const

Definition at line 691 of file unicharset.cpp.

691  {
692  const int kFileBufSize = 1024;
693  char buffer[kFileBufSize + 1];
694  snprintf(buffer, kFileBufSize, "%d\n", this->size());
695  *str = buffer;
696  for (UNICHAR_ID id = 0; id < this->size(); ++id) {
697  int min_bottom, max_bottom, min_top, max_top;
698  get_top_bottom(id, &min_bottom, &max_bottom, &min_top, &max_top);
699  float width, width_sd;
700  get_width_stats(id, &width, &width_sd);
701  float bearing, bearing_sd;
702  get_bearing_stats(id, &bearing, &bearing_sd);
703  float advance, advance_sd;
704  get_advance_stats(id, &advance, &advance_sd);
705  unsigned int properties = this->get_properties(id);
706  if (strcmp(this->id_to_unichar(id), " ") == 0) {
707  snprintf(buffer, kFileBufSize, "%s %x %s %d\n", "NULL", properties,
708  this->get_script_from_script_id(this->get_script(id)),
709  this->get_other_case(id));
710  } else {
711  snprintf(buffer, kFileBufSize,
712  "%s %x %d,%d,%d,%d,%g,%g,%g,%g,%g,%g %s %d %d %d %s\t# %s\n",
713  this->id_to_unichar(id), properties,
714  min_bottom, max_bottom, min_top, max_top, width, width_sd,
715  bearing, bearing_sd, advance, advance_sd,
716  this->get_script_from_script_id(this->get_script(id)),
717  this->get_other_case(id), this->get_direction(id),
718  this->get_mirror(id), this->get_normed_unichar(id),
719  this->debug_str(id).string());
720  }
721  *str += buffer;
722  }
723  return true;
724 }
int UNICHAR_ID
Definition: unichar.h:35
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
Definition: unicharset.h:823
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:849
unsigned int get_properties(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:601
int size() const
Definition: unicharset.h:336
Direction get_direction(UNICHAR_ID unichar_id) const
Definition: unicharset.h:685
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:563
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:342
void get_bearing_stats(UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
Definition: unicharset.h:608
void get_width_stats(UNICHAR_ID unichar_id, float *width, float *width_sd) const
Definition: unicharset.h:591
UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const
Definition: unicharset.h:692
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
void get_advance_stats(UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
Definition: unicharset.h:625
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
Definition: unicharset.h:678
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:658

◆ script_has_upper_lower()

bool UNICHARSET::script_has_upper_lower ( ) const
inline

Definition at line 891 of file unicharset.h.

891  {
892  return script_has_upper_lower_;
893  }

◆ script_has_xheight()

bool UNICHARSET::script_has_xheight ( ) const
inline

Definition at line 898 of file unicharset.h.

898  {
899  return script_has_xheight_;
900  }

◆ set_advance_stats()

void UNICHARSET::set_advance_stats ( UNICHAR_ID  unichar_id,
float  advance,
float  advance_sd 
)
inline

Definition at line 635 of file unicharset.h.

636  {
637  unichars[unichar_id].properties.advance = advance;
638  unichars[unichar_id].properties.advance_sd = advance_sd;
639  }

◆ set_bearing_stats()

void UNICHARSET::set_bearing_stats ( UNICHAR_ID  unichar_id,
float  bearing,
float  bearing_sd 
)
inline

Definition at line 618 of file unicharset.h.

619  {
620  unichars[unichar_id].properties.bearing = bearing;
621  unichars[unichar_id].properties.bearing_sd = bearing_sd;
622  }

◆ set_black_and_whitelist()

void UNICHARSET::set_black_and_whitelist ( const char *  blacklist,
const char *  whitelist,
const char *  unblacklist 
)

Definition at line 979 of file unicharset.cpp.

981  {
982  bool def_enabled = whitelist == nullptr || whitelist[0] == '\0';
983  // Set everything to default
984  for (int ch = 0; ch < size_used; ++ch)
985  unichars[ch].properties.enabled = def_enabled;
986  if (!def_enabled) {
987  // Enable the whitelist.
988  GenericVector<UNICHAR_ID> encoding;
989  encode_string(whitelist, false, &encoding, nullptr, nullptr);
990  for (int i = 0; i < encoding.size(); ++i) {
991  if (encoding[i] != INVALID_UNICHAR_ID)
992  unichars[encoding[i]].properties.enabled = true;
993  }
994  }
995  if (blacklist != nullptr && blacklist[0] != '\0') {
996  // Disable the blacklist.
997  GenericVector<UNICHAR_ID> encoding;
998  encode_string(blacklist, false, &encoding, nullptr, nullptr);
999  for (int i = 0; i < encoding.size(); ++i) {
1000  if (encoding[i] != INVALID_UNICHAR_ID)
1001  unichars[encoding[i]].properties.enabled = false;
1002  }
1003  }
1004  if (unblacklist != nullptr && unblacklist[0] != '\0') {
1005  // Re-enable the unblacklist.
1006  GenericVector<UNICHAR_ID> encoding;
1007  encode_string(unblacklist, false, &encoding, nullptr, nullptr);
1008  for (int i = 0; i < encoding.size(); ++i) {
1009  if (encoding[i] != INVALID_UNICHAR_ID)
1010  unichars[encoding[i]].properties.enabled = true;
1011  }
1012  }
1013 }
int size() const
Definition: genericvector.h:71
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:258

◆ set_direction()

void UNICHARSET::set_direction ( UNICHAR_ID  unichar_id,
UNICHARSET::Direction  value 
)
inline

Definition at line 467 of file unicharset.h.

467  {
468  unichars[unichar_id].properties.direction = value;
469  }

◆ set_isalpha()

void UNICHARSET::set_isalpha ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 426 of file unicharset.h.

426  {
427  unichars[unichar_id].properties.isalpha = value;
428  }

◆ set_isdigit()

void UNICHARSET::set_isdigit ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 441 of file unicharset.h.

441  {
442  unichars[unichar_id].properties.isdigit = value;
443  }

◆ set_islower()

void UNICHARSET::set_islower ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 431 of file unicharset.h.

431  {
432  unichars[unichar_id].properties.islower = value;
433  }

◆ set_isngram()

void UNICHARSET::set_isngram ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 451 of file unicharset.h.

451  {
452  unichars[unichar_id].properties.isngram = value;
453  }

◆ set_ispunctuation()

void UNICHARSET::set_ispunctuation ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 446 of file unicharset.h.

446  {
447  unichars[unichar_id].properties.ispunctuation = value;
448  }

◆ set_isupper()

void UNICHARSET::set_isupper ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 436 of file unicharset.h.

436  {
437  unichars[unichar_id].properties.isupper = value;
438  }

◆ set_mirror()

void UNICHARSET::set_mirror ( UNICHAR_ID  unichar_id,
UNICHAR_ID  mirror 
)
inline

Definition at line 472 of file unicharset.h.

472  {
473  unichars[unichar_id].properties.mirror = mirror;
474  }

◆ set_normed()

void UNICHARSET::set_normed ( UNICHAR_ID  unichar_id,
const char *  normed 
)
inline

Definition at line 477 of file unicharset.h.

477  {
478  unichars[unichar_id].properties.normed = normed;
479  unichars[unichar_id].properties.normed_ids.truncate(0);
480  }

◆ set_normed_ids()

void UNICHARSET::set_normed_ids ( UNICHAR_ID  unichar_id)

Definition at line 372 of file unicharset.cpp.

372  {
373  unichars[unichar_id].properties.normed_ids.truncate(0);
374  if (unichar_id == UNICHAR_SPACE && id_to_unichar(unichar_id)[0] == ' ') {
375  unichars[unichar_id].properties.normed_ids.push_back(UNICHAR_SPACE);
376  } else if (!encode_string(unichars[unichar_id].properties.normed.string(),
377  true, &unichars[unichar_id].properties.normed_ids,
378  nullptr, nullptr)) {
379  unichars[unichar_id].properties.normed_ids.truncate(0);
380  unichars[unichar_id].properties.normed_ids.push_back(unichar_id);
381  }
382 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:258
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290

◆ set_other_case()

void UNICHARSET::set_other_case ( UNICHAR_ID  unichar_id,
UNICHAR_ID  other_case 
)
inline

Definition at line 462 of file unicharset.h.

462  {
463  unichars[unichar_id].properties.other_case = other_case;
464  }

◆ set_ranges_empty()

void UNICHARSET::set_ranges_empty ( )

Definition at line 395 of file unicharset.cpp.

395  {
396  for (int id = 0; id < size_used; ++id) {
397  unichars[id].properties.SetRangesEmpty();
398  }
399 }

◆ set_script()

void UNICHARSET::set_script ( UNICHAR_ID  unichar_id,
const char *  value 
)
inline

Definition at line 457 of file unicharset.h.

457  {
458  unichars[unichar_id].properties.script_id = add_script(value);
459  }
int add_script(const char *script)

◆ set_top_bottom()

void UNICHARSET::set_top_bottom ( UNICHAR_ID  unichar_id,
int  min_bottom,
int  max_bottom,
int  min_top,
int  max_top 
)
inline

Definition at line 577 of file unicharset.h.

579  {
580  unichars[unichar_id].properties.min_bottom =
581  ClipToRange<int>(min_bottom, 0, UINT8_MAX);
582  unichars[unichar_id].properties.max_bottom =
583  ClipToRange<int>(max_bottom, 0, UINT8_MAX);
584  unichars[unichar_id].properties.min_top =
585  ClipToRange<int>(min_top, 0, UINT8_MAX);
586  unichars[unichar_id].properties.max_top =
587  ClipToRange<int>(max_top, 0, UINT8_MAX);
588  }

◆ set_width_stats()

void UNICHARSET::set_width_stats ( UNICHAR_ID  unichar_id,
float  width,
float  width_sd 
)
inline

Definition at line 602 of file unicharset.h.

602  {
603  unichars[unichar_id].properties.width = width;
604  unichars[unichar_id].properties.width_sd = width_sd;
605  }

◆ SetPropertiesFromOther()

void UNICHARSET::SetPropertiesFromOther ( const UNICHARSET src)
inline

Definition at line 540 of file unicharset.h.

540  {
542  }
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
Definition: unicharset.cpp:404

◆ size()

int UNICHARSET::size ( ) const
inline

Definition at line 336 of file unicharset.h.

336  {
337  return size_used;
338  }

◆ SizesDistinct()

bool UNICHARSET::SizesDistinct ( UNICHAR_ID  id1,
UNICHAR_ID  id2 
) const

Definition at line 485 of file unicharset.cpp.

485  {
486  int overlap = std::min(unichars[id1].properties.max_top,
487  unichars[id2].properties.max_top) -
488  std::max(unichars[id1].properties.min_top,
489  unichars[id2].properties.min_top);
490  return overlap <= 0;
491 }

◆ step()

int UNICHARSET::step ( const char *  str) const

Definition at line 232 of file unicharset.cpp.

232  {
233  GenericVector<UNICHAR_ID> encoding;
234  GenericVector<char> lengths;
235  encode_string(str, true, &encoding, &lengths, nullptr);
236  if (encoding.empty() || encoding[0] == INVALID_UNICHAR_ID) return 0;
237  return lengths[0];
238 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:258
bool empty() const
Definition: genericvector.h:90

◆ thai_sid()

int UNICHARSET::thai_sid ( ) const
inline

Definition at line 886 of file unicharset.h.

886 { return thai_sid_; }

◆ to_lower()

UNICHAR_ID UNICHARSET::to_lower ( UNICHAR_ID  unichar_id) const
inline

Definition at line 699 of file unicharset.h.

699  {
700  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
701  ASSERT_HOST(contains_unichar_id(unichar_id));
702  if (unichars[unichar_id].properties.islower) return unichar_id;
703  return unichars[unichar_id].properties.other_case;
704  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ to_upper()

UNICHAR_ID UNICHARSET::to_upper ( UNICHAR_ID  unichar_id) const
inline

Definition at line 707 of file unicharset.h.

707  {
708  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
709  ASSERT_HOST(contains_unichar_id(unichar_id));
710  if (unichars[unichar_id].properties.isupper) return unichar_id;
711  return unichars[unichar_id].properties.other_case;
712  }
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ top_bottom_useful()

bool UNICHARSET::top_bottom_useful ( ) const
inline

Definition at line 532 of file unicharset.h.

532  {
533  return top_bottom_set_;
534  }

◆ unichar_insert() [1/2]

void UNICHARSET::unichar_insert ( const char *const  unichar_repr,
OldUncleanUnichars  old_style 
)

Definition at line 625 of file unicharset.cpp.

626  {
627  if (old_style == OldUncleanUnichars::kTrue) old_style_included_ = true;
628  std::string cleaned =
629  old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
630  if (!cleaned.empty() && !ids.contains(cleaned.data(), cleaned.size())) {
631  const char* str = cleaned.c_str();
632  GenericVector<int> encoding;
633  if (!old_style_included_ &&
634  encode_string(str, true, &encoding, nullptr, nullptr))
635  return;
636  if (size_used == size_reserved) {
637  if (size_used == 0)
638  reserve(8);
639  else
640  reserve(2 * size_used);
641  }
642  int index = 0;
643  do {
644  if (index >= UNICHAR_LEN) {
645  fprintf(stderr, "Utf8 buffer too big, size>%d for %s\n", UNICHAR_LEN,
646  unichar_repr);
647  return;
648  }
649  unichars[size_used].representation[index++] = *str++;
650  } while (*str != '\0');
651  unichars[size_used].representation[index] = '\0';
652  this->set_script(size_used, null_script);
653  // If the given unichar_repr represents a fragmented character, set
654  // fragment property to a pointer to CHAR_FRAGMENT class instance with
655  // information parsed from the unichar representation. Use the script
656  // of the base unichar for the fragmented character if possible.
657  CHAR_FRAGMENT* frag =
658  CHAR_FRAGMENT::parse_from_string(unichars[size_used].representation);
659  this->unichars[size_used].properties.fragment = frag;
660  if (frag != nullptr && this->contains_unichar(frag->get_unichar())) {
661  this->unichars[size_used].properties.script_id =
662  this->get_script(frag->get_unichar());
663  }
664  this->unichars[size_used].properties.enabled = true;
665  ids.insert(unichars[size_used].representation, size_used);
666  ++size_used;
667  }
668 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:258
bool contains(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:81
#define UNICHAR_LEN
Definition: unichar.h:31
const char * get_unichar() const
Definition: unicharset.h:71
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:670
void insert(const char *const unichar_repr, UNICHAR_ID id)
Definition: unicharmap.cpp:58
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241
void reserve(int unichars_number)
Definition: unicharset.cpp:194
void set_script(UNICHAR_ID unichar_id, const char *value)
Definition: unicharset.h:457
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:658
static CHAR_FRAGMENT * parse_from_string(const char *str)

◆ unichar_insert() [2/2]

void UNICHARSET::unichar_insert ( const char *const  unichar_repr)
inline

Definition at line 259 of file unicharset.h.

259  {
261  }
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
Definition: unicharset.cpp:625

◆ unichar_insert_backwards_compatible()

void UNICHARSET::unichar_insert_backwards_compatible ( const char *const  unichar_repr)
inline

Definition at line 264 of file unicharset.h.

264  {
265  std::string cleaned = CleanupString(unichar_repr);
266  if (cleaned != unichar_repr) {
268  } else {
269  int old_size = size();
271  if (size() == old_size) {
273  }
274  }
275  }
int size() const
Definition: unicharset.h:336
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
Definition: unicharset.cpp:625
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241

◆ unichar_to_id() [1/2]

UNICHAR_ID UNICHARSET::unichar_to_id ( const char *const  unichar_repr) const

Definition at line 209 of file unicharset.cpp.

209  {
210  std::string cleaned =
211  old_style_included_ ? unichar_repr : CleanupString(unichar_repr);
212  return ids.contains(cleaned.data(), cleaned.size())
213  ? ids.unichar_to_id(cleaned.data(), cleaned.size())
214  : INVALID_UNICHAR_ID;
215 }
UNICHAR_ID unichar_to_id(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:36
bool contains(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:81
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241

◆ unichar_to_id() [2/2]

UNICHAR_ID UNICHARSET::unichar_to_id ( const char *const  unichar_repr,
int  length 
) const

Definition at line 217 of file unicharset.cpp.

218  {
219  assert(length > 0 && length <= UNICHAR_LEN);
220  std::string cleaned(unichar_repr, length);
221  if (!old_style_included_) cleaned = CleanupString(unichar_repr, length);
222  return ids.contains(cleaned.data(), cleaned.size())
223  ? ids.unichar_to_id(cleaned.data(), cleaned.size())
224  : INVALID_UNICHAR_ID;
225 }
UNICHAR_ID unichar_to_id(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:36
bool contains(const char *const unichar_repr, int length) const
Definition: unicharmap.cpp:81
#define UNICHAR_LEN
Definition: unichar.h:31
static std::string CleanupString(const char *utf8_str)
Definition: unicharset.h:241

Member Data Documentation

◆ kCustomLigatures

const char * UNICHARSET::kCustomLigatures
static
Initial value:
= {
{"ct", "\uE003"},
{"ſh", "\uE006"},
{"ſi", "\uE007"},
{"ſl", "\uE008"},
{"ſſ", "\uE009"},
{nullptr, nullptr}
}

Definition at line 151 of file unicharset.h.

◆ kSpecialUnicharCodes

const char * UNICHARSET::kSpecialUnicharCodes
static
Initial value:
= {
" ",
"Joined",
"|Broken|0|1"
}

Definition at line 154 of file unicharset.h.


The documentation for this class was generated from the following files: