36 #ifndef LANGUAGE_BASE_H 37 #define LANGUAGE_BASE_H 40 #include <unordered_map> 42 #include "misc_log_ex.h" 57 inline std::string
utf8prefix(
const std::string &
s,
size_t count)
59 std::string prefix =
"";
60 const char *ptr =
s.c_str();
61 while (count-- && *ptr)
64 while (((*ptr) & 0xc0) == 0x80)
83 std::unordered_map<std::string, uint32_t>
word_map;
93 std::vector<std::string>::const_iterator it;
95 throw std::runtime_error(
"Wrong word list length for " +
language_name);
104 throw std::runtime_error(
"Too short word in " +
language_name +
" word list: " + *it);
118 MWARNING(
"Duplicate prefix in " <<
language_name <<
" word list: " << trimmed);
120 throw std::runtime_error(
"Duplicate prefix in " +
language_name +
" word list: " + trimmed);
std::string language_name
Definition: language_base.h:85
std::string utf8prefix(const std::string &s, size_t count)
Returns a string made of (at most) the first count characters in s. Assumes well formedness. No check is made for this.
Definition: language_base.h:57
A base language class which all languages have to inherit from for Polymorphism.
Definition: language_base.h:75
Definition: language_base.h:79
flags
Definition: http_parser_merged.h:136
Definition: language_base.h:80
uint32_t get_unique_prefix_length() const
Returns the number of unique starting characters to be used for matching.
Definition: language_base.h:171
Mnemonic language related namespace.
const std::vector< std::string > & get_word_list() const
Returns a pointer to the word list.
Definition: language_base.h:139
virtual ~Base()
Definition: language_base.h:132
std::unordered_map< std::string, uint32_t > word_map
Definition: language_base.h:83
const std::vector< std::string > word_list
Definition: language_base.h:82
void populate_maps(uint32_t flags=0)
Populates the word maps after the list is ready.
Definition: language_base.h:90
const std::unordered_map< std::string, uint32_t > & get_word_map() const
Returns a pointer to the word map.
Definition: language_base.h:147
Base(const char *language_name, const std::vector< std::string > &words, uint32_t prefix_length)
Definition: language_base.h:126
const std::string & get_language_name() const
Returns the name of the language.
Definition: language_base.h:163
std::unordered_map< std::string, uint32_t > trimmed_word_map
Definition: language_base.h:84
const std::unordered_map< std::string, uint32_t > & get_trimmed_word_map() const
Returns a pointer to the trimmed word map.
Definition: language_base.h:155
#define s(x, c)
Definition: aesb.c:46
uint32_t unique_prefix_length
Definition: language_base.h:86