diff options
author | Riccardo Spagni <ric@spagni.net> | 2015-06-21 15:43:30 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2015-06-21 16:00:19 +0200 |
commit | eeff247bf15e2e9406776f8e441d1986c133466a (patch) | |
tree | e86993c095e77deff2b498cba34094c68913cbfd /src/mnemonics/language_base.h | |
parent | Merge pull request #325 (diff) | |
parent | mnemonics: fix prefix extraction with non ASCII text (diff) | |
download | monero-eeff247bf15e2e9406776f8e441d1986c133466a.tar.xz |
Merge pull request #326
ea33cad mnemonics: fix prefix extraction with non ASCII text (moneromooo-monero)
Diffstat (limited to '')
-rw-r--r-- | src/mnemonics/language_base.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/mnemonics/language_base.h b/src/mnemonics/language_base.h index 0e7d60a02..4d7cce724 100644 --- a/src/mnemonics/language_base.h +++ b/src/mnemonics/language_base.h @@ -46,6 +46,26 @@ namespace Language
{
/*!
+ * \brief Returns a string made of (at most) the first count characters in s.
+ * Assumes well formedness. No check is made for this.
+ * \param s The string from which to return the first count characters.
+ * \param count How many characters to return.
+ * \return A string consisting of the first count characters in s.
+ */
+ std::string utf8prefix(const std::string &s, size_t count)
+ {
+ std::string prefix = "";
+ const char *ptr = s.c_str();
+ while (count-- && *ptr)
+ {
+ prefix += *ptr++;
+ while (((*ptr) & 0xc0) == 0x80)
+ prefix += *ptr++;
+ }
+ return prefix;
+ }
+
+ /*!
* \class Base
* \brief A base language class which all languages have to inherit from for
* Polymorphism.
@@ -70,7 +90,7 @@ namespace Language (*word_map)[*it] = ii;
if (it->length() > unique_prefix_length)
{
- (*trimmed_word_map)[it->substr(0, unique_prefix_length)] = ii;
+ (*trimmed_word_map)[utf8prefix(*it, unique_prefix_length)] = ii;
}
else
{
|