35 #ifndef LANGUAGE_BASE_H
36 #define LANGUAGE_BASE_H
39 #include <unordered_map>
41 #include <boost/algorithm/string.hpp>
42 #include "misc_log_ex.h"
63 size_t avail =
s.size();
64 const char *ptr =
s.data();
65 while (
count-- && avail--)
68 while (avail && ((*ptr) & 0xc0) == 0x80)
81 const epee::wipeable_string sc =
tools::utf8canonical(
s, [](wint_t c) -> wint_t {
return std::towlower(c); });
82 return epee::fnv::FNV1a(sc.data(), sc.size());
88 bool operator()(
const epee::wipeable_string &s0,
const epee::wipeable_string &s1)
const
90 const epee::wipeable_string s0c =
tools::utf8canonical(s0, [](wint_t c) -> wint_t {
return std::towlower(c); });
91 const epee::wipeable_string s1c =
tools::utf8canonical(s1, [](wint_t c) -> wint_t {
return std::towlower(c); });
112 std::unordered_map<epee::wipeable_string, uint32_t, WordHash, WordEqual>
word_map;
123 std::vector<std::string>::const_iterator it;
125 throw std::runtime_error(
"Wrong word list length for " +
language_name);
134 throw std::runtime_error(
"Too short word in " +
language_name +
" word list: " + *it);
136 epee::wipeable_string trimmed;
148 MWARNING(
"Duplicate prefix in " <<
language_name <<
" word list: " << std::string(trimmed.data(), trimmed.size()));
150 throw std::runtime_error(
"Duplicate prefix in " +
language_name +
" word list: " + std::string(trimmed.data(), trimmed.size()));
169 for (
size_t i = 0; i <
NWORDS; ++i)
184 const std::unordered_map<epee::wipeable_string, uint32_t, WordHash, WordEqual>&
get_word_map()
const
#define s(x, c)
Definition: aesb.c:47
A base language class which all languages have to inherit from for Polymorphism.
Definition: language_base.h:102
virtual ~Base()
Definition: language_base.h:163
@ NWORDS
Definition: language_base.h:109
std::unordered_map< epee::wipeable_string, uint32_t, WordHash, WordEqual > word_map
Definition: language_base.h:112
std::string language_name
Definition: language_base.h:114
void set_words(const char *const words[])
Definition: language_base.h:166
std::vector< std::string > word_list
Definition: language_base.h:111
std::string english_language_name
Definition: language_base.h:115
const std::string & get_language_name() const
Returns the name of the language.
Definition: language_base.h:200
Base(const char *language_name, const char *english_language_name, const std::vector< std::string > &words, uint32_t prefix_length)
Definition: language_base.h:156
const std::unordered_map< epee::wipeable_string, uint32_t, WordHash, WordEqual > & get_word_map() const
Returns a pointer to the word map.
Definition: language_base.h:184
void populate_maps(uint32_t flags=0)
Populates the word maps after the list is ready.
Definition: language_base.h:120
const std::string & get_english_language_name() const
Returns the name of the language in English.
Definition: language_base.h:208
const std::vector< std::string > & get_word_list() const
Returns a pointer to the word list.
Definition: language_base.h:176
std::unordered_map< epee::wipeable_string, uint32_t, WordHash, WordEqual > trimmed_word_map
Definition: language_base.h:113
uint32_t unique_prefix_length
Definition: language_base.h:116
const std::unordered_map< epee::wipeable_string, uint32_t, WordHash, WordEqual > & get_trimmed_word_map() const
Returns a pointer to the trimmed word map.
Definition: language_base.h:192
@ ALLOW_DUPLICATE_PREFIXES
Definition: language_base.h:106
@ ALLOW_SHORT_WORDS
Definition: language_base.h:105
uint32_t get_unique_prefix_length() const
Returns the number of unique starting characters to be used for matching.
Definition: language_base.h:216
const uint32_t T[512]
Definition: groestl_tables.h:36
Mnemonic language related namespace.
T utf8prefix(const T &s, size_t count)
Returns a string made of (at most) the first count characters in s. Assumes well formedness....
Definition: language_base.h:60
mdb_size_t count(MDB_cursor *cur)
Definition: value_stream.cpp:39
Definition: language_base.h:87
bool operator()(const epee::wipeable_string &s0, const epee::wipeable_string &s1) const
Definition: language_base.h:88
Definition: language_base.h:78
std::size_t operator()(const epee::wipeable_string &s) const
Definition: language_base.h:79